[Mapbender-commits] r9794 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Wed Oct 4 09:11:55 PDT 2017
Author: armin11
Date: 2017-10-04 09:11:55 -0700 (Wed, 04 Oct 2017)
New Revision: 9794
Added:
trunk/mapbender/http/classes/class_crs.php
Log:
First draft of a simple class to request information from the epsg registry
Added: trunk/mapbender/http/classes/class_crs.php
===================================================================
--- trunk/mapbender/http/classes/class_crs.php (rev 0)
+++ trunk/mapbender/http/classes/class_crs.php 2017-10-04 16:11:55 UTC (rev 9794)
@@ -0,0 +1,210 @@
+<?php
+# http://www.mapbender2.org/index.php/class_crs.php
+#
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../core/globalSettings.php");
+require_once(dirname(__FILE__)."/../../conf/altered_axis_epsg.php");
+require_once(dirname(__FILE__)."/class_connector.php");
+
+//class_crs.php
+//TODO
+//get information from registry
+//axisOrder - lat/lon, lon/lat, easting/northing, northing/easting
+//conf file - instead of registry as fallback
+//TODO - use also service type and version as parameter??? wms 1.3+, wfs 1.0+?
+
+
+
+/**
+ * A class to handle information about different CoordinateReferenceSystems
+ *
+ */
+
+class Crs {
+ var $identifierType; //'epsg', 'urn', 'url', 'other'
+ var $identifierCode;
+ var $identifier;
+ var $name;
+ var $gmlRepresentation;
+ //var $uuid;
+ var $epsgType; // false, 'geographic 2D', 'projected', ''
+ var $axisOrder; //different types, first: 'east,north' - ('lon,lat'), second: 'north,east' - ('lat,lon')
+ //preasume, that the old order is always lat/lon for geo and east/north for projected systems
+ var $resolveSuccess;
+ var $resolveErrorMessage;
+
+ public function __construct ($identifier) {
+ $this->extractIdentifierType($identifier);
+ $this->resolveCrsInfo();
+
+ }
+
+ private function extractIdentifierType ($identifier) {
+ //check for type
+ if (substr(strtoupper($identifier), 0, 5) === "EPSG:") {
+ $this->identifier = $identifier;
+ $this->identifierType = 'epsg';
+ $this->identifierCode = explode(':',$identifier)[1];
+ return;
+ } else {
+ //check for urn based version - example: urn:ogc:def:crs:EPSG:
+ if (substr(strtoupper($identifier), 0, 21) === "URN:OGC:DEF:CRS:EPSG:") {
+ //delete this part from original identifier
+ $identifierNew = str_replace('URN:OGC:DEF:CRS:EPSG:','',strtoupper($identifier));
+ $this->identifier = $identifier;
+ $this->identifierType = 'urn';
+ $this->identifierCode = explode(':',$identifierNew)[1];
+ return;
+ } else {
+ if (substr($identifier, 0, 31) === 'http://www.opengis.net/def/crs/') {
+ $identifierNew = str_replace('http://www.opengis.net/def/crs/','',$identifier);
+ //remaining string: ({OGC|EPSG}/{0}/{code})
+ $this->identifier = $identifier;
+ $this->identifierType = 'url';
+ $this->identifierCode = explode('/',$identifierNew)[2];
+ return;
+ } else {
+ $this->identifier = $identifier;
+ $this->identifierType = 'other';
+ $this->identifierCode = $identifier;
+ }
+ }
+ }
+ }
+
+ private function resolveCrsInfo () {
+ //built urls to get information from registries
+ switch ($this->identifierType) {
+ case "epsg":
+ $registryBaseUrl = "http://www.epsg-registry.org/export.htm?gml=";
+ $registryUrl = $registryBaseUrl.urlencode("urn:ogc:def:crs:EPSG::".$this->identifierCode);
+ break;
+ case "urn":
+ $registryBaseUrl = "http://www.epsg-registry.org/export.htm?gml=";
+ $registryUrl = $registryBaseUrl.urlencode($this->identifier);
+ $xpathCrsType = "";
+ $xpathAxis = "";
+ break;
+ case "url":
+ $registryBaseUrl = "http://www.epsg-registry.org/export.htm?gml=";
+ $registryUrl = $registryBaseUrl.urlencode("urn:ogc:def:crs:EPSG::".$this->identifierCode);
+ $xpathCrsType = "";
+ $xpathAxis = "";
+
+ break;
+ default:
+ break;
+ }
+ //get gml description from registry
+ //echo $registryUrl . "<br>";
+ //die();
+ $crsConnector = new connector($registryUrl);
+ $crsConnector->set("timeOut", "2");
+ if ($crsConnector->timedOut == true) {
+ return false;
+ }
+ $this->gmlRepresentation = $crsConnector->file;
+ //parse relevant information
+ libxml_use_internal_errors(true);
+ try {
+ $crsXml = simplexml_load_string($this->gmlRepresentation);
+ if ($crsXml === false) {
+ foreach(libxml_get_errors() as $error) {
+ $err = new mb_exception("class_crs:".$error->message);
+ }
+ throw new Exception("class_crs:".'Cannot parse crs gml!');
+ return false;
+ }
+ }
+ catch (Exception $e) {
+ $err = new mb_exception("class_crs:".$e->getMessage());
+ return false;
+ }
+ //if parsing was successful
+ if ($crsXml !== false) {
+ $crsXml->registerXPathNamespace("epsg", "urn:x-ogp:spec:schema-xsd:EPSG:1.0:dataset");
+ $crsXml->registerXPathNamespace("gml", "http://www.opengis.net/gml/3.2");
+ $crsXml->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
+ //switch for type of cs - distinguish between ellipsoidalCS and CartesianCS (begin with lowercase character in crs document)
+ $this->epsgType = $crsXml->xpath('//gml:metaDataProperty/epsg:CommonMetaData/epsg:type');
+ $this->epsgType = $this->epsgType[0];
+ $this->name = $crsXml->xpath('//gml:name');
+ $this->name = $this->name[0];
+ //echo $this->name;
+ //echo $this->epsgType;
+ //get attribute for specific system
+ switch ($this->epsgType) {
+ case "projected":
+ $xpathIdentifierCs = "//gml:cartesianCS/@xlink:href";
+ break;
+ case "geographic 2D":
+ $xpathIdentifierCs = "//gml:ellipsoidalCS/@xlink:href";
+ break;
+ }
+ $csIdentifier = $crsXml->xpath($xpathIdentifierCs);
+ $csIdentifier = $csIdentifier[0];
+ //echo $csIdentifier."<br>";
+ //get axis order from further xml document
+ $urlToCsDefinition = $registryBaseUrl.urlencode($csIdentifier);
+ $csConnector = new connector($urlToCsDefinition);
+ $csConnector->set("timeOut", "2");
+ if ($csConnector->timedOut == true) {
+ return false;
+ }
+ $csGmlRepresentation = $csConnector->file;
+ //echo $csGmlRepresentation;
+ //parse relevant information
+ //libxml_use_internal_errors(true);
+ try {
+ $csXml = simplexml_load_string($csGmlRepresentation);
+ if ($csXml === false) {
+ foreach(libxml_get_errors() as $error) {
+ $err = new mb_exception("class_crs:".$error->message);
+ }
+ throw new Exception("class_crs: Cannot parse cs gml!");
+ return false;
+ }
+ }
+ catch (Exception $e) {
+ $err = new mb_exception("class_cs:".$e->getMessage());
+ return false;
+ }
+ //echo $csIdentifier."<br>";
+ if ($csXml !== false) {
+ $csXml->registerXPathNamespace("epsg", "urn:x-ogp:spec:schema-xsd:EPSG:1.0:dataset");
+ $csXml->registerXPathNamespace("gml", "http://www.opengis.net/gml/3.2");
+ $csXml->registerXPathNamespace("xlink", "http://www.w3.org/1999/xlink");
+ //switch for type of cs - distinguish between ellipsoidalCS and CartesianCS (begin with lowercase character in crs document)
+ $axis = $csXml->xpath('//gml:axis/gml:CoordinateSystemAxis/gml:axisDirection');
+ //switch for crs lookup table of crs which axis order was swapped from earlier ogc standards to newer - identify them by the usage og EPSG:XXXX notation
+ if (DEFINED("OLD_EPSG_AXIS_ORDER_ALTERED") && OLD_EPSG_AXIS_ORDER_ALTERED !== "") {
+ $old_epsg_axis_order_altered = explode(",", OLD_EPSG_AXIS_ORDER_ALTERED);
+ } else {
+ $old_epsg_axis_order_altered = array();
+ }
+ if ($this->identifierType == 'epsg' && in_array($this->identifierCode, $old_epsg_axis_order_altered)) {
+ $this->axisOrder = $axis[1].",".$axis[0];
+ } else {
+ $this->axisOrder = $axis[0].",".$axis[1];
+ }
+ }
+ }
+ //store information
+ }
+}
+
+?>
More information about the Mapbender_commits
mailing list