Skip to content

Commit

Permalink
Fixes #1182: right usage of GML2 for WFS 1.0.0 (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto authored Oct 25, 2016
1 parent d149919 commit f0fba60
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 16 deletions.
33 changes: 23 additions & 10 deletions web/client/utils/FilterUtils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@
* LICENSE file in the root directory of this source tree.
*/

const normalizeVersion = (version) => {
if (!version) {
return "2.0";
}
if (version === "1.0") {
return "1.0.0";
}
if (version === "1.1") {
return "1.1.0";
}
return version;
};

const FilterUtils = {
ogcVersion: "2.0",
ogcLogicalOperator: {
Expand Down Expand Up @@ -43,7 +56,7 @@ const FilterUtils = {
return e;
}

const versionOGC = version || this.ogcVersion;
const versionOGC = normalizeVersion(version || this.ogcVersion);
this.nsplaceholder = versionOGC === "2.0" ? "fes" : "ogc";

this.setOperatorsPlaceholders("{namespace}", this.nsplaceholder);
Expand Down Expand Up @@ -129,7 +142,7 @@ const FilterUtils = {
});
},
getGetFeatureBase: function(version, pagination, hits, format) {
let ver = !version ? "2.0" : version;
let ver = normalizeVersion(version);

let getFeature = '<wfs:GetFeature ';
getFeature += format ? 'outputFormat="' + format + '" ' : '';
Expand Down Expand Up @@ -475,10 +488,10 @@ const FilterUtils = {
let coords = element.map((coordinate) => {
return coordinate[0] + " " + coordinate[1];
});
if (version === "2.0") {
gmlPoint += '<gml:pos>' + coords.join(" ") + '</gml:pos>';
} else {
if (version === "1.0.0") {
gmlPoint += '<gml:coord><X>' + element[0][0] + '</X><Y>' + element[0][1] + '</Y></gml:coord>';
} else {
gmlPoint += '<gml:pos>' + coords.join(" ") + '</gml:pos>';
}
});

Expand All @@ -496,16 +509,16 @@ const FilterUtils = {
// ///////////////////////////////////////////////////////////////////////////////////////////////////////
coordinates.forEach((element, index) => {
let coords = element.map((coordinate) => {
return coordinate[0] + (version === "2.0" ? " " : ",") + coordinate[1];
return coordinate[0] + (version === "1.0.0" ? "," : " ") + coordinate[1];
});
const exterior = (version === "2.0" ? "exterior" : "outerBoundaryIs");
const interior = (version === "2.0" ? "exterior" : "innerBoundaryIs");
const exterior = (version === "1.0.0" ? "outerBoundaryIs" : "exterior");
const interior = (version === "1.0.0" ? "innerBoundaryIs" : "exterior");
gmlPolygon +=
(index < 1 ? '<gml:' + exterior + '>' : '<gml:' + interior + '>') +
'<gml:LinearRing>' +
(version === "2.0" ? '<gml:posList>' : '<gml:coordinates>') +
(version === "1.0.0" ? '<gml:coordinates>' : '<gml:posList>') +
coords.join(" ") +
(version === "2.0" ? '</gml:posList>' : '</gml:coordinates>') +
(version === "1.0.0" ? '</gml:coordinates>' : '</gml:posList>') +
'</gml:LinearRing>' +
(index < 1 ? '</gml:' + exterior + '>' : '</gml:' + interior + '>');
});
Expand Down
76 changes: 70 additions & 6 deletions web/client/utils/__tests__/FilterUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe('FilterUtils', () => {
let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj);
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField ogc 1.0 Polygon', () => {
it('Check SpatialFilterField ogc 1.0.0 Polygon', () => {
let filterObj = {
spatialField: {
"operation": "INTERSECTS",
Expand All @@ -320,11 +320,11 @@ describe('FilterUtils', () => {
}
}
};
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");
let expected = '<wfs:GetFeature service="WFS" version="1.0.0" outputFormat="GML2" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.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.0");
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField ogc 1.0 Point', () => {
it('Check SpatialFilterField ogc 1.0.0 Point', () => {
let filterObj = {
spatialField: {
"operation": "INTERSECTS",
Expand All @@ -336,10 +336,58 @@ describe('FilterUtils', () => {
}
}
};
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 expected = '<wfs:GetFeature service="WFS" version="1.0.0" outputFormat="GML2" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.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.0");
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField normalizeVersion', () => {
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.0" outputFormat="GML2" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.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 1.1.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="1.1.0" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.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:exterior><gml:LinearRing><gml:posList>1 1 1 2 2 2 2 1 1 1</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></ogc:Intersects></ogc:Filter></wfs:Query></wfs:GetFeature>';
let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.1.0");
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField ogc 1.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.1.0" xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.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:pos>1 1</gml:pos></gml:Point></ogc:Intersects></ogc:Filter></wfs:Query></wfs:GetFeature>';
let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "1.1.0");
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField ogc 2.0 Point', () => {
let filterObj = {
spatialField: {
Expand All @@ -353,7 +401,7 @@ describe('FilterUtils', () => {
}
};
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);
let filter = FilterUtils.toOGCFilter("ft_name_test", filterObj, "2.0");
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField ogc 2.0 Polygon', () => {
Expand All @@ -369,6 +417,22 @@ describe('FilterUtils', () => {
}
};
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, "2.0");
expect(filter).toEqual(expected);
});
it('Check SpatialFilterField ogc default version is 2.0', () => {
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);
});
Expand Down

0 comments on commit f0fba60

Please sign in to comment.