turfpy.misc module¶
This module implements some of the spatial analysis techniques and processes used to analyse geojson linestring. This is mainly inspired by turf.js Misc section. link: http://turfjs.org/
- turfpy.misc.line_intersect(feature1, feature2)[source]¶
Takes any LineString or Polygon GeoJSON and returns the intersecting point(s). If one of the Features is polygon pass the polygon feature as the first parameter to improve performance. To use this functionality Rtree or pygeos is needed to be installed.
See installation instructions at https://geopandas.org/install.html
- Parameters
feature1 (Union[geojson.geometry.LineString, geojson.geometry.Polygon, geojson.geometry.MultiLineString, geojson.geometry.MultiPolygon, geojson.feature.Feature]) – Any LineString or Polygon, if one of the two features is polygon to improve performance please pass polygon as this parameter.
feature2 (Union[geojson.geometry.LineString, geojson.geometry.Polygon, geojson.geometry.MultiLineString, geojson.geometry.MultiPolygon, geojson.feature.Feature]) – Any LineString or Polygon.
- Returns
FeatureCollection of intersecting points.
- Return type
geojson.feature.FeatureCollection
Exmaple: >>> from geojson import LineString, Feature >>> from turfpy.misc import line_intersect >>> l1 = Feature(geometry=LineString([[126, -11], [129, -21]])) >>> l2 = Feature(geometry=LineString([[123, -18], [131, -14]])) >>> line_intersect(l1, l2)
- turfpy.misc.line_segment(geojson)[source]¶
Creates a FeatureCollection of 2-vertex LineString segments from a (Multi)LineString or (Multi)Polygon. :param geojson: GeoJSON Polygon or LineString :return: FeatureCollection of 2-vertex line segments
Example: >>> from turfpy.misc import line_segment >>> >>> poly = { … “type”: “Feature”, … “properties”: {}, … “geometry”: { … “type”: “Polygon”, … “coordinates”: [ … [ … [ … 51.17431640625, … 47.025206001585396 … ], … [ … 45.17578125, … 43.13306116240612 … ], … [ … 54.5361328125, … 41.85319643776675 … ], … [ … 51.17431640625, … 47.025206001585396 … ] … ] … ] … } … } … >>> line_segment(poly)
- Parameters
geojson (Union[geojson.geometry.LineString, geojson.geometry.Polygon, geojson.geometry.MultiLineString, geojson.geometry.MultiPolygon, geojson.feature.Feature]) –
- Return type
geojson.feature.FeatureCollection
- turfpy.misc.line_segment_feature(geojson, results)[source]¶
- Parameters
geojson (Union[geojson.geometry.LineString, geojson.geometry.Polygon]) –
results (List[geojson.feature.Feature]) –
- Returns
- turfpy.misc.create_segments(coords, properties)[source]¶
Create Segments from LineString coordinates :param coords: coords LineString coordinates :param properties: properties GeoJSON properties :return: Line segments Features
- turfpy.misc.bbox(coords1, coords2)[source]¶
Create BBox between two coordinates :param coords1: coords1 Point coordinate :param coords2: coords2 Point coordinate :return: Bounding Box as [west, south, east, north]
- turfpy.misc.nearest_point_on_line(line, point, options={})[source]¶
Takes a Point and a LineString and calculates the closest Point on the (Multi)LineString.
- Parameters
line (Union[geojson.geometry.LineString, geojson.geometry.MultiLineString]) – line(s) to snap to
point (geojson.geometry.Point) – point to snap from
options (dict) – Option like units of distance and properties to be passed to destination point feature. Value for units are ‘mi’, ‘km’, ‘deg’ and ‘rad’.
- Returns
Feature: closest point on the line to point. The properties object will contain three values: index: closest point was found on nth line part, dist: distance between pt and the closest point, location: distance along the line between start and the closest point.
- Return type
geojson.geometry.Point
- turfpy.misc.line_slice(start_pt, stop_pt, line)[source]¶
Takes a LineString, a start Point, and a stop Point and returns a subsection of the line in-between those points. The start & stop points don’t need to fall exactly on the line.
This can be useful for extracting only the part of a route between waypoints.
- Parameters
start_pt (geojson.geometry.Point) – starting point
stop_pt (geojson.geometry.Point) – stopping point
line (geojson.geometry.LineString) – line to slice
- Returns
sliced line as LineString Feature
- Return type
geojson.geometry.LineString
- turfpy.misc.line_arc(center, radius, bearing1, bearing2, options={})[source]¶
Creates a circular arc, of a circle of the given radius and center point, between bearing1 and bearing2; 0 bearing is North of center point, positive clockwise.
- Parameters
center (geojson.feature.Feature) – A Point object representing center point of circle.
radius (int) – An int representing radius of the circle.
bearing1 (int) – Angle, in decimal degrees, of the first radius of the arc.
bearing2 (int) – Angle, in decimal degrees, of the second radius of the arc.
options (dict) – A dict representing additional properties,which can be steps which has default values as 64 and units which has default values of km
- Returns
A Line String feature object.
- Return type
geojson.feature.Feature
Example:
>>> from turfpy.misc import line_arc >>> from geojson import Feature, Point >>> center = Feature(geometry=Point((-75, 40))) >>> radius = 5 >>> bearing1 = 25 >>> bearing2 = 47 >>> feature = line_arc(center=center, radius=radius, >>> bearing1=bearing1, bearing2=bearing2)
- turfpy.misc.sector(center, radius, bearing1, bearing2, options={})[source]¶
Creates a circular sector of a circle of given radius and center Point , between (clockwise) bearing1 and bearing2; 0 bearing is North of center point, positive clockwise.
- Parameters
center (geojson.feature.Feature) – A Point object representing center point of circle.
radius (int) – An int representing radius of the circle.
bearing1 (int) – Angle, in decimal degrees, of the first radius of the arc.
bearing2 (int) – Angle, in decimal degrees, of the second radius of the arc.
options (dict) – A dict representing additional properties, which can be steps which has default values as 64, units which has default values of km, and properties which will be added to resulting Feature as properties.
- Returns
A polygon feature object.
- Return type
geojson.feature.Feature
Example:
>>> from turfpy.misc import sector >>> from geojson import Feature, Point >>> center = Feature(geometry=Point((-75, 40))) >>> radius = 5 >>> bearing1 = 25 >>> bearing2 = 45 >>> sector(center, radius, bearing1, bearing2)