pyinterp.geometry.geographic.algorithms.from_geojson

Contents

pyinterp.geometry.geographic.algorithms.from_geojson#

pyinterp.geometry.geographic.algorithms.from_geojson(geojson: str) → pyinterp.core.geometry.geographic.Point | pyinterp.core.geometry.geographic.LineString | pyinterp.core.geometry.geographic.Ring | pyinterp.core.geometry.geographic.Polygon | pyinterp.core.geometry.geographic.MultiPoint | pyinterp.core.geometry.geographic.MultiLineString | pyinterp.core.geometry.geographic.MultiPolygon#

Creates a geometry from GeoJSON representation.

Parses a GeoJSON string and constructs the corresponding geometry object. The function automatically detects the geometry type from the GeoJSON “type” field and returns the appropriate geometry object.

Parameters:

geojson – GeoJSON string representation of the geometry.

Returns:

Point, LineString, Ring, Polygon, MultiPoint, MultiLineString, or MultiPolygon depending on the GeoJSON type field.

Return type:

A variant containing one of

Examples

>>> geojson_str = '{"type":"Point","coordinates":[1.0,2.0]}'
>>> point = from_geojson(geojson_str)
>>> # Returns Point(1.0, 2.0)
>>> geojson_str = '{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]}'
>>> polygon = from_geojson(geojson_str)
>>> # Returns Polygon object