Skip to content
On this page

geojsonToGeosGeom(geojson, geos) ⇒ number

Convert GeoJSON object to GEOS geometry pointer.

Kind: global function
Returns: number - A pointer to GEOS geometry.

ParamTypeDescription
geojsonGeoJSONThe GeoJSON object.
geosgeosThe GEOS module object.

Example

js
import initGeosJs from 'geos-wasm'
import { geojsonToGeosGeom } from 'geos-wasm/helpers'
const geos = await initGeosJs()
const json = JSON.parse('{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]}')
const geomPtr = geojsonToGeosGeom(json, geos)
const writer = geos.GEOSWKTWriter_create()
const wktPtr = geos.GEOSWKTWriter_write(writer, geomPtr)
const wkt = geos.Module.UTF8ToString(wktPtr)
geos.GEOSFree(wktPtr)
console.log(wkt)
// => POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))