Skip to main content

fromGeoJSON

Creates a Geometry from GeoJSON representation.

This function has 2 overloads, when called with:

  • GeoJSON Geometry or GeoJSON Feature it returns a single geometry,
  • GeoJSON FeatureCollection it returns an array of geometries.

In addition to the 7 standard GeoJSON geometries, this reader also supports JSON representation of other geometries supported by GEOS like JSON_CircularString, JSON_CompoundCurve or JSON_CurvePolygon.

Reader expects that all positions in an input geometry have the same number of elements. The geometry coordinate dimension is determined from the first encountered position.

Type Parameters

  • P - The type of geometry/feature properties

Parameters

NameTypeDefaultDescription
geojsonGeoJSON_Geometry | GeoJSON_Feature<GeoJSON_Geometry, P> | GeoJSON_FeatureCollection<GeoJSON_Geometry, P> | JSON_Geometry | JSON_Feature<JSON_Geometry, P> | JSON_FeatureCollection<JSON_Geometry, P>GeoJSON Geometry, Feature or FeatureCollection
options?objectOptional GeoJSON input configuration
options.layout?'XY' | 'XYZ' | 'XYZM' | 'XYM''XYZM'Coordinate layout for interpreting GeoJSON coordinates.
Defines how to interpret the coordinates of input geometries. This does not force the dimension of the resulting geometries - the actual geometry dimension will be determined from the parsed data.
Use this to:
  • Trim unwanted Z or M ordinates from the input.
  • Treat the third ordinate as M instead of Z.

Returns

Geometry<P> | Geometry<P>[]

A new geometry object or an array of new geometry objects

Throws

See also

Examples

'layout' option