PostGIS  2.3.7dev-r@@SVN_REVISION@@
static LWGEOM* parse_geojson_polygon ( json_object *  geojson,
int *  hasz,
int  root_srid 
)
static

Definition at line 220 of file lwin_geojson.c.

References findMemberByName(), geojson_lwerror(), lwalloc(), lwpoly_construct(), lwpoly_construct_empty(), parse_geojson_coord(), and ptarray_construct_empty().

Referenced by parse_geojson().

221 {
222  POINTARRAY **ppa = NULL;
223  json_object* rings = NULL;
224  json_object* points = NULL;
225  int i = 0, j = 0;
226  int nRings = 0, nPoints = 0;
227 
228  rings = findMemberByName( geojson, "coordinates" );
229  if ( ! rings )
230  {
231  geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4);
232  return NULL;
233  }
234 
235  if ( json_type_array != json_object_get_type(rings) )
236  {
237  geojson_lwerror("The 'coordinates' in GeoJSON are not an array", 4);
238  return NULL;
239  }
240 
241  nRings = json_object_array_length( rings );
242 
243  /* No rings => POLYGON EMPTY */
244  if ( ! nRings )
245  {
246  return (LWGEOM *)lwpoly_construct_empty(root_srid, 0, 0);
247  }
248 
249  for ( i = 0; i < nRings; i++ )
250  {
251  points = json_object_array_get_idx(rings, i);
252  if ( ! points || json_object_get_type(points) != json_type_array )
253  {
254  geojson_lwerror("The 'coordinates' in GeoJSON ring are not an array", 4);
255  return NULL;
256  }
257  nPoints = json_object_array_length(points);
258 
259  /* Skip empty rings */
260  if ( nPoints == 0 ) continue;
261 
262  if ( ! ppa )
263  ppa = (POINTARRAY**)lwalloc(sizeof(POINTARRAY*) * nRings);
264 
265  ppa[i] = ptarray_construct_empty(1, 0, 1);
266  for ( j = 0; j < nPoints; j++ )
267  {
268  json_object* coords = NULL;
269  coords = json_object_array_get_idx( points, j );
270  parse_geojson_coord(coords, hasz, ppa[i]);
271  }
272  }
273 
274  /* All the rings were empty! */
275  if ( ! ppa )
276  return (LWGEOM *)lwpoly_construct_empty(root_srid, 0, 0);
277 
278  return (LWGEOM *) lwpoly_construct(root_srid, NULL, nRings, ppa);
279 }
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
static void geojson_lwerror(char *msg, int error_code)
Definition: lwin_geojson.c:49
static int parse_geojson_coord(json_object *poObj, int *hasz, POINTARRAY *pa)
Definition: lwin_geojson.c:97
LWPOLY * lwpoly_construct(int srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
static json_object * findMemberByName(json_object *poObj, const char *pszName)
Definition: lwin_geojson.c:59
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:137
void * lwalloc(size_t size)
Definition: lwutil.c:227

Here is the call graph for this function:

Here is the caller graph for this function: