[Mapbender-commits] r9796 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Oct 5 06:28:26 PDT 2017


Author: armin11
Date: 2017-10-05 06:28:26 -0700 (Thu, 05 Oct 2017)
New Revision: 9796

Modified:
   trunk/mapbender/http/classes/class_crs.php
Log:
Fix for axis order decision, also use apc to cache axis order

Modified: trunk/mapbender/http/classes/class_crs.php
===================================================================
--- trunk/mapbender/http/classes/class_crs.php	2017-10-04 16:13:56 UTC (rev 9795)
+++ trunk/mapbender/http/classes/class_crs.php	2017-10-05 13:28:26 UTC (rev 9796)
@@ -1,7 +1,6 @@
 <?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)
@@ -19,19 +18,17 @@
 require_once(dirname(__FILE__)."/../../core/globalSettings.php");
 require_once(dirname(__FILE__)."/../../conf/altered_axis_epsg.php");
 require_once(dirname(__FILE__)."/class_connector.php");
+require_once(dirname(__FILE__)."/class_cache.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
- * 
+ * A class to handle information about different CoordinateReferenceSystems. The class tries to call the epsg registry an pulls some
+ * information from it. The handling of CRS axis in different ows is not really homogeneous. 
+ * Further information:
+ * https://themes.jrc.ec.europa.eu/discussion/view/109106/fyi-interpreted-coordinate-order-flipped-in-gml-files-with-uri-format-srsname
+ * http://postgis.net/2013/08/18/tip_lon_lat/
+ * https://github.com/deegree/deegree3/wiki/Axis-order-handling
+ * http://docs.geotools.org/latest/userguide/library/referencing/order.html
+ * http://mapserver.org/ogc/wms_server.html
  */
 
 class Crs {
@@ -40,19 +37,36 @@
 	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 $epsgType; // false, 'geographic 2D', 'projected', '...'
+	var $axisOrder; //different types:'east,north' - ('lon,lat') or 'north,east' - ('lat,lon')
+	//preasume, that the old order is always lon/lat for geo and east/north for projected systems
 	var $resolveSuccess;
+	var $resolveOrigin;
 	var $resolveErrorMessage;
 
 	public function __construct ($identifier) {
+		$this->resolveSuccess = false;
+		$this->resolveErrorMessage = false;
 		$this->extractIdentifierType($identifier);
-		$this->resolveCrsInfo();
-		
+		if ($this->resolveCrsInfo() == true) {
+			$this->resolveSuccess = true;
+		}
 	}
-	
+/**
+ * A public function whith a parameter for {owstype}_{version}. If the ows needs a swap of the crs axis order true is returned,
+ * otherwise - if the axis are handled as they are defined in the epsg registry - the function returns false
+ */
+	//handles ows identifier: wms_1.0.0, wms_1.1.1, wms_1.3.0, wfs_1.0.0, wfs_1.1.0, wfs_2.0.0, wfs_2.0.2
+	public function alterAxisOrder ($targetOws) {
+		$owsWithSpecialOrder = array("wms_1.0.0","wms_1.1.1","wfs_1.0.0");
+		$order = "east,north";
+		if (in_array($targetOws, $owsWithSpecialOrder) && $this->identifierType == 'epsg' && $this->axisOrder !== $order) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+
 	private function extractIdentifierType ($identifier) {
 		//check for type
 		if (substr(strtoupper($identifier), 0, 5) === "EPSG:") {
@@ -87,6 +101,17 @@
 	}
 
 	private function resolveCrsInfo () {
+		$cache = new Cache();
+		//try to read from cache if already exists
+		if ($cache->isActive && $cache->cachedVariableExists(md5($this->identifier))) {
+			$cachedObject = json_decode($cache->cachedVariableFetch(md5($this->identifier)));
+			$this->gmlRepresentation = $cachedObject->gmlRepresentation;	
+			$this->epsgType = $cachedObject->epsgType;
+			$this->axisOrder = $cachedObject->axisOrder;
+			$this->name = $cachedObject->name;		
+			$e = new mb_notice("http/classes/class_crs.php - read crs info from cache!");
+			return true;
+		}
 		//built urls to get information from registries
 		switch ($this->identifierType) {
 			case "epsg":
@@ -96,28 +121,26 @@
 			case "urn":
 				$registryBaseUrl = "http://www.epsg-registry.org/export.htm?gml=";
 				$registryUrl = $registryBaseUrl.urlencode($this->identifier);
-				$xpathCrsType = "";
-				$xpathAxis = "";
+				/*$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 = "";
-
+				/*$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;
+		//generate separate jsonObject
+		$jsonCrsInfo->gmlRepresentation = $this->gmlRepresentation;
 		//parse relevant information
 		libxml_use_internal_errors(true);
 		try {
@@ -144,6 +167,9 @@
 			$this->epsgType = $this->epsgType[0];
 			$this->name = $crsXml->xpath('//gml:name');
 			$this->name = $this->name[0];
+			$e = new mb_notice("http/classes/class_crs.php - name of crs: ".$this->name);
+			$jsonCrsInfo->name = (string)$this->name;
+			$jsonCrsInfo->epsgType = (string)$this->epsgType;
 			//echo $this->name;
 			//echo $this->epsgType;
 			//get attribute for specific system
@@ -157,7 +183,6 @@
 			} 
 			$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);
@@ -166,9 +191,6 @@
 				return false;
 			}
 			$csGmlRepresentation = $csConnector->file;
-			//echo $csGmlRepresentation;
-			//parse relevant information
-			//libxml_use_internal_errors(true);
 			try {
 				$csXml = simplexml_load_string($csGmlRepresentation);
 				if ($csXml === false) {
@@ -182,16 +204,15 @@
 			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 !== "") {
+				//TODO - think about it? 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 - no good idea 
+				/*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();
@@ -200,10 +221,18 @@
 					$this->axisOrder = $axis[1].",".$axis[0];
 				} else {
 					$this->axisOrder = $axis[0].",".$axis[1];
-				}
+				}*/
+				$this->axisOrder = $axis[0].",".$axis[1];
+				$jsonCrsInfo->axisOrder = $this->axisOrder;
 			}
 		}
-		//store information
+		//store information - maybe to cache, if it does not already exists!
+		if ($cache->isActive && $cache->cachedVariableExists(md5($this->identifier)) == false) {
+			$cache->cachedVariableAdd(md5($this->identifier), json_encode($jsonCrsInfo));
+			$e = new mb_notice("http/classes/class_crs.php - store crs info to cache!");
+			return true;
+		}
+		return true;
 	}
 }
 



More information about the Mapbender_commits mailing list