]> granicus.if.org Git - postgis/commitdiff
#3094, found another one
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 15 Apr 2015 15:20:30 +0000 (15:20 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 15 Apr 2015 15:20:30 +0000 (15:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13428 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwin_geojson.c

index 24321b5afa9b2096ddcfca06afd2ed0301365488..021a9d7e8028cc61c0321821f88ac40b61bab795 100644 (file)
@@ -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);
                        }
                }
        }