The Three.js BufferGeometry to convert
Conversion options including the geographic origin
WKT string in POLYHEDRALSURFACE Z format
The output format is:
POLYHEDRALSURFACE Z (
((lng1 lat1 alt1, lng2 lat2 alt2, lng3 lat3 alt3, lng1 lat1 alt1)),
...
)
Note: PostGIS uses (longitude, latitude, altitude) order (X, Y, Z).
import { bufferGeometryToWKT } from '@wendylabsinc/react-three-map/maplibre';
import { BoxGeometry } from 'three';
const geometry = new BoxGeometry(100, 100, 100);
const origin = { latitude: 51.5074, longitude: -0.1278, altitude: 0 };
const wkt = bufferGeometryToWKT(geometry, { origin });
// Store in PostGIS: INSERT INTO geofences (geom) VALUES (ST_GeomFromText(wkt, 4326))
wktToBufferGeometry for the inverse operation
Converts a BufferGeometry to PostGIS POLYHEDRALSURFACE Z WKT format.
This function extracts all triangular faces from the geometry and converts them to geographic coordinates suitable for storage in PostGIS with
geometry(POLYHEDRALSURFACEZ, 4326)column type.