Skip to content

Commit

Permalink
Added docs changes and notebook changes
Browse files Browse the repository at this point in the history
  • Loading branch information
omanges committed Jul 11, 2020
1 parent 1b92c84 commit 3b584cc
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ You can install the Turfpy from [PyPI](https://pypi.org/project/turfpy/):

It supports various functionalities:

Measurement functions: [measurements](measurements.md)
Measurement functions: [measurements](https://github.com/omanges/turfpy/blob/master/measurements.md)

Transformation functions: [transformation](transformation.md)
Transformation functions: [transformation](https://github.com/omanges/turfpy/blob/master/transformation.md)


2 changes: 1 addition & 1 deletion examples/measurements.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down
233 changes: 231 additions & 2 deletions examples/transformations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"metadata": {},
"source": [
"## Circle\n",
"Takes a Point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision"
"Takes a Point and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision."
]
},
{
Expand All @@ -28,6 +28,235 @@
"center = Feature(geometry=Point((19.0760, 72.8777)))\n",
"circle(center, radius=5, steps=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bbox clip\n",
"Takes a Feature or geometry and a bbox and clips the feature to the bbox."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from turfpy.transformation import bbox_clip\n",
"from geojson import Feature\n",
"f = Feature(geometry={\"coordinates\": [[[2, 2], [8, 4],\n",
"[12, 8], [3, 7], [2, 2]]], \"type\": \"Polygon\"})\n",
"bbox = [0, 0, 10, 10]\n",
"bbox_clip(f, bbox)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bezie spline\n",
"Takes a line and returns a curved version by applying a Bezier spline algorithm."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from geojson import LineString, Feature\n",
"from turfpy.transformation import bezie_spline\n",
"ls = LineString([(-76.091308, 18.427501),\n",
" (-76.695556, 18.729501),\n",
" (-76.552734, 19.40443),\n",
" (-74.61914, 19.134789),\n",
" (-73.652343, 20.07657),\n",
" (-73.157958, 20.210656)])\n",
"f = Feature(geometry=ls)\n",
"bezie_spline(f)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Concave Hull\n",
"Generate concave hull for the given feature or Feature Collection."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from turfpy.transformation import concave\n",
"from geojson import FeatureCollection, Feature, Point\n",
"f1 = Feature(geometry=Point((-63.601226, 44.642643)))\n",
"f2 = Feature(geometry=Point((-63.591442, 44.651436)))\n",
"f3 = Feature(geometry=Point((-63.580799, 44.648749)))\n",
"f4 = Feature(geometry=Point((-63.573589, 44.641788)))\n",
"f5 = Feature(geometry=Point((-63.587665, 44.64533)))\n",
"f6 = Feature(geometry=Point((-63.595218, 44.64765)))\n",
"fc = [f1, f2, f3, f4, f5, f6]\n",
"concave(FeatureCollection(fc), alpha=100)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Convex Hull\n",
"Generate convex hull for the given feature or Feature Collection."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from turfpy.transformation import convex\n",
"from geojson import FeatureCollection, Feature, Point\n",
"f1 = Feature(geometry=Point((10.195312, 43.755225)))\n",
"f2 = Feature(geometry=Point((10.404052, 43.8424511)))\n",
"f3 = Feature(geometry=Point((10.579833, 43.659924)))\n",
"f4 = Feature(geometry=Point((10.360107, 43.516688)))\n",
"f5 = Feature(geometry=Point((10.14038, 43.588348)))\n",
"f6 = Feature(geometry=Point((10.195312, 43.755225)))\n",
"fc = [f1, f2, f3, f4, f5, f6]\n",
"convex(FeatureCollection(fc))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Intersect\n",
"Takes polygons and finds their intersection."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from turfpy.transformation import intersect\n",
"from geojson import Feature\n",
"f = Feature(geometry={\"coordinates\": [\n",
"[[-122.801742, 45.48565], [-122.801742, 45.60491],\n",
"[-122.584762, 45.60491], [-122.584762, 45.48565],\n",
"[-122.801742, 45.48565]]], \"type\": \"Polygon\"})\n",
"b = Feature(geometry={\"coordinates\": [\n",
"[[-122.520217, 45.535693], [-122.64038, 45.553967],\n",
"[-122.720031, 45.526554], [-122.669906, 45.507309],\n",
"[-122.723464, 45.446643], [-122.532577, 45.408574],\n",
"[-122.487258, 45.477466], [-122.520217, 45.535693]\n",
"]], \"type\": \"Polygon\"})\n",
"intersect([f, b])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Union\n",
"Given list of features or FeatureCollection return union of those."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from turfpy.transformation import union\n",
"from geojson import Feature, Polygon, FeatureCollection\n",
"f1 = Feature(geometry=Polygon([[\n",
" [-82.574787, 35.594087],\n",
" [-82.574787, 35.615581],\n",
" [-82.545261, 35.615581],\n",
" [-82.545261, 35.594087],\n",
" [-82.574787, 35.594087]\n",
"]]), properties={\"fill\": \"#00f\"})\n",
"f2 = Feature(geometry=Polygon([[\n",
" [-82.560024, 35.585153],\n",
" [-82.560024, 35.602602],\n",
" [-82.52964, 35.602602],\n",
" [-82.52964, 35.585153],\n",
" [-82.560024, 35.585153]]]), properties={\"fill\": \"#00f\"})\n",
"union(FeatureCollection([f1, f2], properties={\"combine\": \"yes\"}))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dissolve\n",
"Take FeatureCollection or list of features to dissolve based on property_name provided."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from geojson import Polygon, Feature, FeatureCollection\n",
"from turfpy.transformation import dissolve\n",
"f1 = Feature(geometry=Polygon([[\n",
" [0, 0],\n",
" [0, 1],\n",
" [1, 1],\n",
" [1, 0],\n",
" [0, 0]]]), properties={\"combine\": \"yes\", \"fill\": \"#00f\"})\n",
"f2 = Feature(geometry=Polygon([[\n",
" [0, -1],\n",
" [0, 0],\n",
" [1, 0],\n",
" [1, -1],\n",
" [0,-1]]]), properties={\"combine\": \"yes\"})\n",
"f3 = Feature(geometry=Polygon([[\n",
" [1,-1],\n",
" [1, 0],\n",
" [2, 0],\n",
" [2, -1],\n",
" [1, -1]]]), properties={\"combine\": \"no\"})\n",
"dissolve(FeatureCollection([f1, f2, f3]), property_name='combine')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Difference\n",
"Find the difference between given two features."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from geojson import Polygon, Feature\n",
"from turfpy.transformation import difference\n",
"f1 = Feature(geometry=Polygon([[\n",
" [128, -26],\n",
" [141, -26],\n",
" [141, -21],\n",
" [128, -21],\n",
" [128, -26]]]), properties={\"combine\": \"yes\", \"fill\": \"#00f\"})\n",
"f2 = Feature(geometry=Polygon([[\n",
" [126, -28],\n",
" [140, -28],\n",
" [140, -20],\n",
" [126, -20],\n",
" [126, -28]]]), properties={\"combine\": \"yes\"})\n",
"difference(f1, f2)"
]
}
],
"metadata": {
Expand All @@ -46,7 +275,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.7.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 3b584cc

Please sign in to comment.