POINTARRAY **ppa;
json_object* rings = NULL;
int i = 0, j = 0;
- int ring = 0;
+ int nRings = 0;
rings = findMemberByName( geojson, "coordinates" );
- if ( ! rings ) {
+ if ( ! rings )
+ {
geojson_lwerror("Unable to find 'coordinates' in GeoJSON string", 4);
- return NULL;
- }
+ return NULL;
+ }
+
+ if ( json_type_array != json_object_get_type(rings) )
+ {
+ geojson_lwerror("The 'coordinates' in GeoJSON string are not an array", 4);
+ return NULL;
+ }
+
+ nRings = json_object_array_length( rings );
+
+ if ( ! nRings )
+ {
+ return (LWGEOM *)lwpoly_construct_empty(root_srid, 0, 0);
+ }
ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*));
- if( json_type_array == json_object_get_type( rings ) )
+ int nPoints;
+ json_object* points = NULL;
+ ppa[0] = ptarray_construct_empty(1, 0, 1);
+ points = json_object_array_get_idx( rings, 0 );
+ nPoints = json_object_array_length( points );
+
+ for (i=0; i < nPoints; i++ )
+ {
+ json_object* coords = NULL;
+ coords = json_object_array_get_idx( points, i );
+ parse_geojson_coord(coords, hasz, ppa[0]);
+ }
+
+ for(i = 1; i < nRings; ++i)
{
int nPoints;
- json_object* points = NULL;
- ppa[0] = ptarray_construct_empty(1, 0, 1);
- ring = json_object_array_length( rings );
- points = json_object_array_get_idx( rings, 0 );
+ ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa, sizeof(POINTARRAY*) * (i + 1));
+ ppa[i] = ptarray_construct_empty(1, 0, 1);
+ points = json_object_array_get_idx( rings, i );
nPoints = json_object_array_length( points );
-
- for (i=0; i < nPoints; i++ )
+ for (j=0; j < nPoints; j++ )
{
json_object* coords = NULL;
- coords = json_object_array_get_idx( points, i );
- parse_geojson_coord(coords, hasz, ppa[0]);
- }
-
- for(i = 1; i < ring; ++i)
- {
- int nPoints;
- ppa = (POINTARRAY**) lwrealloc((POINTARRAY *) ppa, sizeof(POINTARRAY*) * (i + 1));
- ppa[i] = ptarray_construct_empty(1, 0, 1);
- points = json_object_array_get_idx( rings, i );
- nPoints = json_object_array_length( points );
- for (j=0; j < nPoints; j++ )
- {
- json_object* coords = NULL;
- coords = json_object_array_get_idx( points, j );
- parse_geojson_coord(coords, hasz, ppa[i]);
- }
+ coords = json_object_array_get_idx( points, j );
+ parse_geojson_coord(coords, hasz, ppa[i]);
}
}
- geom = (LWGEOM *) lwpoly_construct(root_srid, NULL, ring, ppa);
+ geom = (LWGEOM *) lwpoly_construct(root_srid, NULL, nRings, ppa);
return geom;
}
-- #2216 --
SELECT '#2216', ST_NPoints(ST_GeomFromGeoJSON('{"type":"MultiPolygon","coordinates":[[[[4,0],[0,-4],[-4,0],[0,4],[4,0]],[[2,0],[0,2],[-2,0],[0,-2],[2,0]]],[[[24,0],[20,-4],[16,0],[20,4],[24,0]],[[22,0],[20,2],[18,0],[20,-2],[22,0]]],[[[44,0],[40,-4],[36,0],[40,4],[44,0]],[[42,0],[40,2],[38,0],[40,-2],[42,0]]]]}'));
+
+-- #2619 --
+SELECT '#2619', ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","bbox":[1,5,2,6],"coordinates":[]}'));
\ No newline at end of file