[Mapbender-commits] r8506 - trunk/mapbender/http/php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Nov 12 06:53:38 PST 2012


Author: armin11
Date: 2012-11-12 06:53:37 -0800 (Mon, 12 Nov 2012)
New Revision: 8506

Modified:
   trunk/mapbender/http/php/mod_inspireDownloadFeed.php
Log:
Update handling for urn:... crs which are used in wfs 1.1.0.

Modified: trunk/mapbender/http/php/mod_inspireDownloadFeed.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireDownloadFeed.php	2012-11-08 10:49:52 UTC (rev 8505)
+++ trunk/mapbender/http/php/mod_inspireDownloadFeed.php	2012-11-12 14:53:37 UTC (rev 8506)
@@ -25,7 +25,9 @@
 require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
 require_once(dirname(__FILE__) . "/../classes/class_connector.php");
 require_once(dirname(__FILE__) . "/../classes/class_administration.php");
+require_once dirname(__FILE__) . "/../../core/epsg.php";
 require_once(dirname(__FILE__) . "/../classes/class_Uuid.php");
+//check_epsg_wms_13($tmp_epsg)
 //http://www.weichand.de/inspire/dls/verwaltungsgrenzen.xml
 $con = db_connect(DBSERVER,OWNER,PW);
 db_select_db(DB,$con);
@@ -39,6 +41,7 @@
 
 $maxFeatureCount = 100;
 
+$alterAxisOrder = false;
 //pull the needed things from tables datalink, md_metadata, layer, wms
  
 //parse request parameter
@@ -278,8 +281,24 @@
 	if (!isset($mapbenderMetadata[$m]->metadata_ref_system) || $mapbenderMetadata[$m]->metadata_ref_system == '') {
 		return "<error>For the metadataset with id ".$mapbenderMetadata[$m]->metadata_id." is no reference system defined!</error>";
 	}
-	$epsgId = explode(':',$crs);
-		
+	
+	//Handle CRS
+	//alter all to uppercase 
+	$crsUpper = str_replace("epsg","EPSG",$crs);
+	//Exchange :: with :
+	$crsUpper = str_replace("::",":",$crsUpper);
+	$epsgId = explode('EPSG:',$crsUpper);
+	$epsgId = end($epsgId);
+	//check if order have to be altered
+	if (strpos($crsUpper,'urn') !== false) {
+		//check if axis order should be changed 
+		if (check_epsg_wms_13($epsgId)) {
+			//alter order of axis for 4326
+			$alterAxisOrder = true;
+		} else {
+			$alterAxisOrder = false;	
+		}
+	}
 	//infos about the registrating department, check first if a special metadata point of contact is defined in the service table - function from mod_showMetadata - TODO: should be defined in admin class
 	if (!isset($mapbenderMetadata[$m]->fkey_mb_group_id) or is_null($mapbenderMetadata[$m]->fkey_mb_group_id) or $mapbenderMetadata[$m]->fkey_mb_group_id == 0){
 		$e = new mb_exception("mod_inspireDownloadFeed.php: fkey_mb_group_id not found!");
@@ -516,19 +535,19 @@
 				echo $georssPolygon;*/
 				//TODO: check if epsg, and bbox are filled correctly!
 
-				$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->minx." ".$mapbenderMetadata[$m]->miny.")',4326),".$epsgId[1].")) as minx";
+				$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->minx." ".$mapbenderMetadata[$m]->miny.")',4326),".$epsgId.")) as minx";
 				$resMinx = db_query($sqlMinx);
 				$minx = floatval(db_result($resMinx,0,"minx"));
 			
-				$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->minx." ".$mapbenderMetadata[$m]->miny.")',4326),".$epsgId[1].")) as miny";
+				$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->minx." ".$mapbenderMetadata[$m]->miny.")',4326),".$epsgId.")) as miny";
 				$resMiny = db_query($sqlMiny);
 				$miny = floatval(db_result($resMiny,0,"miny"));
 				
-				$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->maxx." ".$mapbenderMetadata[$m]->maxy.")',4326),".$epsgId[1].")) as maxx";
+				$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->maxx." ".$mapbenderMetadata[$m]->maxy.")',4326),".$epsgId.")) as maxx";
 				$resMaxx = db_query($sqlMaxx);
 				$maxx = floatval(db_result($resMaxx,0,"maxx"));
 				
-				$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->maxx." ".$mapbenderMetadata[$m]->maxy.")',4326),".$epsgId[1].")) as maxy";
+				$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$m]->maxx." ".$mapbenderMetadata[$m]->maxy.")',4326),".$epsgId.")) as maxy";
 				$resMaxy = db_query($sqlMaxy);
 				$maxy = floatval(db_result($resMaxy,0,"maxy"));
 
