This notebook demonstrates all the examples of transformation
Takes a Point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.
from geojson import Feature, Point
from turfpy.transformation import circle
center = Feature(geometry=Point((19.0760, 72.8777)))
circle(center, radius=5, steps=10)
Takes a Feature or geometry and a bbox and clips the feature to the bbox.
from turfpy.transformation import bbox_clip
from geojson import Feature
f = Feature(geometry={"coordinates": [[[2, 2], [8, 4],
[12, 8], [3, 7], [2, 2]]], "type": "Polygon"})
bbox = [0, 0, 10, 10]
bbox_clip(f, bbox)
Takes a line and returns a curved version by applying a Bezier spline algorithm.
from geojson import LineString, Feature
from turfpy.transformation import bezie_spline
ls = LineString([(-76.091308, 18.427501),
(-76.695556, 18.729501),
(-76.552734, 19.40443),
(-74.61914, 19.134789),
(-73.652343, 20.07657),
(-73.157958, 20.210656)])
f = Feature(geometry=ls)
bezie_spline(f)
Generate concave hull for the given feature or Feature Collection.
from turfpy.transformation import concave
from geojson import FeatureCollection, Feature, Point
f1 = Feature(geometry=Point((-63.601226, 44.642643)))
f2 = Feature(geometry=Point((-63.591442, 44.651436)))
f3 = Feature(geometry=Point((-63.580799, 44.648749)))
f4 = Feature(geometry=Point((-63.573589, 44.641788)))
f5 = Feature(geometry=Point((-63.587665, 44.64533)))
f6 = Feature(geometry=Point((-63.595218, 44.64765)))
fc = [f1, f2, f3, f4, f5, f6]
concave(FeatureCollection(fc), alpha=100)
Generate convex hull for the given feature or Feature Collection.
from turfpy.transformation import convex
from geojson import FeatureCollection, Feature, Point
f1 = Feature(geometry=Point((10.195312, 43.755225)))
f2 = Feature(geometry=Point((10.404052, 43.8424511)))
f3 = Feature(geometry=Point((10.579833, 43.659924)))
f4 = Feature(geometry=Point((10.360107, 43.516688)))
f5 = Feature(geometry=Point((10.14038, 43.588348)))
f6 = Feature(geometry=Point((10.195312, 43.755225)))
fc = [f1, f2, f3, f4, f5, f6]
convex(FeatureCollection(fc))
Takes polygons and finds their intersection.
from turfpy.transformation import intersect
from geojson import Feature
f = Feature(geometry={"coordinates": [
[[-122.801742, 45.48565], [-122.801742, 45.60491],
[-122.584762, 45.60491], [-122.584762, 45.48565],
[-122.801742, 45.48565]]], "type": "Polygon"})
b = Feature(geometry={"coordinates": [
[[-122.520217, 45.535693], [-122.64038, 45.553967],
[-122.720031, 45.526554], [-122.669906, 45.507309],
[-122.723464, 45.446643], [-122.532577, 45.408574],
[-122.487258, 45.477466], [-122.520217, 45.535693]
]], "type": "Polygon"})
intersect([f, b])
Given list of features or FeatureCollection return union of those.
from turfpy.transformation import union
from geojson import Feature, Polygon, FeatureCollection
f1 = Feature(geometry=Polygon([[
[-82.574787, 35.594087],
[-82.574787, 35.615581],
[-82.545261, 35.615581],
[-82.545261, 35.594087],
[-82.574787, 35.594087]
]]), properties={"fill": "#00f"})
f2 = Feature(geometry=Polygon([[
[-82.560024, 35.585153],
[-82.560024, 35.602602],
[-82.52964, 35.602602],
[-82.52964, 35.585153],
[-82.560024, 35.585153]]]), properties={"fill": "#00f"})
union(FeatureCollection([f1, f2], properties={"combine": "yes"}))
Take FeatureCollection or list of features to dissolve based on property_name provided.
from geojson import Polygon, Feature, FeatureCollection
from turfpy.transformation import dissolve
f1 = Feature(geometry=Polygon([[
[0, 0],
[0, 1],
[1, 1],
[1, 0],
[0, 0]]]), properties={"combine": "yes", "fill": "#00f"})
f2 = Feature(geometry=Polygon([[
[0, -1],
[0, 0],
[1, 0],
[1, -1],
[0,-1]]]), properties={"combine": "yes"})
f3 = Feature(geometry=Polygon([[
[1,-1],
[1, 0],
[2, 0],
[2, -1],
[1, -1]]]), properties={"combine": "no"})
dissolve(FeatureCollection([f1, f2, f3]), property_name='combine')
Find the difference between given two features.
from geojson import Polygon, Feature
from turfpy.transformation import difference
f1 = Feature(geometry=Polygon([[
[128, -26],
[141, -26],
[141, -21],
[128, -21],
[128, -26]]]), properties={"combine": "yes", "fill": "#00f"})
f2 = Feature(geometry=Polygon([[
[126, -28],
[140, -28],
[140, -20],
[126, -20],
[126, -28]]]), properties={"combine": "yes"})
difference(f1, f2)