[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M73GQTMBFZDCK3ARWSDMPV0X":3,"skill-same:01M73GQTMBFZDCK3ARWSDMPV0X":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M73GQTMBFZDCK3ARWSDMPV0X","geopandas-geospatial",null,"Geospatial vector analysis extending pandas. Read\u002Fwrite spatial formats (Shapefile, GeoJSON, GeoPackage, Parquet, PostGIS), CRS handling, geometric ops (buffer, simplify, centroid, affine), spatial analysis (joins, overlays, dissolve, clipping, distance), visualization (choropleth, interactive maps, basemaps). Use for spatial joins, overlays, CRS transforms, area\u002Fdistance, maps.","bg-szy\u002FTOP-SKILLS","bg-szy","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F106576190?v=4","01M73A4E8KPV67SFXRY8XZGNBX","ShuZhiyong","01M73A4E96MQ294MHM74TZBVQD",6,"BSD-3-Clause","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fawesome-skills\u002Fgeopandas-geospatial\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: geopandas-geospatial\ndescription: \"Geospatial vector analysis extending pandas. Read\u002Fwrite spatial formats (Shapefile, GeoJSON, GeoPackage, Parquet, PostGIS), CRS handling, geometric ops (buffer, simplify, centroid, affine), spatial analysis (joins, overlays, dissolve, clipping, distance), visualization (choropleth, interactive maps, basemaps). Use for spatial joins, overlays, CRS transforms, area\u002Fdistance, maps.\"\nlicense: BSD-3-Clause\n---\n\n# GeoPandas Geospatial Analysis\n\n## Overview\n\nGeoPandas extends pandas with spatial operations on geometric types, combining pandas DataFrames with Shapely geometries and Fiona for file I\u002FO. It enables reading, writing, manipulating, and visualizing geospatial vector data (points, lines, polygons) with a familiar pandas-like API.\n\n## When to Use\n\n- Reading and writing spatial file formats (Shapefile, GeoJSON, GeoPackage, Parquet)\n- Performing spatial joins between geographic datasets (points in polygons, nearest neighbors)\n- Running overlay operations (intersection, union, difference, clipping)\n- Computing geometric properties (area, distance, buffer, centroid)\n- Creating choropleth maps and interactive web maps\n- Reprojecting data between coordinate reference systems\n- Aggregating spatial features by attribute (dissolve)\n- For raster data analysis, use rasterio\u002Fxarray instead\n- For large-scale distributed geospatial, consider Dask-GeoPandas or Apache Sedona\n\n## Prerequisites\n\n```bash\npip install geopandas matplotlib\n# Optional:\n# pip install folium       — interactive maps\n# pip install mapclassify  — classification schemes for choropleth\n# pip install contextily   — basemaps\n# pip install pyarrow      — faster I\u002FO (2-4x speedup)\n# pip install psycopg2 geoalchemy2  — PostGIS support\n```\n\n## Quick Start\n\n```python\nimport geopandas as gpd\n\n# Read spatial data\ngdf = gpd.read_file(\"data.geojson\")\nprint(f\"Shape: {gdf.shape}, CRS: {gdf.crs}\")\nprint(f\"Geometry types: {gdf.geometry.geom_type.unique()}\")\n\n# Reproject, compute area, save\ngdf_proj = gdf.to_crs(\"EPSG:3857\")\ngdf_proj['area_m2'] = gdf_proj.geometry.area\ngdf_proj.to_file(\"output.gpkg\")\n\n# Quick map\ngdf.plot(column='population', legend=True, figsize=(10, 8))\n```\n\n## Core API\n\n### 1. Data I\u002FO\n\n```python\nimport geopandas as gpd\n\n# Read various formats\ngdf = gpd.read_file(\"data.shp\")           # Shapefile\ngdf = gpd.read_file(\"data.geojson\")       # GeoJSON\ngdf = gpd.read_file(\"data.gpkg\")          # GeoPackage\ngdf = gpd.read_file(\"data.gpkg\", layer=\"roads\")  # Specific layer\n\n# Filtered reading (load only needed data)\ngdf = gpd.read_file(\"data.gpkg\", bbox=(xmin, ymin, xmax, ymax))\ngdf = gpd.read_file(\"data.gpkg\", columns=[\"name\", \"geometry\"])\ngdf = gpd.read_file(\"data.gpkg\", where=\"population > 10000\")\n\n# Arrow acceleration (2-4x faster)\ngdf = gpd.read_file(\"data.gpkg\", use_arrow=True)\n\n# Parquet\u002FFeather (columnar, fast, preserves CRS)\ngdf = gpd.read_parquet(\"data.parquet\")\ngdf.to_parquet(\"output.parquet\")\n\n# PostGIS database\nfrom sqlalchemy import create_engine\nengine = create_engine(\"postgresql:\u002F\u002Fuser:pass@host\u002Fdb\")\ngdf = gpd.read_postgis(\"SELECT * FROM parcels\", con=engine, geom_col='geom')\ngdf.to_postgis(\"output_table\", con=engine)\n\n# Write\ngdf.to_file(\"output.gpkg\")             # GeoPackage (recommended)\ngdf.to_file(\"output.shp\")              # Shapefile\ngdf.to_file(\"output.geojson\", driver=\"GeoJSON\")\n```\n\n### 2. CRS Management\n\n```python\n# Check current CRS\nprint(gdf.crs)                  # e.g., EPSG:4326\nprint(gdf.crs.is_geographic)    # True for lat\u002Flon\nprint(gdf.crs.is_projected)     # True for meters\n\n# Reproject (transforms coordinates)\ngdf_proj = gdf.to_crs(\"EPSG:3857\")       # Web Mercator\ngdf_proj = gdf.to_crs(epsg=32633)        # UTM zone 33N\n\n# Set CRS (only when metadata missing, does NOT transform coordinates)\ngdf = gdf.set_crs(\"EPSG:4326\")\n\n# Estimate appropriate UTM zone\nutm_crs = gdf.estimate_utm_crs()\ngdf_utm = gdf.to_crs(utm_crs)\n```\n\n**Common EPSG codes**:\n\n| Code | Name | Use |\n|------|------|-----|\n| 4326 | WGS 84 | GPS coordinates, web data |\n| 3857 | Web Mercator | Web mapping (Google\u002FOSM tiles) |\n| 326xx | UTM zones (N) | Area\u002Fdistance calculations |\n| 5070 | Albers Equal Area (US) | Area-preserving US maps |\n\n### 3. Geometric Operations\n\n```python\n# Buffer (expand\u002Ferode geometry by distance)\nbuffered = gdf.geometry.buffer(100)      # 100 units (meters if projected)\neroded = gdf.geometry.buffer(-50)        # Negative = erosion\n\n# Simplify (reduce complexity)\nsimplified = gdf.geometry.simplify(tolerance=10, preserve_topology=True)\n\n# Centroid, convex hull, envelope\ncentroids = gdf.geometry.centroid\nhulls = gdf.geometry.convex_hull\nbounds = gdf.geometry.envelope\n\n# Union all geometries\nunified = gdf.geometry.union_all()\n\n# Affine transformations\nrotated = gdf.geometry.rotate(angle=45, origin='center')\nscaled = gdf.geometry.scale(xfact=2.0, yfact=2.0)\ntranslated = gdf.geometry.translate(xoff=100, yoff=50)\n\n# Geometric properties\nareas = gdf.geometry.area           # Use projected CRS for accuracy\nlengths = gdf.geometry.length       # Perimeter for polygons\nis_valid = gdf.geometry.is_valid    # Validate geometry\ntotal = gdf.geometry.total_bounds   # [minx, miny, maxx, maxy]\n```\n\n### 4. Spatial Analysis\n\n```python\n# Spatial join (combine datasets by spatial relationship)\njoined = gpd.sjoin(points_gdf, polygons_gdf, predicate='intersects')\njoined = gpd.sjoin(gdf1, gdf2, predicate='within')\njoined = gpd.sjoin(gdf1, gdf2, predicate='contains', how='left')\n\n# Nearest neighbor join\nnearest = gpd.sjoin_nearest(gdf1, gdf2, max_distance=1000, distance_col='dist')\n\n# Overlay operations (set-theoretic)\nintersection = gpd.overlay(gdf1, gdf2, how='intersection')\nunion = gpd.overlay(gdf1, gdf2, how='union')\ndifference = gpd.overlay(gdf1, gdf2, how='difference')\nsym_diff = gpd.overlay(gdf1, gdf2, how='symmetric_difference')\n\n# Dissolve (aggregate by attribute)\ndissolved = gdf.dissolve(by='region', aggfunc='sum')\ndissolved = gdf.dissolve(by='region', aggfunc={'population': 'sum', 'area': 'mean'})\n\n# Clip to boundary\nclipped = gpd.clip(gdf, boundary_gdf)\n\n# Distance calculations (use projected CRS)\ndistances = gdf.geometry.distance(single_point)\n\n# Spatial predicates\nwithin_mask = gdf1.geometry.within(gdf2.geometry)\nintersects_mask = gdf1.geometry.intersects(gdf2.geometry)\n```\n\n### 5. Visualization\n\n```python\nimport matplotlib.pyplot as plt\n\n# Basic plot\ngdf.plot(figsize=(10, 8))\n\n# Choropleth map\ngdf.plot(column='population', cmap='YlOrRd', legend=True, figsize=(12, 8))\n\n# Classification schemes (requires mapclassify)\ngdf.plot(column='population', scheme='quantiles', k=5, legend=True)\ngdf.plot(column='population', scheme='fisher_jenks', k=5, legend=True)\n\n# Multi-layer map\nfig, ax = plt.subplots(figsize=(12, 10))\npolygons_gdf.plot(ax=ax, color='lightblue', edgecolor='black')\npoints_gdf.plot(ax=ax, color='red', markersize=10)\nroads_gdf.plot(ax=ax, color='gray', linewidth=0.5)\nax.set_title('Multi-layer Map')\nax.set_axis_off()\n\n# Interactive map (requires folium)\nm = gdf.explore(column='population', cmap='YlOrRd', legend=True,\n                tooltip=['name', 'population'])\nm.save('map.html')\n\n# Multi-layer interactive\nm = gdf1.explore(color='blue', name='Layer 1')\ngdf2.explore(m=m, color='red', name='Layer 2')\nimport folium\nfolium.LayerControl().add_to(m)\n\n# Basemap (requires contextily)\nimport contextily as ctx\ngdf_wm = gdf.to_crs(epsg=3857)\nax = gdf_wm.plot(alpha=0.5, figsize=(10, 10))\nctx.add_basemap(ax)\n```\n\n## Key Concepts\n\n### Data Structures\n\n- **GeoSeries**: Pandas Series of Shapely geometries with spatial methods (area, distance, buffer, etc.)\n- **GeoDataFrame**: Pandas DataFrame with one or more geometry columns. One column is the \"active geometry\" used by spatial methods\n\n```python\nfrom shapely.geometry import Point\n\n# Create from coordinates\ngdf = gpd.GeoDataFrame(\n    {'name': ['A', 'B'], 'value': [10, 20]},\n    geometry=[Point(0, 0), Point(1, 1)],\n    crs=\"EPSG:4326\"\n)\n\n# Multiple geometry columns\ngdf['centroid'] = gdf.geometry.centroid\ngdf = gdf.set_geometry('centroid')  # Switch active geometry\n```\n\n### CRS Rules for Spatial Operations\n\n- **Always check CRS** before any spatial operation: `print(gdf.crs)`\n- **Match CRS** before spatial joins, overlays, or distance calculations\n- **Use projected CRS** (meters) for area\u002Fdistance — geographic CRS (degrees) gives wrong results\n- **set_crs()** only adds metadata; **to_crs()** transforms coordinates\n\n### Spatial Indexing\n\nGeoPandas automatically creates spatial indexes (R-tree) for sjoin, overlay, and other spatial operations. For manual queries:\n\n```python\nsindex = gdf.sindex\npossible_idx = list(sindex.intersection((xmin, ymin, xmax, ymax)))\n```\n\n## Common Workflows\n\n### Workflow 1: Load → Transform → Analyze → Export\n\n```python\nimport geopandas as gpd\n\n# Load\ngdf = gpd.read_file(\"parcels.shp\")\nprint(f\"CRS: {gdf.crs}, Rows: {len(gdf)}\")\n\n# Transform to projected CRS for measurements\ngdf = gdf.to_crs(gdf.estimate_utm_crs())\n\n# Analyze\ngdf['area_ha'] = gdf.geometry.area \u002F 10000  # hectares\ngdf['perimeter_m'] = gdf.geometry.length\nprint(f\"Total area: {gdf['area_ha'].sum():.1f} ha\")\n\n# Export\ngdf.to_file(\"parcels_analyzed.gpkg\")\n```\n\n### Workflow 2: Spatial Join and Aggregate\n\n```python\n# Count points per polygon\npoints_in_poly = gpd.sjoin(points_gdf, polygons_gdf, predicate='within')\ncounts = points_in_poly.groupby('index_right').agg(\n    point_count=('geometry', 'size'),\n    total_value=('value', 'sum')\n)\nresult = polygons_gdf.merge(counts, left_index=True, right_index=True, how='left')\nresult['point_count'] = result['point_count'].fillna(0)\nprint(f\"Polygons with points: {(result['point_count'] > 0).sum()}\u002F{len(result)}\")\n```\n\n### Workflow 3: Multi-Source Integration\n\n```python\n# Read from different sources, ensure matching CRS\nroads = gpd.read_file(\"roads.shp\")\nbuildings = gpd.read_file(\"buildings.geojson\")\nparcels = gpd.read_postgis(\"SELECT * FROM parcels\", con=engine, geom_col='geom')\n\ntarget_crs = roads.crs\nbuildings = buildings.to_crs(target_crs)\nparcels = parcels.to_crs(target_crs)\n\n# Find buildings within 50m of roads\nbuildings_near_roads = gpd.sjoin_nearest(\n    buildings, roads, max_distance=50, distance_col='road_dist'\n)\nprint(f\"Buildings near roads: {len(buildings_near_roads)}\u002F{len(buildings)}\")\n```\n\n## Key Parameters\n\n| Parameter | Function | Default | Effect |\n|-----------|----------|---------|--------|\n| `predicate` | sjoin | `'intersects'` | Spatial relationship: intersects, within, contains, touches, crosses |\n| `how` | sjoin, overlay | `'inner'` | Join type: inner, left, right |\n| `max_distance` | sjoin_nearest | None | Search radius limit (improves performance) |\n| `k` | sjoin_nearest | 1 | Number of nearest neighbors to find |\n| `tolerance` | simplify | Required | Douglas-Peucker tolerance (in CRS units) |\n| `preserve_topology` | simplify | True | Prevents self-intersections |\n| `resolution` | buffer | 16 | Number of segments for buffer curves |\n| `aggfunc` | dissolve | 'first' | Aggregation function for non-geometry columns |\n| `use_arrow` | read_file | False | Enable Arrow acceleration (2-4x faster) |\n| `scheme` | plot | None | Classification: quantiles, equal_interval, fisher_jenks |\n| `k` | plot (with scheme) | 5 | Number of classification bins |\n\n## Best Practices\n\n1. **Always check CRS** before spatial operations — mismatched CRS gives wrong or empty results\n2. **Use projected CRS** for area and distance calculations — geographic CRS (degrees) is meaningless for measurements\n3. **Match CRS before joins** — `gdf2 = gdf2.to_crs(gdf1.crs)` before `gpd.sjoin(gdf1, gdf2)`\n4. **Validate geometries** with `.is_valid` before complex operations — invalid geometries cause silent errors\n5. **Use GeoPackage** over Shapefile — no 10-char column name limit, supports multiple layers, better performance\n6. **Filter during read** — use `bbox`, `columns`, `where` to load only needed data for large files\n7. **Set max_distance in sjoin_nearest** — unbounded nearest-neighbor search is slow on large datasets\n8. **Use `.copy()` when modifying geometry** — avoid unintended side effects on original GeoDataFrame\n\n## Common Recipes\n\n### Recipe: Count Points in Polygons\n\nWhen to use: Aggregate point observations (sample sites, observations) by region (county, watershed).\n\n```python\nimport geopandas as gpd\n\nregions = gpd.read_file(\"regions.geojson\")\npoints = gpd.read_file(\"observations.geojson\").to_crs(regions.crs)\n\njoined = gpd.sjoin(points, regions, how=\"inner\", predicate=\"within\")\ncounts = joined.groupby(\"index_right\").size().rename(\"point_count\")\nregions_with_counts = regions.join(counts).fillna(0)\nregions_with_counts[\"point_count\"] = regions_with_counts[\"point_count\"].astype(int)\nprint(regions_with_counts[[\"name\", \"point_count\"]].sort_values(\"point_count\", ascending=False).head())\n```\n\n### Recipe: Buffer Around Points and Dissolve Overlaps\n\nWhen to use: Create service areas or catchment zones from point locations.\n\n```python\nimport geopandas as gpd\n\nfacilities = gpd.read_file(\"facilities.geojson\")\nutm_crs = facilities.estimate_utm_crs()   # Project to meters\nfacilities_m = facilities.to_crs(utm_crs)\n\n# 1 km buffer\nbuffers = facilities_m.copy()\nbuffers[\"geometry\"] = facilities_m.geometry.buffer(1000)\n\n# Dissolve overlapping buffers into single polygon\nservice_area = buffers.dissolve()\nservice_area_wgs84 = service_area.to_crs(\"EPSG:4326\")\nservice_area_wgs84.to_file(\"service_area.geojson\", driver=\"GeoJSON\")\nprint(f\"Service area: {service_area_wgs84.geometry.area.sum():.0f} sq degrees\")\n```\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| Empty spatial join result | CRS mismatch between GeoDataFrames | Ensure matching CRS: `gdf2 = gdf2.to_crs(gdf1.crs)` |\n| Wrong area\u002Fdistance values | Using geographic CRS (degrees) | Reproject to projected CRS: `gdf.to_crs(gdf.estimate_utm_crs())` |\n| `DriverError` on read | Missing driver or corrupt file | Check file exists; try `driver=\"GeoJSON\"` explicitly |\n| Geometry column lost after merge | Called `df.merge(gdf)` instead of `gdf.merge(df)` | Always call merge ON the GeoDataFrame |\n| `TopologicalError` on overlay | Invalid geometries | Fix with `gdf.geometry = gdf.geometry.buffer(0)` |\n| Slow sjoin_nearest | No distance limit on large dataset | Set `max_distance` parameter |\n| Folium map blank | Geometries not in EPSG:4326 | Reproject to WGS84: `gdf.to_crs(epsg=4326).explore()` |\n| Shapefile column names truncated | Shapefile 10-char limit | Use GeoPackage instead: `gdf.to_file(\"out.gpkg\")` |\n\n## References\n\n- GeoPandas documentation: https:\u002F\u002Fgeopandas.org\u002F\n- GeoPandas GitHub: https:\u002F\u002Fgithub.com\u002Fgeopandas\u002Fgeopandas\n- Shapely documentation: https:\u002F\u002Fshapely.readthedocs.io\u002F\n- EPSG registry: https:\u002F\u002Fepsg.io\u002F\n\n## Related Skills\n\n- **matplotlib-scientific-plotting** — advanced map styling and figure export\n- **polars-dataframes** — high-performance tabular analysis before\u002Fafter spatial operations\n- **folium** — advanced interactive web mapping beyond geopandas.explore()\n","# GeoPandas Geospatial Analysis\n\n## Overview\n\nGeoPandas extends pandas with spatial operations on geometric types, combining pandas DataFrames with Shapely geometries and Fiona for file I\u002FO. It enables reading, writing, manipulating, and visualizing geospatial vector data (points, lines, polygons) with a familiar pandas-like API.\n\n## When to Use\n\n- Reading and writing spatial file formats (Shapefile, GeoJSON, GeoPackage, Parquet)\n- Performing spatial joins between geographic datasets (points in polygons, nearest neighbors)\n- Running overlay operations (intersection, union, difference, clipping)\n- Computing geometric properties (area, distance, buffer, centroid)\n- Creating choropleth maps and interactive web maps\n- Reprojecting data between coordinate reference systems\n- Aggregating spatial features by attribute (dissolve)\n- For raster data analysis, use rasterio\u002Fxarray instead\n- For large-scale distributed geospatial, consider Dask-GeoPandas or Apache Sedona\n\n## Prerequisites\n\n```bash\npip install geopandas matplotlib\n# Optional:\n# pip install folium       — interactive maps\n# pip install mapclassify  — classification schemes for choropleth\n# pip install contextily   — basemaps\n# pip install pyarrow      — faster I\u002FO (2-4x speedup)\n# pip install psycopg2 geoalchemy2  — PostGIS support\n```\n\n## Quick Start\n\n```python\nimport geopandas as gpd\n\n# Read spatial data\ngdf = gpd.read_file(\"data.geojson\")\nprint(f\"Shape: {gdf.shape}, CRS: {gdf.crs}\")\nprint(f\"Geometry types: {gdf.geometry.geom_type.unique()}\")\n\n# Reproject, compute area, save\ngdf_proj = gdf.to_crs(\"EPSG:3857\")\ngdf_proj['area_m2'] = gdf_proj.geometry.area\ngdf_proj.to_file(\"output.gpkg\")\n\n# Quick map\ngdf.plot(column='population', legend=True, figsize=(10, 8))\n```\n\n## Core API\n\n### 1. Data I\u002FO\n\n```python\nimport geopandas as gpd\n\n# Read various formats\ngdf = gpd.read_file(\"data.shp\")           # Shapefile\ngdf = gpd.read_file(\"data.geojson\")       # GeoJSON\ngdf = gpd.read_file(\"data.gpkg\")          # GeoPackage\ngdf = gpd.read_file(\"data.gpkg\", layer=\"roads\")  # Specific layer\n\n# Filtered reading (load only needed data)\ngdf = gpd.read_file(\"data.gpkg\", bbox=(xmin, ymin, xmax, ymax))\ngdf = gpd.read_file(\"data.gpkg\", columns=[\"name\", \"geometry\"])\ngdf = gpd.read_file(\"data.gpkg\", where=\"population > 10000\")\n\n# Arrow acceleration (2-4x faster)\ngdf = gpd.read_file(\"data.gpkg\", use_arrow=True)\n\n# Parquet\u002FFeather (columnar, fast, preserves CRS)\ngdf = gpd.read_parquet(\"data.parquet\")\ngdf.to_parquet(\"output.parquet\")\n\n# PostGIS database\nfrom sqlalchemy import create_engine\nengine = create_engine(\"postgresql:\u002F\u002Fuser:pass@host\u002Fdb\")\ngdf = gpd.read_postgis(\"SELECT * FROM parcels\", con=engine, geom_col='geom')\ngdf.to_postgis(\"output_table\", con=engine)\n\n# Write\ngdf.to_file(\"output.gpkg\")             # GeoPackage (recommended)\ngdf.to_file(\"output.shp\")              # Shapefile\ngdf.to_file(\"output.geojson\", driver=\"GeoJSON\")\n```\n\n### 2. CRS Management\n\n```python\n# Check current CRS\nprint(gdf.crs)                  # e.g., EPSG:4326\nprint(gdf.crs.is_geographic)    # True for lat\u002Flon\nprint(gdf.crs.is_projected)     # True for meters\n\n# Reproject (transforms coordinates)\ngdf_proj = gdf.to_crs(\"EPSG:3857\")       # Web Mercator\ngdf_proj = gdf.to_crs(epsg=32633)        # UTM zone 33N\n\n# Set CRS (only when metadata missing, does NOT transform coordinates)\ngdf = gdf.set_crs(\"EPSG:4326\")\n\n# Estimate appropriate UTM zone\nutm_crs = gdf.estimate_utm_crs()\ngdf_utm = gdf.to_crs(utm_crs)\n```\n\n**Common EPSG codes**:\n\n| Code | Name | Use |\n|------|------|-----|\n| 4326 | WGS 84 | GPS coordinates, web data |\n| 3857 | Web Mercator | Web mapping (Google\u002FOSM tiles) |\n| 326xx | UTM zones (N) | Area\u002Fdistance calculations |\n| 5070 | Albers Equal Area (US) | Area-preserving US maps |\n\n### 3. Geometric Operations\n\n```python\n# Buffer (expand\u002Ferode geometry by distance)\nbuffered = gdf.geometry.buffer(100)      # 100 units (meters if projected)\neroded = gdf.geometry.buffer(-50)        # Negative = erosion\n\n# Simplify (reduce complexity)\nsimplified = gdf.geometry.simplify(tolerance=10, preserve_topology=True)\n\n# Centroid, convex hull, envelope\ncentroids = gdf.geometry.centroid\nhulls = gdf.geometry.convex_hull\nbounds = gdf.geometry.envelope\n\n# Union all geometries\nunified = gdf.geometry.union_all()\n\n# Affine transformations\nrotated = gdf.geometry.rotate(angle=45, origin='center')\nscaled = gdf.geometry.scale(xfact=2.0, yfact=2.0)\ntranslated = gdf.geometry.translate(xoff=100, yoff=50)\n\n# Geometric properties\nareas = gdf.geometry.area           # Use projected CRS for accuracy\nlengths = gdf.geometry.length       # Perimeter for polygons\nis_valid = gdf.geometry.is_valid    # Validate geometry\ntotal = gdf.geometry.total_bounds   # [minx, miny, maxx, maxy]\n```\n\n### 4. Spatial Analysis\n\n```python\n# Spatial join (combine datasets by spatial relationship)\njoined = gpd.sjoin(points_gdf, polygons_gdf, predicate='intersects')\njoined = gpd.sjoin(gdf1, gdf2, predicate='within')\njoined = gpd.sjoin(gdf1, gdf2, predicate='contains', how='left')\n\n# Nearest neighbor join\nnearest = gpd.sjoin_nearest(gdf1, gdf2, max_distance=1000, distance_col='dist')\n\n# Overlay operations (set-theoretic)\nintersection = gpd.overlay(gdf1, gdf2, how='intersection')\nunion = gpd.overlay(gdf1, gdf2, how='union')\ndifference = gpd.overlay(gdf1, gdf2, how='difference')\nsym_diff = gpd.overlay(gdf1, gdf2, how='symmetric_difference')\n\n# Dissolve (aggregate by attribute)\ndissolved = gdf.dissolve(by='region', aggfunc='sum')\ndissolved = gdf.dissolve(by='region', aggfunc={'population': 'sum', 'area': 'mean'})\n\n# Clip to boundary\nclipped = gpd.clip(gdf, boundary_gdf)\n\n# Distance calculations (use projected CRS)\ndistances = gdf.geometry.distance(single_point)\n\n# Spatial predicates\nwithin_mask = gdf1.geometry.within(gdf2.geometry)\nintersects_mask = gdf1.geometry.intersects(gdf2.geometry)\n```\n\n### 5. Visualization\n\n```python\nimport matplotlib.pyplot as plt\n\n# Basic plot\ngdf.plot(figsize=(10, 8))\n\n# Choropleth map\ngdf.plot(column='population', cmap='YlOrRd', legend=True, figsize=(12, 8))\n\n# Classification schemes (requires mapclassify)\ngdf.plot(column='population', scheme='quantiles', k=5, legend=True)\ngdf.plot(column='population', scheme='fisher_jenks', k=5, legend=True)\n\n# Multi-layer map\nfig, ax = plt.subplots(figsize=(12, 10))\npolygons_gdf.plot(ax=ax, color='lightblue', edgecolor='black')\npoints_gdf.plot(ax=ax, color='red', markersize=10)\nroads_gdf.plot(ax=ax, color='gray', linewidth=0.5)\nax.set_title('Multi-layer Map')\nax.set_axis_off()\n\n# Interactive map (requires folium)\nm = gdf.explore(column='population', cmap='YlOrRd', legend=True,\n                tooltip=['name', 'population'])\nm.save('map.html')\n\n# Multi-layer interactive\nm = gdf1.explore(color='blue', name='Layer 1')\ngdf2.explore(m=m, color='red', name='Layer 2')\nimport folium\nfolium.LayerControl().add_to(m)\n\n# Basemap (requires contextily)\nimport contextily as ctx\ngdf_wm = gdf.to_crs(epsg=3857)\nax = gdf_wm.plot(alpha=0.5, figsize=(10, 10))\nctx.add_basemap(ax)\n```\n\n## Key Concepts\n\n### Data Structures\n\n- **GeoSeries**: Pandas Series of Shapely geometries with spatial methods (area, distance, buffer, etc.)\n- **GeoDataFrame**: Pandas DataFrame with one or more geometry columns. One column is the \"active geometry\" used by spatial methods\n\n```python\nfrom shapely.geometry import Point\n\n# Create from coordinates\ngdf = gpd.GeoDataFrame(\n    {'name': ['A', 'B'], 'value': [10, 20]},\n    geometry=[Point(0, 0), Point(1, 1)],\n    crs=\"EPSG:4326\"\n)\n\n# Multiple geometry columns\ngdf['centroid'] = gdf.geometry.centroid\ngdf = gdf.set_geometry('centroid')  # Switch active geometry\n```\n\n### CRS Rules for Spatial Operations\n\n- **Always check CRS** before any spatial operation: `print(gdf.crs)`\n- **Match CRS** before spatial joins, overlays, or distance calculations\n- **Use projected CRS** (meters) for area\u002Fdistance — geographic CRS (degrees) gives wrong results\n- **set_crs()** only adds metadata; **to_crs()** transforms coordinates\n\n### Spatial Indexing\n\nGeoPandas automatically creates spatial indexes (R-tree) for sjoin, overlay, and other spatial operations. For manual queries:\n\n```python\nsindex = gdf.sindex\npossible_idx = list(sindex.intersection((xmin, ymin, xmax, ymax)))\n```\n\n## Common Workflows\n\n### Workflow 1: Load → Transform → Analyze → Export\n\n```python\nimport geopandas as gpd\n\n# Load\ngdf = gpd.read_file(\"parcels.shp\")\nprint(f\"CRS: {gdf.crs}, Rows: {len(gdf)}\")\n\n# Transform to projected CRS for measurements\ngdf = gdf.to_crs(gdf.estimate_utm_crs())\n\n# Analyze\ngdf['area_ha'] = gdf.geometry.area \u002F 10000  # hectares\ngdf['perimeter_m'] = gdf.geometry.length\nprint(f\"Total area: {gdf['area_ha'].sum():.1f} ha\")\n\n# Export\ngdf.to_file(\"parcels_analyzed.gpkg\")\n```\n\n### Workflow 2: Spatial Join and Aggregate\n\n```python\n# Count points per polygon\npoints_in_poly = gpd.sjoin(points_gdf, polygons_gdf, predicate='within')\ncounts = points_in_poly.groupby('index_right').agg(\n    point_count=('geometry', 'size'),\n    total_value=('value', 'sum')\n)\nresult = polygons_gdf.merge(counts, left_index=True, right_index=True, how='left')\nresult['point_count'] = result['point_count'].fillna(0)\nprint(f\"Polygons with points: {(result['point_count'] > 0).sum()}\u002F{len(result)}\")\n```\n\n### Workflow 3: Multi-Source Integration\n\n```python\n# Read from different sources, ensure matching CRS\nroads = gpd.read_file(\"roads.shp\")\nbuildings = gpd.read_file(\"buildings.geojson\")\nparcels = gpd.read_postgis(\"SELECT * FROM parcels\", con=engine, geom_col='geom')\n\ntarget_crs = roads.crs\nbuildings = buildings.to_crs(target_crs)\nparcels = parcels.to_crs(target_crs)\n\n# Find buildings within 50m of roads\nbuildings_near_roads = gpd.sjoin_nearest(\n    buildings, roads, max_distance=50, distance_col='road_dist'\n)\nprint(f\"Buildings near roads: {len(buildings_near_roads)}\u002F{len(buildings)}\")\n```\n\n## Key Parameters\n\n| Parameter | Function | Default | Effect |\n|-----------|----------|---------|--------|\n| `predicate` | sjoin | `'intersects'` | Spatial relationship: intersects, within, contains, touches, crosses |\n| `how` | sjoin, overlay | `'inner'` | Join type: inner, left, right |\n| `max_distance` | sjoin_nearest | None | Search radius limit (improves performance) |\n| `k` | sjoin_nearest | 1 | Number of nearest neighbors to find |\n| `tolerance` | simplify | Required | Douglas-Peucker tolerance (in CRS units) |\n| `preserve_topology` | simplify | True | Prevents self-intersections |\n| `resolution` | buffer | 16 | Number of segments for buffer curves |\n| `aggfunc` | dissolve | 'first' | Aggregation function for non-geometry columns |\n| `use_arrow` | read_file | False | Enable Arrow acceleration (2-4x faster) |\n| `scheme` | plot | None | Classification: quantiles, equal_interval, fisher_jenks |\n| `k` | plot (with scheme) | 5 | Number of classification bins |\n\n## Best Practices\n\n1. **Always check CRS** before spatial operations — mismatched CRS gives wrong or empty results\n2. **Use projected CRS** for area and distance calculations — geographic CRS (degrees) is meaningless for measurements\n3. **Match CRS before joins** — `gdf2 = gdf2.to_crs(gdf1.crs)` before `gpd.sjoin(gdf1, gdf2)`\n4. **Validate geometries** with `.is_valid` before complex operations — invalid geometries cause silent errors\n5. **Use GeoPackage** over Shapefile — no 10-char column name limit, supports multiple layers, better performance\n6. **Filter during read** — use `bbox`, `columns`, `where` to load only needed data for large files\n7. **Set max_distance in sjoin_nearest** — unbounded nearest-neighbor search is slow on large datasets\n8. **Use `.copy()` when modifying geometry** — avoid unintended side effects on original GeoDataFrame\n\n## Common Recipes\n\n### Recipe: Count Points in Polygons\n\nWhen to use: Aggregate point observations (sample sites, observations) by region (county, watershed).\n\n```python\nimport geopandas as gpd\n\nregions = gpd.read_file(\"regions.geojson\")\npoints = gpd.read_file(\"observations.geojson\").to_crs(regions.crs)\n\njoined = gpd.sjoin(points, regions, how=\"inner\", predicate=\"within\")\ncounts = joined.groupby(\"index_right\").size().rename(\"point_count\")\nregions_with_counts = regions.join(counts).fillna(0)\nregions_with_counts[\"point_count\"] = regions_with_counts[\"point_count\"].astype(int)\nprint(regions_with_counts[[\"name\", \"point_count\"]].sort_values(\"point_count\", ascending=False).head())\n```\n\n### Recipe: Buffer Around Points and Dissolve Overlaps\n\nWhen to use: Create service areas or catchment zones from point locations.\n\n```python\nimport geopandas as gpd\n\nfacilities = gpd.read_file(\"facilities.geojson\")\nutm_crs = facilities.estimate_utm_crs()   # Project to meters\nfacilities_m = facilities.to_crs(utm_crs)\n\n# 1 km buffer\nbuffers = facilities_m.copy()\nbuffers[\"geometry\"] = facilities_m.geometry.buffer(1000)\n\n# Dissolve overlapping buffers into single polygon\nservice_area = buffers.dissolve()\nservice_area_wgs84 = service_area.to_crs(\"EPSG:4326\")\nservice_area_wgs84.to_file(\"service_area.geojson\", driver=\"GeoJSON\")\nprint(f\"Service area: {service_area_wgs84.geometry.area.sum():.0f} sq degrees\")\n```\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| Empty spatial join result | CRS mismatch between GeoDataFrames | Ensure matching CRS: `gdf2 = gdf2.to_crs(gdf1.crs)` |\n| Wrong area\u002Fdistance values | Using geographic CRS (degrees) | Reproject to projected CRS: `gdf.to_crs(gdf.estimate_utm_crs())` |\n| `DriverError` on read | Missing driver or corrupt file | Check file exists; try `driver=\"GeoJSON\"` explicitly |\n| Geometry column lost after merge | Called `df.merge(gdf)` instead of `gdf.merge(df)` | Always call merge ON the GeoDataFrame |\n| `TopologicalError` on overlay | Invalid geometries | Fix with `gdf.geometry = gdf.geometry.buffer(0)` |\n| Slow sjoin_nearest | No distance limit on large dataset | Set `max_distance` parameter |\n| Folium map blank | Geometries not in EPSG:4326 | Reproject to WGS84: `gdf.to_crs(epsg=4326).explore()` |\n| Shapefile column names truncated | Shapefile 10-char limit | Use GeoPackage instead: `gdf.to_file(\"out.gpkg\")` |\n\n## References\n\n- GeoPandas documentation: https:\u002F\u002Fgeopandas.org\u002F\n- GeoPandas GitHub: https:\u002F\u002Fgithub.com\u002Fgeopandas\u002Fgeopandas\n- Shapely documentation: https:\u002F\u002Fshapely.readthedocs.io\u002F\n- EPSG registry: https:\u002F\u002Fepsg.io\u002F\n\n## Related Skills\n\n- **matplotlib-scientific-plotting** — advanced map styling and figure export\n- **polars-dataframes** — high-performance tabular analysis before\u002Fafter spatial operations\n- **folium** — advanced interactive web mapping beyond geopandas.explore()\n",{"name":5,"license":15,"description":7},"master","63f17866001c5ca854bf2fa0b678ce277133de5b","skills\u002Fawesome-skills\u002Fgeopandas-geospatial",0,"https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS","https:\u002F\u002Fbg-szy.github.io\u002FTOP-SKILLS\u002F","https:\u002F\u002Fgithub.com\u002Fbg-szy","https:\u002F\u002Fwww.ecust.edu.cn\u002F","a student of East China University of Science and Technology","2026-11-15 03:38:02",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add bg-szy\u002FTOP-SKILLS --skill geopandas-geospatial",{"tool":40,"command":41},"bunx","bunx skills add bg-szy\u002FTOP-SKILLS --skill geopandas-geospatial",{"tool":43,"command":44},"pnpm","pnpm dlx skills add bg-szy\u002FTOP-SKILLS --skill geopandas-geospatial","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fawesome-skills\u002Fgeopandas-geospatial\u002FSKILL.md",true,[],[49,58,65,72,79,86],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":57},"01M7DXW9N826PKXK174PVW3038","serpmaven","Scrape Google search results (SERP) to JSON with SERP Maven (serpmaven) - a real Chrome browser on a residential proxy with sticky sessions. Run it as a CLI, a Python library, a local HTTP search API (`serve`), an MCP server or a Docker image; set the proxy login, workers, pages and cost tracking. Use when the user wants Google results, rank tracking, a self-hosted SERP API, or live Google search for an AI agent.","MIT","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Fserpmaven\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":57},"01M7DXVHSTWDV65475QEQ915M7","revnu-landing-page-audit","Find out why a landing page isn't turning visitors into signups, demos or sales. Audits one page against what the ad, post or search that sends people there promised, then checks the first screen, proof, call to action, friction and mobile. Returns at most 7 prioritized fixes, plus what is fine and what could not be checked; rewrites specific lines and fixes the page in the repo when asked. Never promises a conversion lift. Works without a Revnu account. Use when the user says or asks: \"audit my landing page\", \"why isn't this page converting\", \"review my homepage\", \"my ads get clicks but no signups\", \"people bounce from the pricing page\", \"CRO review\", \"improve conversion rate\", \"is my hero section clear\", \"roast my landing page\", \"rewrite my headline\", \"what's wrong with this page\", \"landing page feedback\", \"make the signup page convert better\". Not for SEO or AI-search audits, page speed engineering on its own, or building a new page from scratch.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-landing-page-audit\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":57},"01M7DXV8X2D7B3VTD4HHYYHTGR","revnu-growth-context","Write down once who buys, what they're stuck on, what it costs, what proof you have and what you've already tried, so every growth task starts from facts instead of a questionnaire. Creates or updates .agents\u002Frevnu-growth.md from the repo, the live site and the user, and imports an existing product-marketing.md. Use when the user says \"set up our marketing context\", \"who is our ideal customer\", \"write our ICP\", \"describe the product for marketing\", \"positioning doc\", \"what's our brand voice\", \"remember this about our customers\", \"log what we tried\", \"what have we learned from marketing\", \"we changed pricing, update the context\", \"update our growth notes\", \"summarize the business for the agent\", \"import my product-marketing.md\", \"start a growth doc\", or before a first marketing, SEO, outreach or launch task when no context file exists. Works without a Revnu account.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-growth-context\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":57},"01M7DXV0DGJ1G0A60PAHC6J3C5","revnu-get-listed","Get onto the third-party pages AI answers and search cite when buyers ask for the best tool in your category: \"best X\" roundups, directories, review sites, GitHub awesome lists, community threads and comparison pages. Finds which ones are cited, ranks them by fit and effort, and drafts each submission, PR or pitch by the target's own rules. Use when the user says \"get us listed\", \"which directories should we submit to\", \"how do we get into best-of lists\", \"why does ChatGPT recommend competitors and not us\", \"get mentioned in AI answers\", \"submit to awesome lists\", \"get on G2\", \"where are our competitors listed\", \"pitch listicle authors\", \"find backlink opportunities\", \"launch directories\", \"get into roundups\", \"Product Hunt alternatives\", \"where should we be listed\", \"get cited by Perplexity\". Never submits, pays or posts without a yes. Works without a Revnu account.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-get-listed\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":57},"01M7DXTSPMGT9D6DSS0HP9BSTA","revnu-ai-readiness-audit","Audit whether your website gives ChatGPT, Perplexity, Claude, Gemini and Google's AI Overviews something worth quoting, and fix the pages that don't. Use when the user says or asks \"is my site ready for AI search\", \"audit my site for AI answers\", \"AEO audit\", \"GEO audit\", \"why doesn't ChatGPT quote our pricing\", \"make our pages citable by AI\", \"do I need llms.txt\", \"does schema help with ChatGPT\", \"check our structured data\", \"is our content visible without JavaScript\", \"AI SEO audit\", \"optimize our homepage for AI answers\", \"LLM SEO check\", \"why does AI get our product wrong\", \"fix our site for AI Overviews\". Checks fetchability and indexability, answers in the raw HTML, entity facts, schema (including JS-injected markup), headings, dates and llms.txt, then gives at most 10 prioritised fixes and edits the repo when asked. Works without a Revnu account.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Frevnu-ai-readiness-audit\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":53,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":57},"01M7DXSZHCVTRS620GC3S97JZV","proxy-troubleshooting","Diagnose residential proxy failures, with NodeMaven's gateway as the reference - 407 with correct credentials, 406, 410, 500, a connection that hangs, ERR_TUNNEL_CONNECTION_FAILED in a browser, Playwright or Puppeteer ignoring proxy credentials, a sticky session that changes IP, geo-targeting that is silently ignored, passwords with special characters, and unexpected traffic from headless Chrome. Use when a proxy connection fails, returns the wrong location, or costs more traffic than expected.","https:\u002F\u002Fgithub.com\u002Fbg-szy\u002FTOP-SKILLS\u002Fblob\u002Fmaster\u002Fskills\u002Fmarketplace\u002Fproxy-troubleshooting\u002FSKILL.md",[],[]]