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

Definition at line 48 of file lwgeom_in_geojson.c.

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

49 {
50 #ifndef HAVE_LIBJSON
51  elog(ERROR, "You need JSON-C for ST_GeomFromGeoJSON");
52  PG_RETURN_NULL();
53 #else /* HAVE_LIBJSON */
54 
55  GSERIALIZED *geom;
56  LWGEOM *lwgeom;
57  text *geojson_input;
58  char *geojson;
59  char *srs = NULL;
60 
61  /* Get the geojson stream */
62  if (PG_ARGISNULL(0))
63  PG_RETURN_NULL();
64 
65  geojson_input = PG_GETARG_TEXT_P(0);
66  geojson = text2cstring(geojson_input);
67 
68  lwgeom = lwgeom_from_geojson(geojson, &srs);
69  if ( ! lwgeom )
70  {
71  /* Shouldn't get here */
72  elog(ERROR, "lwgeom_from_geojson returned NULL");
73  PG_RETURN_NULL();
74  }
75 
76  if ( srs )
77  {
78  lwgeom_set_srid(lwgeom, getSRIDbySRS(srs));
79  lwfree(srs);
80  }
81 
82  geom = geometry_serialize(lwgeom);
83  lwgeom_free(lwgeom);
84 
85  PG_RETURN_POINTER(geom);
86 #endif
87 }
void lwfree(void *mem)
Definition: lwutil.c:214
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
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:512

Here is the call graph for this function: