375{
378 char *geojson;
379 text *result;
384 int output_guess_short_srid =
LW_FALSE;
385 char *srs = NULL;
386 int32_t srid;
387
388
389 if (PG_ARGISNULL(0))
390 PG_RETURN_NULL();
391
392 geom = PG_GETARG_GSERIALIZED_P(0);
394
395
396 if ( PG_NARGS() > 1 && !PG_ARGISNULL(1) )
397 {
403 }
404
405
406
407
408
409
410
411
412 if (PG_NARGS() > 2 && !PG_ARGISNULL(2))
413 {
414 int option = PG_GETARG_INT32(2);
419 }
420 else
421 output_guess_short_srid =
LW_TRUE;
422
425
426 if (srid !=
SRID_UNKNOWN && (output_short_crs || output_long_crs))
427 {
429
430 if (!srs)
431 {
432 elog(ERROR, "SRID %i unknown in spatial_ref_sys table", srid);
433 PG_RETURN_NULL();
434 }
435 }
436
440
441 if (srs) pfree(srs);
442
443 result = cstring_to_text(geojson);
445
446 PG_FREE_IF_COPY(geom, 0);
447 PG_RETURN_TEXT_P(result);
448}
int32_t gserialized_get_srid(const GSERIALIZED *g)
Extract the SRID from the serialized form (it is packed into three bytes so this is a handy function)...
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void lwgeom_free(LWGEOM *geom)
#define LW_TRUE
Return types for functions with status returns.
#define SRID_UNKNOWN
Unknown SRID value.
char * lwgeom_to_geojson(const LWGEOM *geo, char *srs, int precision, int has_bbox)
Takes a GEOMETRY and returns a GeoJson representation.
char * getSRSbySRID(FunctionCallInfo fcinfo, int32_t srid, bool short_crs)