PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ geom_from_geojson()

Datum geom_from_geojson ( PG_FUNCTION_ARGS  )

Definition at line 85 of file lwgeom_in_geojson.c.

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

References geometry_serialize(), getSRIDbySRS(), lwfree(), lwgeom_free(), lwgeom_from_geojson(), lwgeom_set_srid(), and text2cstring().

Here is the call graph for this function: