From: Paul Ramsey Date: Wed, 15 Apr 2015 15:20:30 +0000 (+0000) Subject: #3094, found another one X-Git-Tag: 2.2.0rc1~558 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=154d5c7c3f799753b4d360483e341885782082b7;p=postgis #3094, found another one git-svn-id: http://svn.osgeo.org/postgis/trunk@13428 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwin_geojson.c b/liblwgeom/lwin_geojson.c index 24321b5af..021a9d7e8 100644 --- a/liblwgeom/lwin_geojson.c +++ b/liblwgeom/lwin_geojson.c @@ -373,58 +373,45 @@ parse_geojson_multipolygon(json_object *geojson, int *hasz, int root_srid) } poObjPolys = findMemberByName( geojson, "coordinates" ); - if ( ! poObjPolys ) { + if ( ! poObjPolys ) + { geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4); - return NULL; - } + return NULL; + } if( json_type_array == json_object_get_type( poObjPolys ) ) { const int nPolys = json_object_array_length( poObjPolys ); for(i = 0; i < nPolys; ++i) - { - POINTARRAY **ppa; - json_object* poObjPoly = NULL; - poObjPoly = json_object_array_get_idx( poObjPolys, i ); - - ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*)); + { + json_object* poObjPoly = json_object_array_get_idx( poObjPolys, i ); if( json_type_array == json_object_get_type( poObjPoly ) ) { - int nPoints; - json_object* points = NULL; - int ring = json_object_array_length( poObjPoly ); - ppa[0] = ptarray_construct_empty(1, 0, 1); - - points = json_object_array_get_idx( poObjPoly, 0 ); - nPoints = json_object_array_length( points ); - - for (j=0; j < nPoints; j++ ) + LWPOLY *lwpoly = lwpoly_construct_empty(geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom)); + int nRings = json_object_array_length( poObjPoly ); + + for(j = 0; j < nRings; ++j) { - json_object* coords = NULL; - coords = json_object_array_get_idx( points, j ); - parse_geojson_coord(coords, hasz, ppa[0]); - } + json_object* points = json_object_array_get_idx( poObjPoly, j ); + + if( json_type_array == json_object_get_type( poObjPoly ) ) + { - for(j = 1; j < ring; ++j) - { - int nPoints; - ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa, sizeof(POINTARRAY*) * (j + 1)); - ppa[j] = ptarray_construct_empty(1, 0, 1); - points = json_object_array_get_idx( poObjPoly, j ); + POINTARRAY *pa = ptarray_construct_empty(1, 0, 1); - nPoints = json_object_array_length( points ); - for (k=0; k < nPoints; k++ ) - { - json_object* coords = NULL; - coords = json_object_array_get_idx( points, k ); - parse_geojson_coord(coords, hasz, ppa[j]); + int nPoints = json_object_array_length( points ); + for ( k=0; k < nPoints; k++ ) + { + json_object* coords = json_object_array_get_idx( points, k ); + parse_geojson_coord(coords, hasz, pa); + } + + lwpoly_add_ring(lwpoly, pa); } } - - geom = (LWGEOM*)lwmpoly_add_lwpoly((LWMPOLY*)geom, - (LWPOLY*)lwpoly_construct(root_srid, NULL, ring, ppa)); + geom = (LWGEOM*)lwmpoly_add_lwpoly((LWMPOLY*)geom, lwpoly); } } }