PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ parse_geojson_multipolygon()

static LWGEOM* parse_geojson_multipolygon ( json_object *  geojson,
int *  hasz,
int  root_srid 
)
static

Definition at line 390 of file lwin_geojson.c.

References findMemberByName(), geojson_lwerror(), lwcollection_construct_empty(), lwgeom_has_m(), lwgeom_has_z(), lwmpoly_add_lwpoly(), lwpoly_add_ring(), lwpoly_construct_empty(), MULTIPOLYGONTYPE, parse_geojson_coord(), ptarray_construct_empty(), and LWGEOM::srid.

Referenced by parse_geojson().

391 {
392  LWGEOM *geom = NULL;
393  int i, j, k;
394  json_object* poObjPolys = NULL;
395 
396  if (!root_srid)
397  {
398  geom = (LWGEOM *)lwcollection_construct_empty(MULTIPOLYGONTYPE, root_srid, 1, 0);
399  }
400  else
401  {
403  }
404 
405  poObjPolys = findMemberByName( geojson, "coordinates" );
406  if ( ! poObjPolys )
407  {
408  geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4);
409  return NULL;
410  }
411 
412  if( json_type_array == json_object_get_type( poObjPolys ) )
413  {
414  const int nPolys = json_object_array_length( poObjPolys );
415 
416  for(i = 0; i < nPolys; ++i)
417  {
418  json_object* poObjPoly = json_object_array_get_idx( poObjPolys, i );
419 
420  if( json_type_array == json_object_get_type( poObjPoly ) )
421  {
422  LWPOLY *lwpoly = lwpoly_construct_empty(geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom));
423  int nRings = json_object_array_length( poObjPoly );
424 
425  for(j = 0; j < nRings; ++j)
426  {
427  json_object* points = json_object_array_get_idx( poObjPoly, j );
428 
429  if( json_type_array == json_object_get_type( points ) )
430  {
431 
432  POINTARRAY *pa = ptarray_construct_empty(1, 0, 1);
433 
434  int nPoints = json_object_array_length( points );
435  for ( k=0; k < nPoints; k++ )
436  {
437  json_object* coords = json_object_array_get_idx( points, k );
438  parse_geojson_coord(coords, hasz, pa);
439  }
440 
441  lwpoly_add_ring(lwpoly, pa);
442  }
443  }
444  geom = (LWGEOM*)lwmpoly_add_lwpoly((LWMPOLY*)geom, lwpoly);
445  }
446  }
447  }
448 
449  return geom;
450 }
static void geojson_lwerror(char *msg, __attribute__((__unused__)) int error_code)
Definition: lwin_geojson.c:55
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:70
static int parse_geojson_coord(json_object *poObj, int *hasz, POINTARRAY *pa)
Definition: lwin_geojson.c:103
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
Definition: lwgeom.c:885
int32_t srid
Definition: liblwgeom.h:399
#define MULTIPOLYGONTYPE
Definition: liblwgeom.h:90
static json_object * findMemberByName(json_object *poObj, const char *pszName)
Definition: lwin_geojson.c:65
LWPOLY * lwpoly_construct_empty(int srid, char hasz, char hasm)
Definition: lwpoly.c:161
int lwpoly_add_ring(LWPOLY *poly, POINTARRAY *pa)
Add a ring, allocating extra space if necessary.
Definition: lwpoly.c:249
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
Definition: lwcollection.c:94
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
Definition: lwgeom.c:892
LWMPOLY * lwmpoly_add_lwpoly(LWMPOLY *mobj, const LWPOLY *obj)
Definition: lwmpoly.c:47
Here is the call graph for this function:
Here is the caller graph for this function: