PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ parse_geojson_poly_rings()

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

Definition at line 174 of file lwin_geojson.c.

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

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: