GIS GIS - Geographic Information System Python Scripting and Automation Questions and Answers 2 — Questions and Answers
Question 1: Which Python package is used to reproject geometries and coordinate reference systems in GIS automation scripts?
- Pyproj (Correct answer)
- Geopy
- Folium
- Rtree
Correct answer: Pyproj
Pyproj is a Python interface to PROJ, providing coordinate transformation and CRS definition capabilities for reprojection tasks.
Question 2: In Python GIS automation, what is a 'spatial index' (e.g., using the Rtree library) used for?
- Storing metadata about each layer's coordinate reference system
- Speeding up spatial queries by enabling rapid identification of candidate geometries without checking all features (Correct answer)
- Assigning unique IDs to every feature in a dataset
- Encoding geometry vertices into a compressed binary format
Correct answer: Speeding up spatial queries by enabling rapid identification of candidate geometries without checking all features
A spatial index (like an R-tree) organizes geometries by bounding box so that intersection or nearest-neighbor queries scan only a small candidate set instead of every feature.
Question 3: What does the GeoPandas 'dissolve()' function do?
- Merges two GeoDataFrames by a common attribute key
- Aggregates and merges geometries based on a grouping attribute, combining touching or overlapping polygons (Correct answer)
- Removes duplicate coordinate vertices from geometry objects
- Converts polygon features to their centroid point representations
Correct answer: Aggregates and merges geometries based on a grouping attribute, combining touching or overlapping polygons
dissolve() groups rows by a specified column and unions all geometries within each group, similar to a SQL GROUP BY with spatial aggregation.
Question 4: In a Python GIS script using Rasterio, what does 'src.transform' represent?
- The map projection EPSG code of the raster
- The affine transformation matrix that maps pixel row/column coordinates to geographic coordinates (Correct answer)
- The radiometric correction factor for each spectral band
- The compression algorithm applied to the raster file
Correct answer: The affine transformation matrix that maps pixel row/column coordinates to geographic coordinates
The affine transform encodes the origin, pixel size, and rotation, enabling conversion between pixel indices and real-world coordinates.
Question 5: Which GDAL command-line utility (callable from Python via subprocess or gdal bindings) converts a vector file to a raster grid?
- gdal_translate
- gdal_warp
- gdal_rasterize (Correct answer)
- gdal_polygonize
Correct answer: gdal_rasterize
gdal_rasterize burns vector feature values into a raster grid at a specified resolution and extent.
Question 6: In Python GIS scripting, what is the purpose of the 'Folium' library?
- Processing LiDAR point clouds in Python
- Creating interactive web maps in Python using Leaflet.js as the backend (Correct answer)
- Performing GPU-accelerated raster algebra operations
- Connecting Python scripts to PostGIS spatial databases
Correct answer: Creating interactive web maps in Python using Leaflet.js as the backend
Folium renders interactive, zoomable maps in a browser by generating Leaflet.js HTML from Python data structures.
Which Python package is used to reproject geometries and coordinate reference systems in GIS automation scripts?