[Mapbender-commits] r7068 - in trunk/mapbender: lib
test/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Oct 27 06:38:05 EDT 2010
Author: christoph
Date: 2010-10-27 03:38:05 -0700 (Wed, 27 Oct 2010)
New Revision: 7068
Added:
trunk/mapbender/lib/class_OgcFilter.php
trunk/mapbender/test/http/classes/OgcFilterTest.php
Log:
Allows the creation of OGC filter XMLs. Inherits from existing Filter class. Needs to be enhanced for complex filters.
Added: trunk/mapbender/lib/class_OgcFilter.php
===================================================================
--- trunk/mapbender/lib/class_OgcFilter.php (rev 0)
+++ trunk/mapbender/lib/class_OgcFilter.php 2010-10-27 10:38:05 UTC (rev 7068)
@@ -0,0 +1,57 @@
+<?php
+# License:
+# Copyright (c) 2009, Open Source Geospatial Foundation
+# This program is dual licensed under the GNU General Public License
+# and Simplified BSD license.
+# http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
+
+require_once dirname(__FILE__) . "/class_Filter.php";
+require_once dirname(__FILE__) . "/../http/classes/class_wfs_configuration.php";
+require_once dirname(__FILE__) . "/../http/classes/class_universal_gml_factory.php";
+require_once dirname(__FILE__) . "/../http/classes/class_universal_wfs_factory.php";
+
+
+/**
+ * Description of class_OgcFilter
+ *
+ * @author cbaudson
+ */
+class OgcFilter extends Filter {
+ const SPATIAL_OPERATORS = "Intersects";
+
+ public function __construct () {
+ $allOperators = implode(",", array(self::OPERATORS, self::SPATIAL_OPERATORS));
+ if (func_num_args() === 4) {
+ $this->operator = func_get_arg(0);
+ $this->key = func_get_arg(1);
+ $this->value = func_get_arg(2);
+ $this->wfsConf = func_get_arg(3);
+ if (!in_array($this->operator, explode(",", $allOperators))) {
+ throw new Exception ("OgcFilter: Invalid operator " . $this->operator);
+ }
+ if (!is_a($this->wfsConf, "WfsConfiguration")) {
+ throw new Exception ("OgcFilter: wfsConf is not a WFS Configuration.");
+ }
+
+ }
+ else {
+ throw new Exception("OgcFilter: Insufficient arguments.");
+ }
+ }
+
+ public function toXmlNoWrap() {
+ $k = "<ogc:PropertyName>" . $this->key . "</ogc:PropertyName>";
+ if (in_array($this->operator, explode(",", self::SPATIAL_OPERATORS))) {
+ $gmlFactory = new UniversalGmlFactory();
+ $gml = $gmlFactory->createFromGeoJson($this->value, $this->wfsConf);
+ $v = $gml->toGml();
+ }
+ return "<" . $this->operator . ">" . $k . $v . "</" . $this->operator . ">";
+ }
+
+ public function toXml () {
+ return "<ogc:Filter>" . $this->toXmlNoWrap() . "</ogc:Filter>";
+ }
+
+}
+?>
Added: trunk/mapbender/test/http/classes/OgcFilterTest.php
===================================================================
--- trunk/mapbender/test/http/classes/OgcFilterTest.php (rev 0)
+++ trunk/mapbender/test/http/classes/OgcFilterTest.php 2010-10-27 10:38:05 UTC (rev 7068)
@@ -0,0 +1,105 @@
+<?php
+require_once 'PHPUnit/Framework.php';
+require_once dirname(__FILE__) . "/../../../lib/class_OgcFilter.php";
+
+class OgcFilterTest extends PHPUnit_Framework_TestCase {
+
+ public function testConstructorEmpty () {
+ try {
+ $filter = new OgcFilter();
+ }
+ catch (Exception $e) {
+ return;
+ }
+ $this->fail('An expected Exception has not been raised.');
+ }
+
+ public function testInvalidOperator () {
+ try {
+ $filter = new OgcFilter("gsdfhj", "a", "b", new WfsConfiguration());
+ }
+ catch (Exception $e) {
+ return;
+ }
+ $this->fail('An expected Exception has not been raised.');
+ }
+
+ public function testInvalidWfsConf () {
+ try {
+ $filter = new OgcFilter("Intersects", "a", 3, null);
+ }
+ catch (Exception $e) {
+ return;
+ }
+ $this->fail('An expected Exception has not been raised.');
+ }
+
+ // this test is not operational
+/*
+ public function testOperatorIntersects () {
+ $geoJson = <<<GEOJSON
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "crs": {
+ "type": "name",
+ "properties": {
+ "name": "EPSG:4326"
+ }
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ 28,
+ -38
+ ],
+ [
+ 31,
+ -38
+ ],
+ [
+ 31,
+ -41
+ ],
+ [
+ 28,
+ -41
+ ],
+ [
+ 28,
+ -38
+ ]
+ ]
+ }
+ }
+ ]
+}
+GEOJSON;
+ $wfsConf = new WfsConfiguration();
+
+ $filter = new OgcFilter("Intersects", "topp:the_geom", $geoJson, $wfsConf);
+
+ $filterXml = <<<FILTER
+<ogc:Filter>
+ <Intersects>
+ <ogc:PropertyName>topp:the_geom</ogc:PropertyName>
+ <gml:Polygon srsName="EPSG:4326">
+ <gml:outerBoundaryIs>
+ <gml:LinearRing>
+ <gml:coordinates>28,-38 31,-38 31,-41 28,-41 28,-38</gml:coordinates>
+ </gml:LinearRing>
+ </gml:outerBoundaryIs>
+ </gml:Polygon>
+ </Intersects>
+</ogc:Filter>
+FILTER;
+
+// $this->assertEquals($filterXml, $filter->toXml());
+ }
+
+*/
+}
+?>
\ No newline at end of file
More information about the Mapbender_commits
mailing list