From c20bc78be5a6491458c65e60641916ce86b992cc Mon Sep 17 00:00:00 2001 From: Olivier Courtin Date: Thu, 22 Oct 2009 14:08:09 +0000 Subject: [PATCH] Use ptarray_isclosed3d to check if 3D rings are closed also on Z. Update units tests cases git-svn-id: http://svn.osgeo.org/postgis/trunk@4671 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/lwgeom_in_gml.c | 20 ++++++----- regress/in_gml.sql | 74 ++++++++++++++++++++++------------------- regress/in_gml_expected | 28 +++++++++------- 3 files changed, 67 insertions(+), 55 deletions(-) diff --git a/postgis/lwgeom_in_gml.c b/postgis/lwgeom_in_gml.c index 6f9e8ca00..b7201d055 100644 --- a/postgis/lwgeom_in_gml.c +++ b/postgis/lwgeom_in_gml.c @@ -744,8 +744,9 @@ static LWGEOM* parse_gml_polygon(xmlNodePtr xnode, bool *hasz) ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*)); ppa[0] = parse_gml_data(xb->children, hasz); - /* FIXME: And what about the 3D ? */ - if (ppa[0]->npoints < 4 || !ptarray_isclosed2d(ppa[0])) + if (ppa[0]->npoints < 4 + || (!*hasz && !ptarray_isclosed2d(ppa[0])) + || (*hasz && !ptarray_isclosed3d(ppa[0]))) lwerror("invalid GML representation"); } } @@ -767,8 +768,9 @@ static LWGEOM* parse_gml_polygon(xmlNodePtr xnode, bool *hasz) sizeof(POINTARRAY*) * (ring + 1)); ppa[ring] = parse_gml_data(xb->children, hasz); - /* FIXME: And what about the 3D ? */ - if (ppa[ring]->npoints < 4 || !ptarray_isclosed2d(ppa[ring])) + if (ppa[ring]->npoints < 4 + || (!*hasz && !ptarray_isclosed2d(ppa[ring])) + || (*hasz && !ptarray_isclosed3d(ppa[ring]))) lwerror("invalid GML representation"); ring++; } @@ -836,8 +838,9 @@ static LWGEOM* parse_gml_surface(xmlNodePtr xnode, bool *hasz) ppa = (POINTARRAY**) lwalloc(sizeof(POINTARRAY*)); ppa[0] = parse_gml_data(xc->children, hasz); - /* FIXME: And what about the 3D ? */ - if (ppa[0]->npoints < 4 || !ptarray_isclosed2d(ppa[0])) + if (ppa[0]->npoints < 4 + || (!*hasz && !ptarray_isclosed2d(ppa[0])) + || (*hasz && !ptarray_isclosed3d(ppa[0]))) lwerror("invalid GML representation"); } } @@ -859,8 +862,9 @@ static LWGEOM* parse_gml_surface(xmlNodePtr xnode, bool *hasz) sizeof(POINTARRAY*) * (ring + 1)); ppa[ring] = parse_gml_data(xc->children, hasz); - /* FIXME: And what about the 3D ? */ - if (ppa[ring]->npoints < 4 || !ptarray_isclosed2d(ppa[ring])) + if (ppa[ring]->npoints < 4 + || (!*hasz && !ptarray_isclosed2d(ppa[ring])) + || ( *hasz && !ptarray_isclosed3d(ppa[ring]))) lwerror("invalid GML representation"); } ring++; diff --git a/regress/in_gml.sql b/regress/in_gml.sql index 40fece605..d1e062716 100644 --- a/regress/in_gml.sql +++ b/regress/in_gml.sql @@ -127,43 +127,45 @@ SELECT 'polygon_2', ST_AsEWKT(ST_GeomFromGML('< -- ERROR: In exterior ring: Last point is not the same as the first one SELECT 'polygon_3', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,3')); --- TODO ERROR: In exterior 3D ring: Last point is not the same as the first one in Z +-- ERROR: In exterior 3D ring: Last point is not the same as the first one in Z +SELECT 'polygon_4', ST_AsEWKT(ST_GeomFromGML('1,2,3 4,5,6 7,8,9 1,2,0')); -- ERROR: Only 3 points in exterior ring -SELECT 'polygon_4', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 1,2')); +SELECT 'polygon_5', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 1,2')); -- ERROR: Empty exterior ring coordinates -SELECT 'polygon_5', ST_AsEWKT(ST_GeomFromGML('')); -SELECT 'polygon_6', ST_AsEWKT(ST_GeomFromGML('')); -SELECT 'polygon_7', ST_AsEWKT(ST_GeomFromGML('')); -SELECT 'polygon_8', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'polygon_6', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'polygon_7', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'polygon_8', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'polygon_9', ST_AsEWKT(ST_GeomFromGML('')); -- GML 2 - 2 rings -SELECT 'polygon_9', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); +SELECT 'polygon_10', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); -- XML not elements handle -SELECT 'polygon_10', ST_AsEWKT(ST_GeomFromGML(' 1,2 3,4 5,6 1,2 7,8 9,10 11,12 7,8')); +SELECT 'polygon_11', ST_AsEWKT(ST_GeomFromGML(' 1,2 3,4 5,6 1,2 7,8 9,10 11,12 7,8')); -- Empty interior ring coordinates (even if defined) -SELECT 'polygon_11', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); +SELECT 'polygon_12', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); -- ERROR: Only 3 points in interior ring -SELECT 'polygon_12', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 7,8')); +SELECT 'polygon_13', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 7,8')); -- ERROR: In interior ring: Last point is not the same as the first one -SELECT 'polygon_13', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,9')); +SELECT 'polygon_14', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,9')); --- TODO ERROR: In interior 3D ring: Last point is not the same as the first one in Z +-- ERROR: In interior 3D ring: Last point is not the same as the first one in Z +SELECT 'polygon_15', ST_AsEWKT(ST_GeomFromGML('1,2,3 4,5,6 7,8,9 1,2,310,11,12 13,14,15 16,17,18 10,11,0')); -- GML 2 - 3 rings -SELECT 'polygon_14', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,813,14 15,16 17,18 13,14')); +SELECT 'polygon_16', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,813,14 15,16 17,18 13,14')); -- GML 3 -SELECT 'polygon_15', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); +SELECT 'polygon_17', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); -- Mixed dimension in rings -SELECT 'polygon_16', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 7 8 9 1 2 310 11 12 13 14 15 10 11')); -SELECT 'polygon_17', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 1 27 8 9 10 11 12 13 14 15 7 8 9')); +SELECT 'polygon_18', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 7 8 9 1 2 310 11 12 13 14 15 10 11')); +SELECT 'polygon_19', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 1 27 8 9 10 11 12 13 14 15 7 8 9')); @@ -181,50 +183,52 @@ SELECT 'surface_2', ST_AsEWKT(ST_GeomFromGML('< -- ERROR: In exterior ring: Last point is not the same as the first one SELECT 'surface_3', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,0')); --- TODO -- ERROR: In exterior 3D ring: Last point is not the same as the first one in Z +-- ERROR: In exterior 3D ring: Last point is not the same as the first one in Z +SELECT 'surface_4', ST_AsEWKT(ST_GeomFromGML('1,2,3 4,5,6 7,8,9 1,2,0')); -- ERROR: Only 3 points in exterior ring -SELECT 'surface_4', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 1,2')); +SELECT 'surface_5', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 1,2')); -- ERROR: Empty exterior ring coordinates -SELECT 'surface_5', ST_AsEWKT(ST_GeomFromGML('')); -SELECT 'surface_6', ST_AsEWKT(ST_GeomFromGML('')); -SELECT 'surface_7', ST_AsEWKT(ST_GeomFromGML('')); -SELECT 'surface_8', ST_AsEWKT(ST_GeomFromGML('')); -SELECT 'surface_9', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'surface_6', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'surface_7', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'surface_8', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'surface_9', ST_AsEWKT(ST_GeomFromGML('')); +SELECT 'surface_10', ST_AsEWKT(ST_GeomFromGML('')); -- 2 rings -SELECT 'surface_10', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); +SELECT 'surface_11', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); -- XML not elements handle -SELECT 'surface_11', ST_AsEWKT(ST_GeomFromGML(' 1,2 3,4 5,6 1,2 7,8 9,10 11,12 7,8')); +SELECT 'surface_12', ST_AsEWKT(ST_GeomFromGML(' 1,2 3,4 5,6 1,2 7,8 9,10 11,12 7,8')); -- Empty interior ring coordinates (even if defined) -SELECT 'surface_12', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); +SELECT 'surface_13', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); -- ERROR: Only 3 points in interior ring -SELECT 'surface_13', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 7,8')); +SELECT 'surface_14', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 7,8')); -- ERROR: In interior ring: Last point is not the same as the first one -SELECT 'surface_14', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,0')); +SELECT 'surface_15', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,0')); --- TODO -- ERROR: In interior 3D ring: Last point is not the same as the first one in Z +-- ERROR: In interior 3D ring: Last point is not the same as the first one in Z +SELECT 'surface_16', ST_AsEWKT(ST_GeomFromGML('1,2,3 4,5,6 7,8,9 1,2,310,11,12 13,14,15 16,17,18 10,11,0')); -- 3 rings -SELECT 'surface_15', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,813,14 15,16 17,18 13,14')); +SELECT 'surface_17', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,813,14 15,16 17,18 13,14')); -- Mixed dimension in rings -SELECT 'surface_16', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 7 8 9 1 2 310 11 12 13 14 15 10 11')); -SELECT 'surface_17', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 1 27 8 9 10 11 12 13 14 15 7 8 9')); +SELECT 'surface_18', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 7 8 9 1 2 310 11 12 13 14 15 10 11')); +SELECT 'surface_19', ST_AsEWKT(ST_GeomFromGML('1 2 3 4 5 6 1 27 8 9 10 11 12 13 14 15 7 8 9')); -- ERROR: two patches -SELECT 'surface_18', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); +SELECT 'surface_20', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,27,8 9,10 11,12 7,8')); -- planar interpolation -SELECT 'surface_19', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); +SELECT 'surface_21', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); -- ERROR: interpolation not planar -SELECT 'surface_20', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); +SELECT 'surface_22', ST_AsEWKT(ST_GeomFromGML('1,2 3,4 5,6 1,2')); diff --git a/regress/in_gml_expected b/regress/in_gml_expected index f3b0f0fc9..843d43dd5 100644 --- a/regress/in_gml_expected +++ b/regress/in_gml_expected @@ -36,15 +36,17 @@ ERROR: invalid GML representation ERROR: invalid GML representation ERROR: invalid GML representation ERROR: invalid GML representation -polygon_9|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) +ERROR: invalid GML representation polygon_10|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) -polygon_11|POLYGON((1 2,3 4,5 6,1 2)) +polygon_11|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) +polygon_12|POLYGON((1 2,3 4,5 6,1 2)) +ERROR: invalid GML representation ERROR: invalid GML representation ERROR: invalid GML representation -polygon_14|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8),(13 14,15 16,17 18,13 14)) -polygon_15|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) -polygon_16|POLYGON((1 2,4 5,7 8,1 2),(10 11,12 13,14 15,10 11)) -polygon_17|POLYGON((1 2,3 4,5 6,1 2),(7 8,10 11,13 14,7 8)) +polygon_16|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8),(13 14,15 16,17 18,13 14)) +polygon_17|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) +polygon_18|POLYGON((1 2,4 5,7 8,1 2),(10 11,12 13,14 15,10 11)) +polygon_19|POLYGON((1 2,3 4,5 6,1 2),(7 8,10 11,13 14,7 8)) surface_1|POLYGON((1 2,3 4,5 6,1 2)) surface_2|SRID=4326;POLYGON((1 2,3 4,5 6,1 2)) ERROR: invalid GML representation @@ -54,16 +56,18 @@ ERROR: invalid GML representation ERROR: invalid GML representation ERROR: invalid GML representation ERROR: invalid GML representation -surface_10|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) +ERROR: invalid GML representation surface_11|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) -surface_12|POLYGON((1 2,3 4,5 6,1 2)) +surface_12|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8)) +surface_13|POLYGON((1 2,3 4,5 6,1 2)) +ERROR: invalid GML representation ERROR: invalid GML representation ERROR: invalid GML representation -surface_15|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8),(13 14,15 16,17 18,13 14)) -surface_16|POLYGON((1 2,4 5,7 8,1 2),(10 11,12 13,14 15,10 11)) -surface_17|POLYGON((1 2,3 4,5 6,1 2),(7 8,10 11,13 14,7 8)) +surface_17|POLYGON((1 2,3 4,5 6,1 2),(7 8,9 10,11 12,7 8),(13 14,15 16,17 18,13 14)) +surface_18|POLYGON((1 2,4 5,7 8,1 2),(10 11,12 13,14 15,10 11)) +surface_19|POLYGON((1 2,3 4,5 6,1 2),(7 8,10 11,13 14,7 8)) ERROR: invalid GML representation -surface_19|POLYGON((1 2,3 4,5 6,1 2)) +surface_21|POLYGON((1 2,3 4,5 6,1 2)) ERROR: invalid GML representation mpoint_1|MULTIPOINT(1 2) mpoint_2|MULTIPOINT(1 2,3 4) -- 2.50.1