PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ lwgeom_to_geojson()

lwvarlena_t * lwgeom_to_geojson ( const LWGEOM geo,
const char *  srs,
int  precision,
int  has_bbox 
)
extern

Takes a GEOMETRY and returns a GeoJson representation.

Definition at line 378 of file lwout_geojson.c.

379{
380 GBOX static_bbox = {0};
383
384 memset(&opts, 0, sizeof(opts));
385 opts.precision = precision;
386 opts.hasz = FLAGS_GET_Z(geom->flags);
387 opts.srs = srs;
388
389 if (has_bbox)
390 {
391 /* Whether these are geography or geometry,
392 the GeoJSON expects a cartesian bounding box */
393 lwgeom_calculate_gbox_cartesian(geom, &static_bbox);
394 opts.bbox = &static_bbox;
395 }
396
397 /* To avoid taking a copy of the output, we make */
398 /* space for the VARLENA header before starting to */
399 /* serialize the geom */
401 /* Now serialize the geometry */
402 asgeojson_geometry(&sb, geom, &opts);
403 /* Leave the initially allocated buffer in place */
404 /* and write the varlena_t metadata into the slot we */
405 /* left at the start */
406 return stringbuffer_getvarlena(&sb);
407}
static uint8_t precision
Definition cu_in_twkb.c:25
int lwgeom_calculate_gbox_cartesian(const LWGEOM *lwgeom, GBOX *gbox)
Calculate the 2-4D bounding box of a geometry.
Definition gbox.c:752
#define FLAGS_GET_Z(flags)
Definition liblwgeom.h:165
static void asgeojson_geometry(stringbuffer_t *sb, const LWGEOM *geom, const geojson_opts *opts)
lwvarlena_t * stringbuffer_getvarlena(stringbuffer_t *s)
void stringbuffer_init_varlena(stringbuffer_t *s)

References asgeojson_geometry(), LWGEOM::flags, FLAGS_GET_Z, lwgeom_calculate_gbox_cartesian(), precision, stringbuffer_getvarlena(), and stringbuffer_init_varlena().

Referenced by do_geojson_test(), do_geojson_unsupported(), geography_as_geojson(), geometry_to_json(), geometry_to_jsonb(), and LWGEOM_asGeoJson().

Here is the call graph for this function:
Here is the caller graph for this function: