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

◆ geom_from_geojson()

Datum geom_from_geojson ( PG_FUNCTION_ARGS  )

Definition at line 82 of file lwgeom_in_geojson.c.

83{
84#ifndef HAVE_LIBJSON
85 elog(ERROR, "You need JSON-C for ST_GeomFromGeoJSON");
86 PG_RETURN_NULL();
87#else /* HAVE_LIBJSON */
88
89 GSERIALIZED *geom;
90 LWGEOM *lwgeom;
91 text *geojson_input;
92 char *geojson;
93 char *srs = NULL;
94 int32_t srid = WGS84_SRID;
95
96 /* Get the geojson stream */
97 if (PG_ARGISNULL(0))
98 PG_RETURN_NULL();
99
100 geojson_input = PG_GETARG_TEXT_P(0);
101 geojson = text2cstring(geojson_input);
102
103 lwgeom = lwgeom_from_geojson(geojson, &srs);
104 lwfree(geojson);
105 if (!lwgeom)
106 {
107 /* Shouldn't get here */
108 elog(ERROR, "lwgeom_from_geojson returned NULL");
109 PG_RETURN_NULL();
110 }
111
112 if (srs)
113 {
114 srid = GetSRIDCacheBySRS(fcinfo, srs);
115 lwfree(srs);
116 }
117
118 lwgeom_set_srid(lwgeom, srid);
119 geom = geometry_serialize(lwgeom);
120 lwgeom_free(lwgeom);
121
122 PG_RETURN_POINTER(geom);
123#endif
124}
#define WGS84_SRID
Definition liblwgeom.h:149
void lwgeom_set_srid(LWGEOM *geom, int32_t srid)
Set the SRID on an LWGEOM For collections, only the parent gets an SRID, all the children get SRID_UN...
Definition lwgeom.c:1638
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
static char * text2cstring(const text *textptr)

References lwfree(), lwgeom_free(), lwgeom_from_geojson(), lwgeom_set_srid(), text2cstring(), and WGS84_SRID.

Here is the call graph for this function: