Skip to content

Commit

Permalink
Fixes #1182: implemented GML2 support for WFS 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Oct 20, 2016
1 parent 2b5b7e0 commit 80ee0a1
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 29 deletions.
49 changes: 21 additions & 28 deletions web/client/utils/FilterUtils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 += '<gml:MultiPoint srsName="' + (this.objFilter.spatialField.geometry.projection || "EPSG:4326") + '">';
Expand All @@ -402,7 +402,7 @@ const FilterUtils = {
let point = element;
if (point) {
ogc += "<gml:pointMember>";
ogc += this.getGmlPointElement(point);
ogc += this.getGmlPointElement(point, version);
ogc += "</gml:pointMember>";
}
});
Expand All @@ -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";
Expand All @@ -426,7 +426,7 @@ const FilterUtils = {
let polygon = element;
if (polygon) {
ogc += "<gml:" + polygonMemberTagName + ">";
ogc += this.getGmlPolygonElement(polygon);
ogc += this.getGmlPolygonElement(polygon, version);
ogc += "</gml:" + polygonMemberTagName + ">";
}
});
Expand Down Expand Up @@ -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 = '<gml:Point srsDimension="2"';

gmlPoint += srsName ? ' srsName="' + srsName + '">' : '>';
Expand All @@ -475,14 +475,17 @@ const FilterUtils = {
let coords = element.map((coordinate) => {
return coordinate[0] + " " + coordinate[1];
});

gmlPoint += '<gml:pos>' + coords.join(" ") + '</gml:pos>';
if (version === "2.0") {
gmlPoint += '<gml:pos>' + coords.join(" ") + '</gml:pos>';
} else {
gmlPoint += '<gml:coord><X>' + element[0][0] + '</X><Y>' + element[0][1] + '</Y></gml:coord>';
}
});

gmlPoint += '</gml:Point>';
return gmlPoint;
},
getGmlPolygonElement: function(coordinates, srsName) {
getGmlPolygonElement: function(coordinates, srsName, version) {
let gmlPolygon = '<gml:Polygon';

gmlPolygon += srsName ? ' srsName="' + srsName + '">' : '>';
Expand All @@ -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 +=
'<gml:exterior>' +
const exterior = (version === "2.0" ? "exterior" : "outerBoundaryIs");
const interior = (version === "2.0" ? "exterior" : "innerBoundaryIs");
gmlPolygon +=
(index < 1 ? '<gml:' + exterior + '>' : '<gml:' + interior + '>') +
'<gml:LinearRing>' +
'<gml:posList>' +
(version === "2.0" ? '<gml:posList>' : '<gml:coordinates>') +
coords.join(" ") +
'</gml:posList>' +
(version === "2.0" ? '</gml:posList>' : '</gml:coordinates>') +
'</gml:LinearRing>' +
'</gml:exterior>';
} else {
gmlPolygon +=
'<gml:interior>' +
'<gml:LinearRing>' +
'<gml:posList>' +
coords.join(" ") +
'</gml:posList>' +
'</gml:LinearRing>' +
'</gml:interior>';
}
(index < 1 ? '</gml:' + exterior + '>' : '</gml:' + interior + '>');
});

gmlPolygon += '</gml:Polygon>';
Expand Down Expand Up @@ -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);
}
Expand Down
66 changes: 65 additions & 1 deletion web/client/utils/__tests__/FilterUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<wfs:GetFeature service="WFS" version="1.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"><wfs:Query typeName="ft_name_test" srsName="EPSG:4326"><ogc:Filter><ogc:Intersects><ogc:PropertyName>geometry</ogc:PropertyName><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>1,1 1,2 2,2 2,1 1,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogc:Intersects></ogc:Filter></wfs:Query></wfs:GetFeature>';
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 = '<wfs:GetFeature service="WFS" version="1.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"><wfs:Query typeName="ft_name_test" srsName="EPSG:4326"><ogc:Filter><ogc:Intersects><ogc:PropertyName>geometry</ogc:PropertyName><gml:Point srsDimension="2" srsName="EPSG:4326"><gml:coord><X>1</X><Y>1</Y></gml:coord></gml:Point></ogc:Intersects></ogc:Filter></wfs:Query></wfs:GetFeature>';
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 = '<wfs:GetFeature service="WFS" version="2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"><wfs:Query typeNames="ft_name_test" srsName="EPSG:4326"><fes:Filter><fes:Intersects><fes:ValueReference>geometry</fes:ValueReference><gml:Point srsDimension="2" srsName="EPSG:4326"><gml:pos>1 1</gml:pos></gml:Point></fes:Intersects></fes:Filter></wfs:Query></wfs:GetFeature>';
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 = '<wfs:GetFeature service="WFS" version="2.0" xmlns:wfs="http://www.opengis.net/wfs/2.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"><wfs:Query typeNames="ft_name_test" srsName="EPSG:4326"><fes:Filter><fes:Intersects><fes:ValueReference>geometry</fes:ValueReference><gml:Polygon srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList>1 1 1 2 2 2 2 1 1 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></fes:Intersects></fes:Filter></wfs:Query></wfs:GetFeature>';
let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj);
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField cql', () => {
let filterObj = {
simpleFilterFields: [{
"fieldId": 1,
Expand Down

0 comments on commit 80ee0a1

Please sign in to comment.