toGeoJSON
Converts a geometry object to a GeoJSON Feature object or a GeoJSON
FeatureCollection object.
This function has 2 overloads, when called with:
- a single geometry object it returns a GeoJSON
Featureobject, - an array of geometry objects it returns a GeoJSON
FeatureCollectionobject.
Type Parameters
P- The type of geometry/feature properties
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
geometryies | Geometry<P> | Geometry<P>[] | The geometry object or the array of geometry objects to be converted into a GeoJSON object | |
options? | object | Optional GeoJSON output configuration | |
options.flavor? | 'strict' | 'extended' | 'strict' | Geometry types support mode.
|
options.layout? | 'XY' | 'XYZ' | 'XYZM' | 'XYM' | 'XYZ' | Coordinate layout for the output GeoJSON. Defines the coordinate structure of the output geometries. Use this to:
|
Returns
GeoJSON_Feature<GeoJSON_Geometry, P> | GeoJSON_FeatureCollection<GeoJSON_Geometry, P> | JSON_Feature<JSON_Geometry, P> | JSON_FeatureCollection<JSON_Geometry, P>
GeoJSON Feature or GeoJSON FeatureCollection object
Throws
GEOSError(strictmode only) when called with not standard GeoJSON geometry
See also
GeometryRef#toJSONconverts geometry to a GeoJSONFeatureobject
Examples
'flavor' option
'layout' option
toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XYZM' }); // will extract [ 1, 2, 3, 4 ]
toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XYZ' }); // [ 1, 2, 3 ]
toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XYM' }); // [ 1, 2, 4 ]
toGeoJSON(fromWKT('POINT ZM (1 2 3 4)'), { layout: 'XY' }); // [ 1, 2 ]
toGeoJSON(fromWKT('POINT M (1 2 4)'), { layout: 'XYZM' }); // [ 1, 2, NaN, 4 ]
toGeoJSON(fromWKT('POINT M (1 2 4)'), { layout: 'XYZ' }); // [ 1, 2 ]
toGeoJSON(fromWKT('POINT (1 2)'), { layout: 'XYZM' }); // [ 1, 2 ]
toGeoJSON(fromWKT('POINT (1 2)'), { layout: 'XYZ' }); // [ 1, 2 ]