Adding support for reading and writing spatial filters with Within, Contains, and Intersects elements. Thanks pvalsecc for the original patch. r=ahocevar (closes #1959)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@8921 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
126
tests/Format/Filter/v1.html
Normal file
126
tests/Format/Filter/v1.html
Normal file
@@ -0,0 +1,126 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
function test_Intersects(t) {
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var str =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
'<Intersects>' +
|
||||
'<PropertyName>Geometry</PropertyName>' +
|
||||
'<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
|
||||
'<gml:outerBoundaryIs>' +
|
||||
'<gml:LinearRing>' +
|
||||
'<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
|
||||
'</gml:LinearRing>' +
|
||||
'</gml:outerBoundaryIs>' +
|
||||
'</gml:Polygon>' +
|
||||
'</Intersects>' +
|
||||
'</Filter>';
|
||||
|
||||
var format = new OpenLayers.Format.Filter.v1_0_0();
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.INTERSECTS,
|
||||
property: "Geometry",
|
||||
value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
|
||||
});
|
||||
|
||||
// test writing
|
||||
var node = format.write(filter);
|
||||
t.xml_eq(node, str, "filter correctly written");
|
||||
|
||||
// test reading
|
||||
var doc = (new OpenLayers.Format.XML).read(str);
|
||||
var got = format.read(doc.firstChild);
|
||||
t.eq(got.type, filter.type, "read correct type");
|
||||
t.eq(got.property, filter.property, "read correct property");
|
||||
t.geom_eq(got.value, filter.value, "read correct value");
|
||||
|
||||
}
|
||||
|
||||
function test_Within(t) {
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var str =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
'<Within>' +
|
||||
'<PropertyName>Geometry</PropertyName>' +
|
||||
'<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
|
||||
'<gml:outerBoundaryIs>' +
|
||||
'<gml:LinearRing>' +
|
||||
'<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
|
||||
'</gml:LinearRing>' +
|
||||
'</gml:outerBoundaryIs>' +
|
||||
'</gml:Polygon>' +
|
||||
'</Within>' +
|
||||
'</Filter>';
|
||||
|
||||
var format = new OpenLayers.Format.Filter.v1_0_0();
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.WITHIN,
|
||||
property: "Geometry",
|
||||
value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
|
||||
});
|
||||
|
||||
// test writing
|
||||
var node = format.write(filter);
|
||||
t.xml_eq(node, str, "filter correctly written");
|
||||
|
||||
// test reading
|
||||
var doc = (new OpenLayers.Format.XML).read(str);
|
||||
var got = format.read(doc.firstChild);
|
||||
t.eq(got.type, filter.type, "read correct type");
|
||||
t.eq(got.property, filter.property, "read correct property");
|
||||
t.geom_eq(got.value, filter.value, "read correct value");
|
||||
|
||||
}
|
||||
|
||||
function test_Contains(t) {
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var str =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
'<Contains>' +
|
||||
'<PropertyName>Geometry</PropertyName>' +
|
||||
'<gml:Polygon xmlns:gml="http://www.opengis.net/gml">' +
|
||||
'<gml:outerBoundaryIs>' +
|
||||
'<gml:LinearRing>' +
|
||||
'<gml:coordinates decimal="." cs="," ts=" ">2488789,289552 2588789,289552 2588789,389552 2488789,389552 2488789,289552</gml:coordinates>' +
|
||||
'</gml:LinearRing>' +
|
||||
'</gml:outerBoundaryIs>' +
|
||||
'</gml:Polygon>' +
|
||||
'</Contains>' +
|
||||
'</Filter>';
|
||||
|
||||
var format = new OpenLayers.Format.Filter.v1_0_0();
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.CONTAINS,
|
||||
property: "Geometry",
|
||||
value: OpenLayers.Geometry.fromWKT("POLYGON((2488789 289552, 2588789 289552, 2588789 389552, 2488789 389552, 2488789 289552))")
|
||||
});
|
||||
|
||||
// test writing
|
||||
var node = format.write(filter);
|
||||
t.xml_eq(node, str, "filter correctly written");
|
||||
|
||||
// test reading
|
||||
var doc = (new OpenLayers.Format.XML).read(str);
|
||||
var got = format.read(doc.firstChild);
|
||||
t.eq(got.type, filter.type, "read correct type");
|
||||
t.eq(got.property, filter.property, "read correct property");
|
||||
t.geom_eq(got.value, filter.value, "read correct value");
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
@@ -77,7 +77,81 @@
|
||||
|
||||
t.xml_eq(node, out, "bbox correctly written");
|
||||
}
|
||||
|
||||
|
||||
function test_DWithin(t) {
|
||||
|
||||
t.plan(6);
|
||||
|
||||
var str =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
'<DWithin>' +
|
||||
'<PropertyName>Geometry</PropertyName>' +
|
||||
'<gml:Point xmlns:gml="http://www.opengis.net/gml">' +
|
||||
'<gml:coordinates decimal="." cs="," ts=" ">2488789,289552</gml:coordinates>' +
|
||||
'</gml:Point>' +
|
||||
'<Distance units="m">1000</Distance>' +
|
||||
'</DWithin>' +
|
||||
'</Filter>';
|
||||
|
||||
var format = new OpenLayers.Format.Filter.v1_0_0();
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.DWITHIN,
|
||||
property: "Geometry",
|
||||
value: new OpenLayers.Geometry.Point(2488789,289552),
|
||||
distance: 1000,
|
||||
distanceUnits: "m"
|
||||
});
|
||||
|
||||
// test writing
|
||||
var node = format.write(filter);
|
||||
t.xml_eq(node, str, "filter correctly written");
|
||||
|
||||
// test reading
|
||||
var doc = (new OpenLayers.Format.XML).read(str);
|
||||
var got = format.read(doc.firstChild);
|
||||
t.eq(got.type, filter.type, "read correct type");
|
||||
t.eq(got.property, filter.property, "read correct property");
|
||||
t.geom_eq(got.value, filter.value, "read correct value");
|
||||
t.eq(got.distance, filter.distance, "read correct distance");
|
||||
t.eq(got.distanceUnits, filter.distanceUnits, "read correct distance units");
|
||||
|
||||
}
|
||||
|
||||
function test_Intersects(t) {
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var str =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
'<Intersects>' +
|
||||
'<PropertyName>Geometry</PropertyName>' +
|
||||
'<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">' +
|
||||
'<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>' +
|
||||
'</gml:Box>' +
|
||||
'</Intersects>' +
|
||||
'</Filter>';
|
||||
|
||||
var format = new OpenLayers.Format.Filter.v1_0_0();
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.INTERSECTS,
|
||||
property: "Geometry",
|
||||
value: new OpenLayers.Bounds(-180, -90, 180, 90),
|
||||
projection: "EPSG:4326"
|
||||
});
|
||||
|
||||
// test writing
|
||||
var node = format.write(filter);
|
||||
t.xml_eq(node, str, "filter correctly written");
|
||||
|
||||
// test reading
|
||||
var doc = (new OpenLayers.Format.XML).read(str);
|
||||
var got = format.read(doc.firstChild);
|
||||
t.eq(got.type, filter.type, "read correct type");
|
||||
t.eq(got.property, filter.property, "read correct property");
|
||||
t.eq(got.value.toArray(), filter.value.toArray(), "read correct value");
|
||||
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -167,6 +167,41 @@
|
||||
t.xml_eq(node, out, "bbox correctly written");
|
||||
}
|
||||
|
||||
function test_Intersects(t) {
|
||||
|
||||
t.plan(4);
|
||||
|
||||
var str =
|
||||
'<Filter xmlns="http://www.opengis.net/ogc">' +
|
||||
'<Intersects>' +
|
||||
'<PropertyName>Geometry</PropertyName>' +
|
||||
'<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">' +
|
||||
'<gml:lowerCorner>-180 -90</gml:lowerCorner>' +
|
||||
'<gml:upperCorner>180 90</gml:upperCorner>' +
|
||||
'</gml:Envelope>' +
|
||||
'</Intersects>' +
|
||||
'</Filter>';
|
||||
|
||||
var format = new OpenLayers.Format.Filter.v1_1_0();
|
||||
var filter = new OpenLayers.Filter.Spatial({
|
||||
type: OpenLayers.Filter.Spatial.INTERSECTS,
|
||||
property: "Geometry",
|
||||
value: new OpenLayers.Bounds(-180, -90, 180, 90),
|
||||
projection: "EPSG:4326"
|
||||
});
|
||||
|
||||
// test writing
|
||||
var node = format.write(filter);
|
||||
t.xml_eq(node, str, "filter correctly written");
|
||||
|
||||
// test reading
|
||||
var doc = (new OpenLayers.Format.XML).read(str);
|
||||
var got = format.read(doc.firstChild);
|
||||
t.eq(got.type, filter.type, "read correct type");
|
||||
t.eq(got.property, filter.property, "read correct property");
|
||||
t.eq(got.value.toArray(), filter.value.toArray(), "read correct value");
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
<li>Format/SLD.html</li>
|
||||
<li>Format/SLD/v1_0_0.html</li>
|
||||
<li>Format/Filter.html</li>
|
||||
<li>Format/Filter/v1.html</li>
|
||||
<li>Format/Filter/v1_0_0.html</li>
|
||||
<li>Format/Filter/v1_1_0.html</li>
|
||||
<li>Format/WFSDescribeFeatureType.html</li>
|
||||
|
||||
Reference in New Issue
Block a user