PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ geom_from_geojson()

Datum geom_from_geojson ( PG_FUNCTION_ARGS  )

Definition at line 63 of file lwgeom_in_geojson.c.

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

Referenced by postgis_libjson_version().

64 {
65 #ifndef HAVE_LIBJSON
66  elog(ERROR, "You need JSON-C for ST_GeomFromGeoJSON");
67  PG_RETURN_NULL();
68 #else /* HAVE_LIBJSON */
69 
70  GSERIALIZED *geom;
71  LWGEOM *lwgeom;
72  text *geojson_input;
73  char *geojson;
74  char *srs = NULL;
75 
76  /* Get the geojson stream */
77  if (PG_ARGISNULL(0))
78  PG_RETURN_NULL();
79 
80  geojson_input = PG_GETARG_TEXT_P(0);
81  geojson = text2cstring(geojson_input);
82 
83  lwgeom = lwgeom_from_geojson(geojson, &srs);
84  if ( ! lwgeom )
85  {
86  /* Shouldn't get here */
87  elog(ERROR, "lwgeom_from_geojson returned NULL");
88  PG_RETURN_NULL();
89  }
90 
91  if ( srs )
92  {
93  lwgeom_set_srid(lwgeom, getSRIDbySRS(srs));
94  lwfree(srs);
95  }
96 
97  geom = geometry_serialize(lwgeom);
98  lwgeom_free(lwgeom);
99 
100  PG_RETURN_POINTER(geom);
101 #endif
102 }
void lwfree(void *mem)
Definition: lwutil.c:244
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
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:539
Here is the call graph for this function:
Here is the caller graph for this function: