PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ 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  if (!lwgeom)
105  {
106  /* Shouldn't get here */
107  elog(ERROR, "lwgeom_from_geojson returned NULL");
108  PG_RETURN_NULL();
109  }
110 
111  if (srs)
112  {
113  srid = getSRIDbySRS(fcinfo, srs);
114  lwfree(srs);
115  }
116 
117  lwgeom_set_srid(lwgeom, srid);
118  geom = geometry_serialize(lwgeom);
119  lwgeom_free(lwgeom);
120 
121  PG_RETURN_POINTER(geom);
122 #endif
123 }
#define WGS84_SRID
Definition: liblwgeom.h:163
LWGEOM * lwgeom_from_geojson(const char *geojson, char **srs)
Create an LWGEOM object from a GeoJSON representation.
Definition: lwin_geojson.c:409
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:1530
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1138
void lwfree(void *mem)
Definition: lwutil.c:242
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(), text2cstring(), and WGS84_SRID.

Here is the call graph for this function: