GIS GIS - Geographic Information System Python Scripting and Automation Questions and Answers 1 — Questions and Answers
Question 1: Which Python library is most widely used for reading, writing, and manipulating vector geospatial data formats such as shapefiles and GeoJSON?
- NumPy
- Fiona (Correct answer)
- SciPy
- Pillow
Correct answer: Fiona
Fiona provides Pythonic access to OGR's vector data reading and writing capabilities, supporting dozens of geospatial formats.
Question 2: In Python GIS scripting with Shapely, which method returns the geometric intersection of two polygon objects?
- polygon1.union(polygon2)
- polygon1.intersection(polygon2) (Correct answer)
- polygon1.difference(polygon2)
- polygon1.buffer(polygon2)
Correct answer: polygon1.intersection(polygon2)
The intersection() method returns the geometry representing the area shared by both input geometries.
Question 3: What is the primary purpose of the Python library 'GeoPandas' in GIS workflows?
- Rendering 3D terrain models
- Extending pandas DataFrames to support spatial operations on vector data (Correct answer)
- Performing radiometric correction on satellite imagery
- Managing geodatabase schema definitions
Correct answer: Extending pandas DataFrames to support spatial operations on vector data
GeoPandas adds a geometry column to pandas DataFrames, enabling spatial joins, projections, dissolves, and map plotting directly in Python.
Question 4: In ArcPy (Esri's Python site-package), which function is used to iterate over features in a feature class and read attribute values?
- arcpy.da.InsertCursor
- arcpy.da.SearchCursor (Correct answer)
- arcpy.da.UpdateCursor
- arcpy.ListFields
Correct answer: arcpy.da.SearchCursor
arcpy.da.SearchCursor creates a read-only cursor that iterates over rows in a feature class, returning field values as tuples.
Question 5: Which Python library provides tools for raster data processing, including reading GeoTIFF files and performing array-based calculations?
- Rasterio (Correct answer)
- Cartopy
- PyQGIS
- Pyproj
Correct answer: Rasterio
Rasterio reads and writes raster datasets (GeoTIFF, etc.) and exposes pixel values as NumPy arrays for analysis.
Question 6: In QGIS Python scripting (PyQGIS), what does the 'processing.run()' function do?
- Renders a map layout to PDF
- Executes a QGIS processing algorithm programmatically with specified parameters (Correct answer)
- Opens a new QGIS project file
- Loads a WMS layer into the current map canvas
Correct answer: Executes a QGIS processing algorithm programmatically with specified parameters
processing.run() calls any algorithm from the QGIS Processing Toolbox (including GDAL and GRASS tools) with input parameters from a Python script.
Which Python library is most widely used for reading, writing, and manipulating vector geospatial data formats such as shapefiles and GeoJSON?