turfpy
raw JSON → 0.0.8 verified Fri May 01 auth: no python
A Python library for geospatial data analysis that reimplements turf.js. Current version 0.0.8, released periodically with incremental improvements.
pip install turfpy Common errors
error AttributeError: module 'turfpy' has no attribute 'distance' ↓
cause distance is in turfpy.measurement submodule, not top-level.
fix
Use from turfpy import measurement; measurement.distance(...)
error TypeError: Object of type Polygon is not JSON serializable ↓
cause turfpy expects GeoJSON Feature or geometry dict, not raw shapely object.
fix
Convert to GeoJSON: from geojson import Feature; Feature(geometry=your_shapely_polygon)
error ModuleNotFoundError: No module named 'turfpy' ↓
cause turfpy not installed or installed in wrong environment.
fix
Run 'pip install turfpy' or check that you're in the correct Python environment.
Warnings
gotcha turfpy expects GeoJSON Feature objects, not raw shapely geometries. Convert polygons to GeoJSON features before passing to functions like area or length. ↓
fix Use geojson library to wrap geometries: Feature(geometry=Polygon(...))
deprecated Boolean operations like intersect, union, difference were moved to a separate submodule in v0.0.8. Importing from top-level turfpy may break. ↓
fix Use from turfpy import boolean_ops or from turfpy.boolean_ops import ...
gotcha The area function returns square meters for geographic coordinates, not degrees. If you need other units, convert beforehand. ↓
fix Use turfpy.measurement.area with appropriate coordinate system or convert output.
Imports
- turfpy wrong
from turfpy import ...correctimport turfpy - measurement wrong
import measurementcorrectfrom turfpy import measurement
Quickstart
import turfpy
from turfpy import measurement
from geojson import Point, Feature
point1 = Feature(geometry=Point((-3.0, 53.0)))
point2 = Feature(geometry=Point((-2.0, 55.0)))
distance = measurement.distance(point1, point2)
print(f'Distance: {distance}')