Geopandas 50 Exercises
Geopandas 50 Exercises
1. Install and Import: Install GeoPandas (pip install geopandas) and import it.
2. Load a Shapefile: Read a shapefile (e.g., a country boundaries dataset) using
gpd.read_file().
3. Create a GeoDataFrame: Convert a DataFrame with latitude and longitude columns
into a GeoDataFrame.
4. Set CRS: Assign a coordinate reference system (CRS) to a GeoDataFrame.
5. Convert CRS: Reproject a GeoDataFrame to a different CRS (e.g., EPSG:4326 to
EPSG:3857).
6. Plot a GeoDataFrame: Use .plot() to visualize geometries in a GeoDataFrame.
7. Filter Data: Select features based on an attribute (e.g., select countries with a
population > 50 million).
8. Extract Centroids: Compute centroids of polygons using .centroid.
9. Save a GeoDataFrame: Export a GeoDataFrame to a shapefile or GeoJSON format.
10. Access Geometry: Extract the geometry column of a GeoDataFrame and print the
first 5 geometries.
31. Compute Convex Hull: Get the convex hull of a set of geometries.
32. Create Thiessen Polygons: Generate Voronoi/Thiessen polygons from a point
dataset.
33. Geospatial Aggregation: Aggregate spatial data based on a column (e.g., sum
population by region).
34. Find Polygon Holes: Identify holes within polygons and extract them.
35. Split a Polygon: Split a polygon into smaller sections using a line.
36. Find Nearest Neighbor: Calculate the nearest neighbor of each point in a dataset.
37. Convert Raster to Vector: Convert a raster dataset into vector format.
38. Extract Roads from OpenStreetMap: Load road networks using osmnx and convert
them to a GeoDataFrame.
39. Handle Missing Geometries: Find and remove rows with None or NaN geometries.
40. Write a Custom Geometric Function: Implement a function to modify geometries
(e.g., rotate polygons).
41. Perform Spatial Autocorrelation: Calculate Moran's I for spatial clustering analysis.
42. Use MapClassify for Choropleths: Classify data into bins and visualize it using
choropleth maps.
43. Extract Country Borders from Natural Earth: Load and process Natural Earth data
to extract country boundaries.
44. Hexbin Spatial Analysis: Aggregate data into hexagonal bins for density
visualization.
45. Network Analysis with Geopandas and NetworkX: Build a graph from a road
network dataset and perform shortest path analysis.
46. Find Self-Intersecting Geometries: Detect and fix self-intersecting polygons.
47. Convert Line to Points: Convert a LineString into multiple evenly spaced points.
48. Create an Animated Map: Use folium or mplleaflet to animate geospatial data
over time.
49. Calculate Viewshed Analysis: Determine visible areas from a given point using
elevation data.
50. Develop a Full GIS Web App: Integrate GeoPandas with FastAPI or Django to serve
geospatial data via an API.