From e58addea022b9e076deedf695e27b477894bdf2c Mon Sep 17 00:00:00 2001 From: mbarto Date: Thu, 20 Oct 2016 17:48:25 +0200 Subject: [PATCH] Fixes #1182: implemented GML2 support for WFS 1.x (#1183) --- web/client/utils/FilterUtils.jsx | 49 ++++++-------- .../utils/__tests__/FilterUtils-test.js | 66 ++++++++++++++++++- 2 files changed, 86 insertions(+), 29 deletions(-) diff --git a/web/client/utils/FilterUtils.jsx b/web/client/utils/FilterUtils.jsx index b88af69622..a68c4cf2a6 100644 --- a/web/client/utils/FilterUtils.jsx +++ b/web/client/utils/FilterUtils.jsx @@ -70,7 +70,7 @@ const FilterUtils = { } let spatialFilter; - if (this.objFilter.spatialField && this.objFilter.spatialField.geometry && this.objFilter.spatialField.method) { + if (this.objFilter.spatialField && this.objFilter.spatialField.geometry && this.objFilter.spatialField.operation) { spatialFilter = this.processOGCSpatialFilter(versionOGC); filters.push(spatialFilter); } @@ -390,7 +390,7 @@ const FilterUtils = { switch (this.objFilter.spatialField.geometry.type) { case "Point": ogc += this.getGmlPointElement(this.objFilter.spatialField.geometry.coordinates, - this.objFilter.spatialField.geometry.projection || "EPSG:4326"); + this.objFilter.spatialField.geometry.projection || "EPSG:4326", version); break; case "MultiPoint": ogc += ''; @@ -402,7 +402,7 @@ const FilterUtils = { let point = element; if (point) { ogc += ""; - ogc += this.getGmlPointElement(point); + ogc += this.getGmlPointElement(point, version); ogc += ""; } }); @@ -411,7 +411,7 @@ const FilterUtils = { break; case "Polygon": ogc += this.getGmlPolygonElement(this.objFilter.spatialField.geometry.coordinates, - this.objFilter.spatialField.geometry.projection || "EPSG:4326"); + this.objFilter.spatialField.geometry.projection || "EPSG:4326", version); break; case "MultiPolygon": const multyPolygonTagName = version === "2.0" ? "MultiSurface" : "MultiPolygon"; @@ -426,7 +426,7 @@ const FilterUtils = { let polygon = element; if (polygon) { ogc += ""; - ogc += this.getGmlPolygonElement(polygon); + ogc += this.getGmlPolygonElement(polygon, version); ogc += ""; } }); @@ -462,7 +462,7 @@ const FilterUtils = { ogc += this.ogcSpatialOperator[this.objFilter.spatialField.operation].endTag; return ogc; }, - getGmlPointElement: function(coordinates, srsName) { + getGmlPointElement: function(coordinates, srsName, version) { let gmlPoint = '' : '>'; @@ -475,14 +475,17 @@ const FilterUtils = { let coords = element.map((coordinate) => { return coordinate[0] + " " + coordinate[1]; }); - - gmlPoint += '' + coords.join(" ") + ''; + if (version === "2.0") { + gmlPoint += '' + coords.join(" ") + ''; + } else { + gmlPoint += '' + element[0][0] + '' + element[0][1] + ''; + } }); gmlPoint += ''; return gmlPoint; }, - getGmlPolygonElement: function(coordinates, srsName) { + getGmlPolygonElement: function(coordinates, srsName, version) { let gmlPolygon = '' : '>'; @@ -493,28 +496,18 @@ const FilterUtils = { // /////////////////////////////////////////////////////////////////////////////////////////////////////// coordinates.forEach((element, index) => { let coords = element.map((coordinate) => { - return coordinate[0] + " " + coordinate[1]; + return coordinate[0] + (version === "2.0" ? " " : ",") + coordinate[1]; }); - - if (index < 1) { - gmlPolygon += - '' + + const exterior = (version === "2.0" ? "exterior" : "outerBoundaryIs"); + const interior = (version === "2.0" ? "exterior" : "innerBoundaryIs"); + gmlPolygon += + (index < 1 ? '' : '') + '' + - '' + + (version === "2.0" ? '' : '') + coords.join(" ") + - '' + + (version === "2.0" ? '' : '') + '' + - ''; - } else { - gmlPolygon += - '' + - '' + - '' + - coords.join(" ") + - '' + - '' + - ''; - } + (index < 1 ? '' : ''); }); gmlPolygon += ''; @@ -547,7 +540,7 @@ const FilterUtils = { } let spatialFilter; - if (this.objFilter.spatialField && this.objFilter.spatialField.geometry && this.objFilter.spatialField.method) { + if (this.objFilter.spatialField && this.objFilter.spatialField.geometry && this.objFilter.spatialField.operation) { spatialFilter = this.processCQLSpatialFilter(); filters.push(spatialFilter); } diff --git a/web/client/utils/__tests__/FilterUtils-test.js b/web/client/utils/__tests__/FilterUtils-test.js index 98b31cea4f..66050cb939 100644 --- a/web/client/utils/__tests__/FilterUtils-test.js +++ b/web/client/utils/__tests__/FilterUtils-test.js @@ -308,7 +308,71 @@ describe('FilterUtils', () => { let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj); expect(filter).toEqual(expected); }); - it('Check SimpleFilterField cql', () => { + it('Check SpatialFilterField ogc 1.0 Polygon', () => { + let filterObj = { + spatialField: { + "operation": "INTERSECTS", + "attribute": "geometry", + "geometry": { + "type": "Polygon", + "projection": "EPSG:4326", + "coordinates": [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]] + } + } + }; + let expected = 'geometry1,1 1,2 2,2 2,1 1,1'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.0"); + expect(filter).toEqual(expected); + }); + it('Check SpatialFilterField ogc 1.0 Point', () => { + let filterObj = { + spatialField: { + "operation": "INTERSECTS", + "attribute": "geometry", + "geometry": { + "type": "Point", + "projection": "EPSG:4326", + "coordinates": [[[1, 1]]] + } + } + }; + let expected = 'geometry11'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.0"); + expect(filter).toEqual(expected); + }); + it('Check SpatialFilterField ogc 2.0 Point', () => { + let filterObj = { + spatialField: { + "operation": "INTERSECTS", + "attribute": "geometry", + "geometry": { + "type": "Point", + "projection": "EPSG:4326", + "coordinates": [[[1, 1]]] + } + } + }; + let expected = 'geometry1 1'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj); + expect(filter).toEqual(expected); + }); + it('Check SpatialFilterField ogc 2.0 Polygon', () => { + let filterObj = { + spatialField: { + "attribute": "geometry", + "operation": "INTERSECTS", + "geometry": { + "type": "Polygon", + "projection": "EPSG:4326", + "coordinates": [[[1, 1], [1, 2], [2, 2], [2, 1], [1, 1]]] + } + } + }; + let expected = 'geometry1 1 1 2 2 2 2 1 1 1'; + let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj); + expect(filter).toEqual(expected); + }); + it('Check SpatialFilterField cql', () => { let filterObj = { simpleFilterFields: [{ "fieldId": 1,