@@ -576,7 +595,7 @@
 						$maxyWms = $miny + ($j+1) * $incY;
 						//echo "maxyWms: ". $maxyWms .",";
 						$bboxWms[] = $minxWms.",".$minyWms.",".$maxxWms.",".$maxyWms;
-						$bboxWmsWGS84[] = transformBbox($minxWms.",".$minyWms.",".$maxxWms.",".$maxyWms,intval($epsgId[1]),4326);
+						$bboxWmsWGS84[] = transformBbox($minxWms.",".$minyWms.",".$maxxWms.",".$maxyWms,intval($epsgId),4326);
 						
 					}
 				}
@@ -599,9 +618,32 @@
 				//overwrite feature count with information from database
 				$maxFeatureCount = (integer)$mapbenderMetadata[$i]->wfs_max_features;
 				$crs = $mapbenderMetadata[$i]->metadata_ref_system;
-				$e = new mb_notice("Ref system of featuretype ".$mapbenderMetadata[$i]->featuretype_name." : ".$crs);
-				$epsgId = explode(':',$crs);
-				$e = new mb_notice("Epsg id of featuretype ".$mapbenderMetadata[$i]->featuretype_name." : ".$epsgId[1]);
+				//use featuretype ref system?
+				$crs = $mapbenderMetadata[$i]->featuretype_srs;
+				//log ref system of metadata - is this a good idea?
+				$e = new mb_exception("Ref system of featuretype ".$mapbenderMetadata[$i]->featuretype_name." : ".$crs);
+				//
+				//handle other definitions of epsg ids
+				//urn:ogc:def:crs:EPSG::31467
+				//Handle CRS
+				//alter all to uppercase 
+				$crsUpper = str_replace("epsg","EPSG",$crs);
+				//Exchange :: with :
+				$crsUpper = str_replace("::",":",$crsUpper);
+				$epsgId = explode('EPSG:',$crsUpper);
+				$epsgId = end($epsgId);
+				//check if order have to be altered
+				if (strpos($crsUpper,'urn') !== false) {
+					$e = new mb_exception("urn - found");
+					//check if axis order should be changed 
+					if (check_epsg_wms_13($epsgId)) {
+						//alter order of axis for 4326
+						//$alterAxisOrder = true;
+					} else {
+						$alterAxisOrder = false;	
+					}
+				}
+				$e = new mb_notice("Epsg id of featuretype ".$mapbenderMetadata[$i]->featuretype_name." : ".$epsgId);
 				if (!($mapbenderMetadata[$i]->wfs_version) || $mapbenderMetadata[$i]->wfs_version == '' || $mapbenderMetadata[$i]->wfs_version == '1.0.0') {
 				return "<error>Version of WFS : ".$mapbenderMetadata[$i]->wfs_version." is not supported to generate inspire download services for predefined datasets!</error>";
 			}
@@ -633,21 +675,49 @@
 				//minimum number of single tiles:
 				$countTiles = ceil($featureHits[$i]/$maxFeatureCount);
 				//calculate number of rows and columns from x / y ratio
