GeoPandas – Overview of Basic Tools
Here you’ll find a set of basic GeoPandas tools that allow you to go through the entire spatial analysis process — from loading the data to saving the results.
Loading Data
import geopandas as gpd
gdf = gpd.read_file("file.shp")
Basic Layer Information
gdf.head() # data preview
gdf.crs # coordinate reference system
gdf.plot() # quick map
Creating Geometry
from shapely.geometry import Point
point = Point(21.0, 52.2)
gdf = gpd.GeoDataFrame(geometry=[point])
Spatial Operations
gdf.buffer(100) # buffer
gdf.distance(gdf2) # distance between objects
gdf.intersects(gdf2) # intersections
gdf.contains(gdf2) # contains
gdf.within(gdf2) # within
Reprojection (Changing Coordinate System)
gdf.to_crs(epsg=2180) # e.g., PUWG 1992
Filtering Data (like in Pandas)
gdf[gdf["type"] == "forest"] # filter
Saving to File
gdf.to_file("result.shp")
Joining Data (merge)
gdf_joined = gdf.merge(table, on="id")
