Source: https://github.com/aipoch/medical-research-skills
When to Use
- You need to load and export vector geospatial data (Shapefile, GeoJSON, GeoPackage, Parquet) and keep attributes + geometry together.
- You want to run geometric operations such as buffer, simplify, centroid, convex hull, or distance/area calculations.
- You need spatial analysis like spatial joins (intersects/within/nearest), overlay (intersection/union/difference), dissolve, or clipping.
- You must manage coordinate reference systems (CRS): inspect CRS, set missing CRS metadata, or reproject between EPSG codes.
- You want to visualize geospatial data as static plots (matplotlib) or interactive maps (folium-backed
explore()).
Key Features
- GeoDataFrame / GeoSeries: pandas-like tabular structures with a geometry column and vectorized spatial methods.
- Multi-format I/O: read/write common GIS formats and integrate with PostGIS.
- CRS-aware transformations:
set_crs() for metadata, to_crs() for coordinate transformation.
- Spatial operations: buffer/simplify/centroid and higher-level analysis (sjoin, overlay, dissolve).
- Mapping: quick plotting and choropleths; optional interactive exploration.
(Additional conceptual references: references/data-structures.md, references/data-io.md, references/crs-management.md, references/geometric-operations.md, references/spatial-analysis.md, references/visualization.md.)
Dependencies
Core:
geopandas (latest)
pandas (transitive)
shapely (transitive)
Optional (install as needed):
folium (interactive maps via GeoDataFrame.explore())
mapclassify (classification schemes for choropleths)
pyarrow (faster I/O; enables use_arrow=True in some writers)
psycopg2 and geoalchemy2 (PostGIS connectivity)
contextily (basemaps)
cartopy (map projections / advanced cartographic plotting)
Example Usage
import geopandas as gpd
def main():
# 1) Read vector data (GeoJSON/Shapefile/GeoPackage/etc.)
gdf = gpd.read_file("data.geojson")
# 2) Inspect CRS and geometry types
print("CRS:", gdf.crs)
print("Geometry types:", gdf.geometry.geom_type.unique())
# 3) Reproject for metric calculations (area/distance)
# Use a projected CRS appropriate for your region; EPSG:3857 is common but not always ideal.
gdf_m = gdf.to_crs("EPSG:3857")
# 4) Compute area and create a buffer (units are CRS units; meters in many projected CRSs)
gdf_m["area_m2"] = gdf_m.geometry.area
gdf_m["geometry"] = gdf_m.geometry.buffer(100)
# 5) Plot a quick choropleth (static)
ax = gdf_m.plot(column="area_m2", cmap="YlOrRd", legend=True)
ax.set_title("Buffered features colored by area (m²)")
# 6) Write results to GeoPackage
gdf_m.to_file("output.gpkg", layer="buffered", driver="GPKG")
if __name__ == "__main__":
main()
Implementation Details
Data model
GeoSeries: a 1D array of geometries with vectorized spatial methods.
GeoDataFrame: a pandas DataFrame with a designated geometry column (commonly named geometry).
CRS rules
set_crs("EPSG:4326") sets CRS metadata without transforming coordinates (use only when CRS is missing/unknown but you are sure of it).
to_crs("EPSG:3857") transforms coordinates into a new CRS.
- Area/distance should be computed in a projected CRS (units typically meters/feet). Geographic CRS (lat/lon) is not suitable for metric area/distance.
Spatial joins
gpd.sjoin(left, right, predicate="intersects"|"within"|"contains"|...) matches features using a spatial predicate.
gpd.sjoin_nearest(..., max_distance=...) performs nearest-neighbor matching; setting max_distance can reduce work and avoid unexpected far matches.
Overlay operations
gpd.overlay(gdf1, gdf2, how="intersection"|"union"|"difference"|...) computes polygon overlays; complexity grows with geometry vertex count, so simplifying geometries can improve performance when high precision is not required.
I/O performance
- When supported, enabling Arrow-backed paths (e.g.,
use_arrow=True) can speed up read/write operations; pyarrow is typically required.
- Use read-time filters like
bbox= (and format-specific filters) to avoid loading unnecessary features.
When Not to Use
- Do not use this skill when the required source data, identifiers, files, or credentials are missing.
- Do not use this skill when the user asks for fabricated results, unsupported claims, or out-of-scope conclusions.
- Do not use this skill when a simpler direct answer is more appropriate than the documented workflow.
Required Inputs
- A clearly specified task goal aligned with the documented scope.
- All required files, identifiers, parameters, or environment variables before execution.
- Any domain constraints, formatting requirements, and expected output destination if applicable.
Recommended Workflow
- Validate the request against the skill boundary and confirm all required inputs are present.
- Select the documented execution path and prefer the simplest supported command or procedure.
- Produce the expected output using the documented file format, schema, or narrative structure.
- Run a final validation pass for completeness, consistency, and safety before returning the result.
Deterministic Output Rules
- Use the same section order for every supported request of this skill.
- Keep output field names stable and do not rename documented keys across examples.
- If a value is unavailable, emit an explicit placeholder instead of omitting the field.
Output Contract
- Return a structured deliverable that is directly usable without reformatting.
- If a file is produced, prefer a deterministic output name such as
geopandas_result.md unless the skill documentation defines a better convention.
- Include a short validation summary describing what was checked, what assumptions were made, and any remaining limitations.
Validation and Safety Rules
- Validate required inputs before execution and stop early when mandatory fields or files are missing.
- Do not fabricate measurements, references, findings, or conclusions that are not supported by the provided source material.
- Emit a clear warning when credentials, privacy constraints, safety boundaries, or unsupported requests affect the result.
- Keep the output safe, reproducible, and within the documented scope at all times.
Failure Handling
- If validation fails, explain the exact missing field, file, or parameter and show the minimum fix required.
- If an external dependency or script fails, surface the command path, likely cause, and the next recovery step.
- If partial output is returned, label it clearly and identify which checks could not be completed.
Completion Checklist
- Confirm all required inputs were present and valid.
- Confirm the supported execution path completed without unresolved errors.
- Confirm the final deliverable matches the documented format exactly.
- Confirm assumptions, limitations, and warnings are surfaced explicitly.
Quick Validation
Run this minimal verification path before full execution when possible:
No local script validation step is required for this skill.
Expected output format:
Result file: geopandas_result.md
Validation summary: PASS/FAIL with brief notes
Assumptions: explicit list if any
Scope Reminder
- Core purpose: A Python library for reading, writing, and analyzing geospatial vector data; use it when you need spatial operations (buffer/overlay/join), CRS reprojection, or map visualization on formats like Shapefile/GeoJSON/GeoPackage or PostGIS.
1---2name: geopandas3description: A Python library for reading, writing, and analyzing geospatial vector data; use it when you need spatial operations (buffer/overlay/join), CRS reprojection, or map visualization on formats like Shapefile/GeoJSON/GeoPackage or PostGIS.4license: MIT5---6> **Source**: [https://github.com/aipoch/medical-research-skills](https://github.com/aipoch/medical-research-skills)78## When to Use910- You need to **load and export vector geospatial data** (Shapefile, GeoJSON, GeoPackage, Parquet) and keep attributes + geometry together.11- You want to run **geometric operations** such as buffer, simplify, centroid, convex hull, or distance/area calculations.12- You need **spatial analysis** like spatial joins (intersects/within/nearest), overlay (intersection/union/difference), dissolve, or clipping.13- You must **manage coordinate reference systems (CRS)**: inspect CRS, set missing CRS metadata, or reproject between EPSG codes.14- You want to **visualize geospatial data** as static plots (matplotlib) or interactive maps (folium-backed `explore()`).1516## Key Features1718- **GeoDataFrame / GeoSeries**: pandas-like tabular structures with a geometry column and vectorized spatial methods.19- **Multi-format I/O**: read/write common GIS formats and integrate with PostGIS.20- **CRS-aware transformations**: `set_crs()` for metadata, `to_crs()` for coordinate transformation.21- **Spatial operations**: buffer/simplify/centroid and higher-level analysis (sjoin, overlay, dissolve).22- **Mapping**: quick plotting and choropleths; optional interactive exploration.2324(Additional conceptual references: `references/data-structures.md`, `references/data-io.md`, `references/crs-management.md`, `references/geometric-operations.md`, `references/spatial-analysis.md`, `references/visualization.md`.)2526## Dependencies2728Core:29- `geopandas` (latest)30- `pandas` (transitive)31- `shapely` (transitive)3233Optional (install as needed):34- `folium` (interactive maps via `GeoDataFrame.explore()`)35- `mapclassify` (classification schemes for choropleths)36- `pyarrow` (faster I/O; enables `use_arrow=True` in some writers)37- `psycopg2` and `geoalchemy2` (PostGIS connectivity)38- `contextily` (basemaps)39- `cartopy` (map projections / advanced cartographic plotting)4041## Example Usage4243```python44import geopandas as gpd4546def main():47 # 1) Read vector data (GeoJSON/Shapefile/GeoPackage/etc.)48 gdf = gpd.read_file("data.geojson")4950 # 2) Inspect CRS and geometry types51 print("CRS:", gdf.crs)52 print("Geometry types:", gdf.geometry.geom_type.unique())5354 # 3) Reproject for metric calculations (area/distance)55 # Use a projected CRS appropriate for your region; EPSG:3857 is common but not always ideal.56 gdf_m = gdf.to_crs("EPSG:3857")5758 # 4) Compute area and create a buffer (units are CRS units; meters in many projected CRSs)59 gdf_m["area_m2"] = gdf_m.geometry.area60 gdf_m["geometry"] = gdf_m.geometry.buffer(100)6162 # 5) Plot a quick choropleth (static)63 ax = gdf_m.plot(column="area_m2", cmap="YlOrRd", legend=True)64 ax.set_title("Buffered features colored by area (m²)")6566 # 6) Write results to GeoPackage67 gdf_m.to_file("output.gpkg", layer="buffered", driver="GPKG")6869if __name__ == "__main__":70 main()71```7273## Implementation Details7475- **Data model**76 - `GeoSeries`: a 1D array of geometries with vectorized spatial methods.77 - `GeoDataFrame`: a pandas DataFrame with a designated geometry column (commonly named `geometry`).7879- **CRS rules**80 - `set_crs("EPSG:4326")` sets CRS metadata **without transforming coordinates** (use only when CRS is missing/unknown but you are sure of it).81 - `to_crs("EPSG:3857")` **transforms coordinates** into a new CRS.82 - **Area/distance** should be computed in a **projected CRS** (units typically meters/feet). Geographic CRS (lat/lon) is not suitable for metric area/distance.8384- **Spatial joins**85 - `gpd.sjoin(left, right, predicate="intersects"|"within"|"contains"|...)` matches features using a spatial predicate.86 - `gpd.sjoin_nearest(..., max_distance=...)` performs nearest-neighbor matching; setting `max_distance` can reduce work and avoid unexpected far matches.8788- **Overlay operations**89 - `gpd.overlay(gdf1, gdf2, how="intersection"|"union"|"difference"|...)` computes polygon overlays; complexity grows with geometry vertex count, so simplifying geometries can improve performance when high precision is not required.9091- **I/O performance**92 - When supported, enabling Arrow-backed paths (e.g., `use_arrow=True`) can speed up read/write operations; `pyarrow` is typically required.93 - Use read-time filters like `bbox=` (and format-specific filters) to avoid loading unnecessary features.9495## When Not to Use9697- Do not use this skill when the required source data, identifiers, files, or credentials are missing.98- Do not use this skill when the user asks for fabricated results, unsupported claims, or out-of-scope conclusions.99- Do not use this skill when a simpler direct answer is more appropriate than the documented workflow.100101## Required Inputs102103- A clearly specified task goal aligned with the documented scope.104- All required files, identifiers, parameters, or environment variables before execution.105- Any domain constraints, formatting requirements, and expected output destination if applicable.106107## Recommended Workflow1081091. Validate the request against the skill boundary and confirm all required inputs are present.1102. Select the documented execution path and prefer the simplest supported command or procedure.1113. Produce the expected output using the documented file format, schema, or narrative structure.1124. Run a final validation pass for completeness, consistency, and safety before returning the result.113114## Deterministic Output Rules115116- Use the same section order for every supported request of this skill.117- Keep output field names stable and do not rename documented keys across examples.118- If a value is unavailable, emit an explicit placeholder instead of omitting the field.119120## Output Contract121122- Return a structured deliverable that is directly usable without reformatting.123- If a file is produced, prefer a deterministic output name such as `geopandas_result.md` unless the skill documentation defines a better convention.124- Include a short validation summary describing what was checked, what assumptions were made, and any remaining limitations.125126## Validation and Safety Rules127128- Validate required inputs before execution and stop early when mandatory fields or files are missing.129- Do not fabricate measurements, references, findings, or conclusions that are not supported by the provided source material.130- Emit a clear warning when credentials, privacy constraints, safety boundaries, or unsupported requests affect the result.131- Keep the output safe, reproducible, and within the documented scope at all times.132133## Failure Handling134135- If validation fails, explain the exact missing field, file, or parameter and show the minimum fix required.136- If an external dependency or script fails, surface the command path, likely cause, and the next recovery step.137- If partial output is returned, label it clearly and identify which checks could not be completed.138139## Completion Checklist140141- Confirm all required inputs were present and valid.142- Confirm the supported execution path completed without unresolved errors.143- Confirm the final deliverable matches the documented format exactly.144- Confirm assumptions, limitations, and warnings are surfaced explicitly.145146## Quick Validation147148Run this minimal verification path before full execution when possible:149150```text151No local script validation step is required for this skill.152```153154Expected output format:155156```text157Result file: geopandas_result.md158Validation summary: PASS/FAIL with brief notes159Assumptions: explicit list if any160```161162## Scope Reminder163164- Core purpose: A Python library for reading, writing, and analyzing geospatial vector data; use it when you need spatial operations (buffer/overlay/join), CRS reprojection, or map visualization on formats like Shapefile/GeoJSON/GeoPackage or PostGIS.