-				$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->minx." ".$mapbenderMetadata[$i]->miny.")',4326),".$epsgId[1].")) as minx";
-				$resMinx = db_query($sqlMinx);
-				$minx = floatval(db_result($resMinx,0,"minx"));
+				if ($epsgId == '4326' && $alterAxisOrder) {
+					//no transformation needed only change order
+					$minx = $mapbenderMetadata[$i]->miny;
+					$miny = $mapbenderMetadata[$i]->minx;
+					$maxx = $mapbenderMetadata[$i]->maxy;
+					$maxy = $mapbenderMetadata[$i]->maxx;
+				} else {
+					//no transformation needed normal order
+					if ($epsgId == '4326') {
+						$minx = $mapbenderMetadata[$i]->minx;
+						$miny = $mapbenderMetadata[$i]->miny;
+						$maxx = $mapbenderMetadata[$i]->maxx;
+						$maxy = $mapbenderMetadata[$i]->maxy;
+					} else {
+						//transformation needed and axis order changed
+						if ($alterAxisOrder) {
+							$e = new mb_exception("axis_order_altered");
+							$minxI = $mapbenderMetadata[$i]->miny;
+							$minyI = $mapbenderMetadata[$i]->minx;
+							$maxxI = $mapbenderMetadata[$i]->maxy;
+							$maxyI = $mapbenderMetadata[$i]->maxx;
+							$mapbenderMetadata[$i]->miny = $minyI;
+							$mapbenderMetadata[$i]->minx = $minxI;
+							$mapbenderMetadata[$i]->maxy = $maxyI;
+							$mapbenderMetadata[$i]->maxx = $maxxI;
+						}
+						$sqlMinx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->minx." ".$mapbenderMetadata[$i]->miny.")',4326),".$epsgId.")) as minx";
+						$resMinx = db_query($sqlMinx);
+						$minx = floatval(db_result($resMinx,0,"minx"));
 				
-				$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->minx." ".$mapbenderMetadata[$i]->miny.")',4326),".$epsgId[1].")) as miny";
-				$resMiny = db_query($sqlMiny);
-				$miny = floatval(db_result($resMiny,0,"miny"));
+						$sqlMiny = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->minx." ".$mapbenderMetadata[$i]->miny.")',4326),".$epsgId.")) as miny";
+						$resMiny = db_query($sqlMiny);
+						$miny = floatval(db_result($resMiny,0,"miny"));
 				
-				$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->maxx." ".$mapbenderMetadata[$i]->maxy.")',4326),".$epsgId[1].")) as maxx";
-				$resMaxx = db_query($sqlMaxx);
-				$maxx = floatval(db_result($resMaxx,0,"maxx"));
+						$sqlMaxx = "SELECT X(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->maxx." ".$mapbenderMetadata[$i]->maxy.")',4326),".$epsgId.")) as maxx";
+						$resMaxx = db_query($sqlMaxx);
+						$maxx = floatval(db_result($resMaxx,0,"maxx"));
 				
-				$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->maxx." ".$mapbenderMetadata[$i]->maxy.")',4326),".$epsgId[1].")) as maxy";
-				$resMaxy = db_query($sqlMaxy);
-				$maxy = floatval(db_result($resMaxy,0,"maxy"));
+						$sqlMaxy = "SELECT Y(transform(GeometryFromText('POINT(".$mapbenderMetadata[$i]->maxx." ".$mapbenderMetadata[$i]->maxy.")',4326),".$epsgId.")) as maxy";
+						$resMaxy = db_query($sqlMaxy);
+						$maxy = floatval(db_result($resMaxy,0,"maxy"));
+					}
+				}		
 				//only calculate new boxes if countTiles > 1
 				if ($countTiles > 1) {
 					$diffX = $maxx - $minx; //in m - depends on given epsg code
@@ -670,7 +740,7 @@
 							//echo "maxyWms: ". $maxyWms .",";
 							$bboxWfs[$mapbenderMetadata[$i]->featuretype_name][$countBbox] = $minxWfs.",".$minyWfs.",".$maxxWfs.",".$maxyWfs;
 							//transform bbox back to geographic coordinates
-							$lonLatBbox = transformBbox($minxWfs.",".$minyWfs.",".$maxxWfs.",".$maxyWfs,intval($epsgId[1]),4326);
+							$lonLatBbox = transformBbox($minxWfs.",".$minyWfs.",".$maxxWfs.",".$maxyWfs,intval($epsgId),4326);
 							$lonLatBbox = explode(',',$lonLatBbox);
 							//georss needs latitude longitude
 							$featureTypeBboxWGS84[] = $lonLatBbox[1].",".$lonLatBbox[0].",".$lonLatBbox[3].",".$lonLatBbox[2];
@@ -682,7 +752,7 @@
 					//only normal extent used
 					$bboxWfs[$mapbenderMetadata[$i]->featuretype_name][0] = $minx.",".$miny.",".$maxx.",".$maxy;
 					//transform bbox back to geographic coordinates
-					$lonLatBbox = transformBbox($minx.",".$miny.",".$maxx.",".$maxy,intval($epsgId[1]),4326);
+					$lonLatBbox = transformBbox($minx.",".$miny.",".$maxx.",".$maxy,intval($epsgId),4326);
 					$lonLatBbox = explode(',',$lonLatBbox);
 					//georss needs latitude longitude
 					$featureTypeBboxWGS84[] = $lonLatBbox[1].",".$lonLatBbox[0].",".$lonLatBbox[3].",".$lonLatBbox[2];		
@@ -846,6 +916,12 @@
 					$furtherLinkType = array();
 					$furtherLinkTitle = array();
 					$furtherLinkBbox = array();
+					if ($numberOfTiles > 1) {
+						$feedEntryContent = $feedDoc->createElement("content");
+						$feedEntryContentText = $feedDoc->createTextNode("Datensatz wird in  in ".$numberOfTiles." einzelnen Teilen ausgeliefert.");
+						$feedEntryContent->appendChild($feedEntryContentText);
+						$feedEntry->appendChild($feedEntryContent);
+					}
 					for ($m = 0; $m < $numberOfTiles; $m++ ) {
 						$furtherLink[$m] = $mapbenderMetadata[$i]->wms_getmap."REQUEST=GetMap&VERSION=".$mapbenderMetadata[$i]->wms_version."&SERVICE=WMS&LAYERS=".$mapbenderMetadata[$i]->layer_name;
 						$furtherLink[$m] .= "&STYLES=&SRS=".trim($crs)."&BBOX=".$bboxWms[$m]."&WIDTH=".$maxImageSize."&HEIGHT=".$maxImageSize."&FORMAT=image/tiff&";
@@ -949,8 +1025,8 @@
 		/*<!-- CRSs in which the pre-defined Dataset is available --> <category term="EPSG:25832" scheme="http://www.opengis.net/def/crs/" label="EPSG/0/25832"/> <category term="EPSG:4258" scheme="http://www.opengis.net/def/crs/" label="EPSG/0/4258"/>*/
 		
 		$feedEntryCategory = $feedDoc->createElement("category");
-		$feedEntryCategory->setAttribute("term", "http://www.opengis.net/def/crs/EPSG/".$epsgId[1]);
-		$feedEntryCategory->setAttribute("label", "EPSG/0/".$epsgId[1]);
+		$feedEntryCategory->setAttribute("term", "http://www.opengis.net/def/crs/EPSG/".$epsgId);
+		$feedEntryCategory->setAttribute("label", "EPSG/0/".$epsgId);
 		$feedEntry->appendChild($feedEntryCategory);
 
 		//<!-- INSPIRE Spatial Object Types contained in the pre-defined dataset -->



More information about the Mapbender_commits mailing list