PostGIS  3.4.0dev-r@@SVN_REVISION@@
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages

◆ parse_geojson_poly_rings()

static LWPOLY* parse_geojson_poly_rings ( json_object *  rings,
int *  hasz 
)
inlinestatic

Definition at line 176 of file lwin_geojson.c.

177 {
178  if (!rings || json_object_get_type(rings) != json_type_array)
179  return NULL;
180 
181  int nRings = json_object_array_length(rings);
182 
183  /* No rings => POLYGON EMPTY */
184  if (!nRings)
185  return lwpoly_construct_empty(0, 1, 0);
186 
187  /* Expecting up to nRings otherwise */
188  POINTARRAY **ppa = (POINTARRAY **)lwalloc(sizeof(POINTARRAY *) * nRings);
189  int o = 0;
190 
191  for (int i = 0; i < nRings; i++)
192  {
193  json_object *points = json_object_array_get_idx(rings, i);
194  if (!points || json_object_get_type(points) != json_type_array)
195  {
196  for (int k = 0; k < o; k++)
197  ptarray_free(ppa[k]);
198  lwfree(ppa);
199  lwerror("The 'coordinates' in GeoJSON ring are not an array");
200  return NULL;
201  }
202  int nPoints = json_object_array_length(points);
203 
204  /* Skip empty rings */
205  if (!nPoints)
206  {
207  /* Empty outer? Don't promote first hole to outer, holes don't matter. */
208  if (!i)
209  break;
210  else
211  continue;
212  }
213 
214  ppa[o] = ptarray_construct_empty(1, 0, 1);
215  for (int j = 0; j < nPoints; j++)
216  {
217  json_object *coords = NULL;
218  coords = json_object_array_get_idx(points, j);
219  if (LW_FAILURE == parse_geojson_coord(coords, hasz, ppa[o]))
220  {
221  for (int k = 0; k <= o; k++)
222  ptarray_free(ppa[k]);
223  lwfree(ppa);
224  lwerror("The 'coordinates' in GeoJSON are not sufficiently nested");
225  return NULL;
226  }
227  }
228  o++;
229  }
230 
231  /* All the rings were empty! */
232  if (!o)
233  {
234  lwfree(ppa);
235  return lwpoly_construct_empty(0, 1, 0);
236  }
237 
238  return lwpoly_construct(0, NULL, o, ppa);
239 }
#define LW_FAILURE
Definition: liblwgeom.h:96
void lwfree(void *mem)
Definition: lwutil.c:242
POINTARRAY * ptarray_construct_empty(char hasz, char hasm, uint32_t maxpoints)
Create a new POINTARRAY with no points.
Definition: ptarray.c:59
void ptarray_free(POINTARRAY *pa)
Definition: ptarray.c:319
void * lwalloc(size_t size)
Definition: lwutil.c:227
LWPOLY * lwpoly_construct_empty(int32_t srid, char hasz, char hasm)
Definition: lwpoly.c:161
LWPOLY * lwpoly_construct(int32_t srid, GBOX *bbox, uint32_t nrings, POINTARRAY **points)
Definition: lwpoly.c:43
void lwerror(const char *fmt,...)
Write a notice out to the error handler.
Definition: lwutil.c:190
static int parse_geojson_coord(json_object *poObj, int *hasz, POINTARRAY *pa)
Definition: lwin_geojson.c:106

References LW_FAILURE, lwalloc(), lwerror(), lwfree(), lwpoly_construct(), lwpoly_construct_empty(), parse_geojson_coord(), ptarray_construct_empty(), and ptarray_free().

Referenced by parse_geojson_multipolygon(), and parse_geojson_polygon().

Here is the call graph for this function:
Here is the caller graph for this function: