Optional
emptyBy default, this is true.
WKT has a concept of an 'EMPTY' geometry: for example,
POINT EMPTY
.
GeoJSON has two similar representations:
null
as the geometry. This allows a GeoJSON Feature
to have no geometry attached to it. However, it also
does not indicate what kind of geometry would be attached
to it. It's not a null Point, it's just null.coordinates
array. This is rarer than null
geometries, and makes it possible to reflect the exact
idea from WKT. However, this is much rarer in practice -
depending on what you're doing with the GeoJSON you generate,
empty coordinates arrays might trip up another parser.By default, we encode EMPTY
as null
geometries. This
is more likely to work with GeoJSON-understanding systems.
The disadvantage of EMPTY
as null
is that it isn't symmetrical:
a WKT string like POINT EMPTY
will translate to null
,
but if you convert null
back to WKT, it won't be represented
as anything, because there's no indication of its geometry type.
Optional
projAn optional method for reprojecting EWKT strings.
The GeoJSON standard does not support alternative coordinate systems: all GeoJSON is longitude, latitude. EWKT does support alternative coordinate systems, so in order to parse it into GeoJSON we also need to reproject those coordinates.
A common way to do this would be to use proj4js. That module
exposes a method you can use as proj
:
import proj4 from "proj4";
wktToGeoJSON(`SRID=3857;POINT(-400004.3 60000.1)`, {
proj: proj4,
})
This will reproject coordinates as they're being converted to GeoJSON.
This method is optional. Without it, all WKT features will work, and EWKT features that are already in the GeoJSON required coordinate system (in this case, EPSG:4326) will also work.
However, if you convert an EWKT string with an alternative projection and you haven't specified a proj function, then the parsing will fail.
Generated using TypeDoc
User-facing options for the WKT parser.