PostGIS  2.1.10dev-r@@SVN_REVISION@@
Datum geom_from_geojson ( PG_FUNCTION_ARGS  )

Definition at line 36 of file lwgeom_in_geojson.c.

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

37 {
38 #ifndef HAVE_LIBJSON
39  elog(ERROR, "You need JSON-C for ST_GeomFromGeoJSON");
40  PG_RETURN_NULL();
41 #else /* HAVE_LIBJSON */
42 
44  LWGEOM *lwgeom;
45  text *geojson_input;
46  char *geojson;
47  char *srs = NULL;
48 
49  /* Get the geojson stream */
50  if (PG_ARGISNULL(0)) PG_RETURN_NULL();
51  geojson_input = PG_GETARG_TEXT_P(0);
52  geojson = text2cstring(geojson_input);
53 
54  lwgeom = lwgeom_from_geojson(geojson, &srs);
55  if ( ! lwgeom ) {
56  /* Shouldn't get here */
57  elog(ERROR, "lwgeom_from_geojson returned NULL");
58  PG_RETURN_NULL();
59  }
60 
61  if ( srs ) {
62  lwgeom_set_srid(lwgeom, getSRIDbySRS(srs));
63  lwfree(srs);
64  }
65 
66  geom = geometry_serialize(lwgeom);
67  lwgeom_free(lwgeom);
68 
69  PG_RETURN_POINTER(geom);
70 #endif
71 }
void lwfree(void *mem)
Definition: lwutil.c:190
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * geom
char * text2cstring(const text *textptr)
int getSRIDbySRS(const char *srs)
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
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...
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:510

Here is the call graph for this function: