[Mapbender-commits] r8461 - in trunk/mapbender/http: classes php

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Aug 20 03:35:14 PDT 2012


Author: armin11
Date: 2012-08-20 03:35:12 -0700 (Mon, 20 Aug 2012)
New Revision: 8461

Modified:
   trunk/mapbender/http/classes/class_iso19139.php
   trunk/mapbender/http/classes/class_wms.php
   trunk/mapbender/http/php/mod_inspireDownloadFeed.php
Log:
Bugfix and enhancement in mapbenders metadata management and inspire download service functionality

Modified: trunk/mapbender/http/classes/class_iso19139.php
===================================================================
--- trunk/mapbender/http/classes/class_iso19139.php	2012-08-17 11:01:21 UTC (rev 8460)
+++ trunk/mapbender/http/classes/class_iso19139.php	2012-08-20 10:35:12 UTC (rev 8461)
@@ -164,6 +164,12 @@
 			//spatial_res_type
 			//spatial_res_value
 			//ref_system
+			$this->refSystem = $iso19139Xml->xpath('/gmd:MD_Metadata/gmd:referenceSystemInfo/gmd:MD_ReferenceSystem/gmd:referenceSystemIdentifier/gmd:RS_Identifier/gmd:code/gco:CharacterString');
+			$this->refSystem = $this->refSystem[0];
+			//parse codes to get EPSG:XXXXX TODO use other function to support other codes
+			//get last part of string separated by the colon symbol
+			$this->refSystem = explode(':',$this->refSystem);
+			$this->refSystem = "EPSG:".$this->refSystem[count($this->refSystem)-1];
 			//format
 			//inspire_charset
 			//inspire_top_consistence
@@ -810,7 +816,7 @@
 			$sql .= "linktype = $4, uuid = $5, title = $6, createdate = $7, changedate = $8, lastchanged = now(), ";
 			$sql .= "abstract = $9, searchtext = $10, type = $11, tmp_reference_1 = $12, tmp_reference_2 = $13, export2csw = $14, datasetid = $15, ";
 			$sql .= "datasetid_codespace = $16, randomid = $17, harvestresult = $20, harvestexception = $21, lineage = $22, inspire_top_consistence = $23, ";
-			$sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28 WHERE metadata_id = $19";
+			$sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28, ref_system = $29 WHERE metadata_id = $19";
 
 			$v = array(
 				$this->href,
@@ -841,9 +847,10 @@
 				$this->spatialResValue,
 				$this->updateFrequency,
 				$this->dataFormat,
-				$this->inspireCharset
+				$this->inspireCharset,
+				$this->refSystem
 			);
-			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s');
+			$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s');
 			$res = db_prep_query($sql,$v,$t);
 
 		} else {
@@ -860,7 +867,7 @@
 				$sql .= "linktype = $4, uuid = $5, title = $6, createdate = $7, changedate = $8, lastchanged = now(), ";
 				$sql .= "abstract = $9, searchtext = $10, type = $11, tmp_reference_1 = $12, tmp_reference_2 = $13, export2csw = $14, datasetid = $15, ";
 				$sql .= "datasetid_codespace = $16, randomid = $17, harvestresult = $20, harvestexception = $21, lineage = $22, inspire_top_consistence = $23, ";
-				$sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28 WHERE metadata_id = $19";
+				$sql .= "spatial_res_type = $24, spatial_res_value = $25, update_frequency = $26, format = $27, inspire_charset = $28, ref_system = $29 WHERE metadata_id = $19";
 
 				$v = array(
 					$this->href,
@@ -891,16 +898,17 @@
 					$this->spatialResValue,
 					$this->updateFrequency,
 					$this->dataFormat,
-					$this->inspireCharset
+					$this->inspireCharset,
+					$this->refSystem
 				);
-				$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s');
+				$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s');
 				$res = db_prep_query($sql,$v,$t);
 			} else {
 				//insert new record
 				$e = new mb_exception("class_Iso19139:"."No existing metadata fileIdentifier found in mapbender metadata table. New record will be inserted with uuid: ".$this->fileIdentifier);
 
 				$sql = <<<SQL
-INSERT INTO mb_metadata (lastchanged, link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid, fkey_mb_user_id, harvestresult, harvestexception, lineage, inspire_top_consistence, spatial_res_type, spatial_res_value, update_frequency, format, inspire_charset)  VALUES(now(), $1, $18, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
+INSERT INTO mb_metadata (lastchanged, link, origin, md_format, data, linktype, uuid, title, createdate, changedate, abstract, searchtext, type, tmp_reference_1, tmp_reference_2, export2csw, datasetid, datasetid_codespace, randomid, fkey_mb_user_id, harvestresult, harvestexception, lineage, inspire_top_consistence, spatial_res_type, spatial_res_value, update_frequency, format, inspire_charset)  VALUES(now(), $1, $18, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29)
 SQL;
 				$v = array(
 					$this->href,
@@ -930,10 +938,11 @@
 					$this->spatialResValue,
 					$this->updateFrequency,
 					$this->dataFormat,
-					$this->inspireCharset
+					$this->inspireCharset,
+					$this->refSystem
 				
 				);
-				$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s');
+				$t = array('s','s','s','s','s','s','s','s','s','s','s','s','s','b','s','s','s','s','i','i','s','s','b','s','s','s','s','s','s');
 				$res = db_prep_query($sql,$v,$t);
 			}
 

Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php	2012-08-17 11:01:21 UTC (rev 8460)
+++ trunk/mapbender/http/classes/class_wms.php	2012-08-20 10:35:12 UTC (rev 8461)
@@ -1852,7 +1852,7 @@
 	}
 	function updateLayer($i,$myWMS,$updateMetadataOnly=false){
 		$e = new mb_notice("class_wms.php: updateLayer");
-		$sql = "SELECT layer_id FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
+		$sql = "SELECT layer_id, layer_searchable, inspire_download FROM layer WHERE fkey_wms_id = $1 AND layer_name = $2";
 		$v = array($myWMS,$this->objLayer[$i]->layer_name);
 		$t = array('i','s');
 		$res = db_prep_query($sql,$v,$t);
@@ -1864,21 +1864,35 @@
 			$e = new mb_exception("Not found: ".$this->objLayer[$i]->layer_name);
 			return;	
 		}	
-		
+		//don't update title, abstract when not explicitly demanded thru $this->overwrite == true
+
 		$sql = "UPDATE layer SET ";
 		$sql .= "layer_pos = $1, ";
 		$sql .= "layer_parent = $2, ";
-		$sql .= "layer_title = $3, ";
-		$sql .= "layer_queryable = $4, ";
-		$sql .= "layer_minscale = $5, ";
-		$sql .= "layer_maxscale = $6, ";
-		$sql .= "layer_dataurl = $7, ";
-		$sql .= "layer_metadataurl = $8, ";
-		$sql .= "layer_searchable = $9, ";
-		$sql .= "layer_abstract = $10, ";
-		$sql .= "inspire_download = $12 ";
-		$sql .= "WHERE layer_id = $11";
 		
+		$sql .= "layer_queryable = $3, ";
+		$sql .= "layer_minscale = $4, ";
+		$sql .= "layer_maxscale = $5, ";
+		$sql .= "layer_dataurl = $6, ";
+		$sql .= "layer_metadataurl = $7, ";
+		$sql .= "layer_searchable = $8, ";
+		
+		$sql .= "inspire_download = $10 ";
+		$sql .= "WHERE layer_id = $9";
+
+		if (!$updateMetadataOnly) {
+			//read inspire_download and layer_searchable from database if update from capabilities
+			$this->objLayer[$i]->inspire_download = $row["inspire_download"];
+			$this->objLayer[$i]->layer_searchable = $row["layer_searchable"];
+		}
+		//if inspire_download, and layer_searchable is neither stored in database nor given thru object, set it too a default value 0
+		if (!isset($this->objLayer[$i]->inspire_download) || ($this->objLayer[$i]->inspire_download =='')) {
+			$this->objLayer[$i]->inspire_download = intval('0');
+		}
+		if (!isset($this->objLayer[$i]->layer_searchable) || ($this->objLayer[$i]->layer_searchable =='')) {
+			$this->objLayer[$i]->layer_searchable = intval('0');
+		}
+		
 		if($this->objLayer[$i]->layer_id != null){
 			$tmpPos =  $this->objLayer[$i]->layer_id;
 		}
@@ -1889,16 +1903,17 @@
 			$this->objLayer[$i]->layer_parent = '';
 		}
 		$v = array($tmpPos,$this->objLayer[$i]->layer_parent,
-				$this->objLayer[$i]->layer_title,
+				
 				$this->objLayer[$i]->layer_queryable,$this->objLayer[$i]->layer_minscale,
 				$this->objLayer[$i]->layer_maxscale,$this->objLayer[$i]->layer_dataurl[0]->href,
 				$this->objLayer[$i]->layer_metadataurl[0]->href, $this->objLayer[$i]->layer_searchable,
-				$this->objLayer[$i]->layer_abstract, $l_id, 
+				$l_id, 
 				$this->objLayer[$i]->inspire_download
 			);
-		$t = array('i','s','s','i','i','i','s','s','i', 's','i', 'i');
+		$t = array('i','s','i','i','i','s','s','i', 'i', 'i');
 		$e = new mb_notice("class_wms.php: update layer sql:".$sql);
 		$e = new mb_notice("class_wms.php: layerid: ".$l_id." layersearchable: ".$this->objLayer[$i]->layer_searchable);
+		$e = new mb_notice("class_wms.php: layerid: ".$l_id." inspiredownload: ".$this->objLayer[$i]->inspire_download);
 		$res = db_prep_query($sql,$v,$t);
 		if($this->overwrite == true){
 			$sql = "UPDATE layer SET ";
@@ -1914,14 +1929,12 @@
 			db_rollback();	
 		}
 		else {
-			
 			# save the id of each layer: set param2 true
 			$this->objLayer[$i]->db_id = $l_id;
 			if (!$updateMetadataOnly) {
 				$this->insertLayerEPSG($i);
 			}
 			$this->insertLayerDataUrls($i);
-			
 			$this->insertLayerMetadataUrls($i);
 			# TABLE layer_style for each layer
 			$this->insertLayerStyle($i);
@@ -2468,10 +2481,25 @@
 	}
 
 	function updateObjInDB($myWMS,$updateMetadataOnly=false){ //TODO give return true or false to allow feedback to user!!!
+
+
+		//get some things out from database if not already given thru metadata editor: wms_network_access, wms_max_imagesize, inspire_download (on layer level)
+		//they don't come from the capabilities!
+		if (!$updateMetadataOnly) {
+			//read network_access from database
+			$sql = "SELECT wms_network_access, wms_max_imagesize from wms WHERE wms_id = $1 ";
+			$v = array($myWMS);
+			$t = array('i');
+			$res = db_prep_query($sql,$v,$t);
+			$row = db_fetch_assoc($res);
+			$this->wms_network_access = $row["wms_network_access"];
+			$this->wms_max_imagesize = $row["wms_max_imagesize"];
+			//$e = new mb_exception("class_wms.php: wms_network_access from database: ".$this->wms_network_access);
+		}
+		//if network access is either stored in database nor given thru object, set it too a default value 0
 		if (!isset($this->wms_network_access) || ($this->wms_network_access == '')) {
 			$this->wms_network_access = intval('0');
 		}
-	
 		if ($this->setGeoRss == true) {
 		    $this->geoRssFactory = new GeoRssFactory();
 		    $this->geoRss = $this->geoRssFactory->loadOrCreate(GEO_RSS_FILE);
@@ -2585,7 +2613,7 @@
 		$v = array($myWMS);
 		$t = array('i');
 		$c = 2;
-		$sql = "SELECT layer_id, layer_name, layer_title, layer_abstract FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
+		$sql = "SELECT layer_id, layer_name, layer_title, layer_abstract, inspire_download FROM layer WHERE fkey_wms_id = $1 AND NOT layer_name IN(";
 		for($i=0; $i<count($this->objLayer); $i++){
 			if($i>0){$sql .= ',';}
 			$sql .= "$".$c;
@@ -2602,6 +2630,7 @@
 				"name" => $row["layer_name"],
 				"title" => $row["layer_title"],
 				"abstract" => $row["layer_abstract"]
+				//"inspire_download" => $row["inspire_download"]
 			);
 			
 		}

Modified: trunk/mapbender/http/php/mod_inspireDownloadFeed.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireDownloadFeed.php	2012-08-17 11:01:21 UTC (rev 8460)
+++ trunk/mapbender/http/php/mod_inspireDownloadFeed.php	2012-08-20 10:35:12 UTC (rev 8461)
@@ -173,7 +173,7 @@
 	switch ($generateFrom) {
 		case "dataurl":
 			$sql = <<<SQL
-select *, 'dataurl' as origin from (select * from (select * from (select * from (select mb_metadata.metadata_id, layer_relation.layer_name, layer_relation.fkey_wms_id, layer_relation.layer_id, mb_metadata.uuid as metadata_uuid, mb_metadata.format,mb_metadata.title as metadata_title, mb_metadata.abstract as metadata_abstract, layer_relation.layer_title, layer_relation.layer_abstract, mb_metadata.ref_system as metadata_ref_system, mb_metadata.datasetid, mb_metadata.spatial_res_type, mb_metadata.spatial_res_value, mb_metadata.datasetid_codespace  from (select * from layer inner join ows_relation_metadata on layer.layer_id = ows_relation_metadata.fkey_layer_id) as layer_relation inner join mb_metadata on layer_relation.fkey_metadata_id = mb_metadata.metadata_id where mb_metadata.uuid = $1) as layer_metadata inner join ows_relation_data on ows_relation_data.fkey_layer_id = layer_metadata.layer_id) as layer_relation_data inner join datalink on layer_relation_data.fkey_datalink_id 
 = datalink.datalink_id) as layer_data inner join wms on layer_data.fkey_wms_id = wms.wms_id)  as layer_wms, layer_epsg where layer_wms.layer_id = layer_epsg.fkey_layer_id and layer_epsg.epsg = 'EPSG:4326';  
+select *, 'dataurl' as origin from (select * from (select * from (select * from (select mb_metadata.metadata_id, layer_relation.layer_name,layer_relation.inspire_download, layer_relation.fkey_wms_id, layer_relation.layer_id, mb_metadata.uuid as metadata_uuid, mb_metadata.format,mb_metadata.title as metadata_title, mb_metadata.abstract as metadata_abstract, layer_relation.layer_title, layer_relation.layer_abstract, mb_metadata.ref_system as metadata_ref_system, mb_metadata.datasetid, mb_metadata.spatial_res_type, mb_metadata.spatial_res_value, mb_metadata.datasetid_codespace  from (select * from layer inner join ows_relation_metadata on layer.layer_id = ows_relation_metadata.fkey_layer_id) as layer_relation inner join mb_metadata on layer_relation.fkey_metadata_id = mb_metadata.metadata_id where mb_metadata.uuid = $1) as layer_metadata inner join ows_relation_data on ows_relation_data.fkey_layer_id = layer_metadata.layer_id) as layer_relation_data inner join datalink on layer
 _relation_data.fkey_datalink_id = datalink.datalink_id) as layer_data inner join wms on layer_data.fkey_wms_id = wms.wms_id)  as layer_wms, layer_epsg where layer_wms.layer_id = layer_epsg.fkey_layer_id and layer_epsg.epsg = 'EPSG:4326';  
 SQL;
 		$generateFromDataurl = true;
 		break;
@@ -215,6 +215,7 @@
 			$v = array($recordId);
 			$t = array('s');
 			$res = db_prep_query($sql,$v,$t);
+			//$e = new mb_exception("mod_inspireDownloadFeed: Fill mapbender metadata");
 			fillMapbenderMetadata($res, $generateFrom);
 		break;
 		case "wmslayer":
@@ -245,6 +246,10 @@
 	$countRessource = count($mapbenderMetadata); //count of coupled featuretypes, layers or dataurls or both!
 	//echo "<error>".count($mapbenderMetadata)."</error>";
 	//die();
+	//$e = new mb_exception("mod_inspireDownloadFeed: uuid ".$recordId);
+	//$e = new mb_exception("mod_inspireDownloadFeed: datalink_id ".$mapbenderMetadata[0]->datalink_id);
+	//$e = new mb_exception("mod_inspireDownloadFeed: sql ".$sql);
+
 	if ($generateFrom != "wfs") {
 		$countRessource = 1;
 	}
@@ -545,11 +550,11 @@
 						
 					break;
 				}
-				$e = new mb_exception($diffXPx.":".$diffYPx);
+				$e = new mb_notice($diffXPx.":".$diffYPx);
 				
 				$nRows = ceil($diffYPx / floatval($maxImageSize));
 				$nCols = ceil($diffXPx / floatval($maxImageSize));
-				$e = new mb_exception($nRows.":".$nCols);
+				$e = new mb_notice($nRows.":".$nCols);
 				$bboxWms = array();
 				$bboxWmsWGS84 = array();
 				/*echo $diffXPx.":".$diffYPx.",";
@@ -607,10 +612,10 @@
 				$startRequestTime = time();
 				$hitConnector = new connector($gHLink);
 				$hitXml = $hitConnector->file;
-				$e = new mb_exception($gHLink);
+				$e = new mb_notice($gHLink);
 				$endRequestTime = time();
 				$diffTime = $endRequestTime-$startRequestTime;
-				$e = new mb_exception("Time for counting objects of featuretype ".$mapbenderMetadata[$i]->featuretype_name." : ".$diffTime." seconds!");
+				$e = new mb_notice("Time for counting objects of featuretype ".$mapbenderMetadata[$i]->featuretype_name." : ".$diffTime." seconds!");
 				//$e = new mb_exception($hitXml);
 				//parse hits
 				try {
@@ -624,7 +629,7 @@
 				}
 				$hits = $featureTypeHits->xpath('/wfs:FeatureCollection/@numberOfFeatures');
 				$featureHits[$i] = (integer)$hits[0];
-				$e = new mb_exception($featureHits[$i]." hits for featuretype ".$mapbenderMetadata[$i]->featuretype_name);
+				$e = new mb_notice($featureHits[$i]." hits for featuretype ".$mapbenderMetadata[$i]->featuretype_name);
 				//$e = new mb_exception($featureHits[$i]);
 
 				//calculate further bboxes if the # of hits extents some value
@@ -659,7 +664,7 @@
 				$e = new mb_notice($diffY);
 			
 				$width = ceil(sqrt(($diffX * $diffY) / $countTiles));
-$e = new mb_exception($width);
+				$e = new mb_notice($width);
 				$nRows = ceil($diffY / $width);
 				$nCols = ceil($diffX / $width);
 
@@ -712,7 +717,7 @@
 					$bboxFilter .= '<gml:coordinates>';
 					$currentBbox = explode(',',$bboxWfs[$mapbenderMetadata[$i]->featuretype_name][$l]);
 					
-					$e = new mb_exception("Bounding box ".$l." : ".$l.$bboxWfs[$mapbenderMetadata[$i]->featuretype_name][$l]);
+					$e = new mb_notice("Bounding box ".$l." : ".$l.$bboxWfs[$mapbenderMetadata[$i]->featuretype_name][$l]);
 					$bboxFilter .= $currentBbox[0].','.$currentBbox[1].' '.$currentBbox[2].','.$currentBbox[3];
 					$bboxFilter .= '</gml:coordinates></gml:Box></BBOX></Filter>';
 					$bboxFilter = urlencode($bboxFilter);
@@ -734,7 +739,7 @@
 			$numberOfEntries = count($mapbenderMetadata);
 		}
 	}
-	$e = new mb_exception("Count of bboxes: ".$numberOfEntries);
+	$e = new mb_notice("Count of bboxes: ".$numberOfEntries);
 	for ($i = 0; $i < $numberOfEntries; $i++) {
 		//<entry> 5.1.12 / 5.2.3
 		$feedEntry = $feedDoc->createElement("entry");
@@ -834,6 +839,15 @@
 					$furtherLink = $datasetLink;
 					$furtherLinkType = $mapbenderMetadata[$i]->datalink_format;
 					$furtherLinkTitle = $ressourceTitle." im CRS ".$mapbenderMetadata[$i]->metadata_ref_system."(".$mapbenderMetadata[$m]->format.")";
+					//generate content link 
+					$feedEntryLink = $feedDoc->createElement("link");
+					$feedEntryLink->setAttribute("rel", "section");
+					$feedEntryLink->setAttribute("href", $furtherLink);
+					$feedEntryLink->setAttribute("type", $furtherLinkType);
+					$feedEntryLink->setAttribute("hreflang", "de");
+					$feedEntryLink->setAttribute("title", $furtherLinkTitle);
+					//$feedEntryLink->setAttribute("bbox", $newBox);
+					$feedEntry->appendChild($feedEntryLink);	
 				break;
 				case "wmslayer":
 					//example:
@@ -875,7 +889,7 @@
 					$furtherLinkTitle = array();
 					$furtherLinkBbox = array();
 					//loop for each featuretype
-					$e = new mb_exception("Count of wfs links: ".count($getFeatureLink));
+					$e = new mb_notice("Count of wfs links: ".count($getFeatureLink));
 					for ($m = 0; $m < count($getFeatureLink); $m++ ) {
 						$furtherLink[$m] = $getFeatureLink[$m];//was computed before
 						$furtherLinkType[$m] = "text/xml; subtype=gml/3.1.1";//TODO: set right format for wfs version!
@@ -933,9 +947,9 @@
 		//<georss:polygon>47.202 5.755 55.183 5.755 55.183 15.253 47.202 15.253 47.202 5.755</georss:polygon>
 		//TODO: Get this out of mb_metadata! If not given get it from layer bbox - but normally they should be identical!
 		$feedEntryBbox = $feedDoc->createElement("georss:polygon");
-		$e = new mb_exception('mapbender minx: '.$mapbenderMetadata[$i]->minx);
-		$e = new mb_exception('mapbender i: '.$i);
-		$e = new mb_exception('mapbender origin: '.$mapbenderMetadata[$i]->origin);
+		$e = new mb_notice('mapbender minx: '.$mapbenderMetadata[$i]->minx);
+		$e = new mb_notice('mapbender i: '.$i);
+		$e = new mb_notice('mapbender origin: '.$mapbenderMetadata[$i]->origin);
 		$georssPolygon = $mapbenderMetadata[$i]->miny." ".$mapbenderMetadata[$i]->minx." ".$mapbenderMetadata[$i]->maxy." ".$mapbenderMetadata[$i]->minx." ";
 		$georssPolygon .= $mapbenderMetadata[$i]->maxy." ".$mapbenderMetadata[$i]->maxx." ".$mapbenderMetadata[$i]->miny." ".$mapbenderMetadata[$i]->maxx." ";
 		$georssPolygon .= $mapbenderMetadata[$i]->miny." ".$mapbenderMetadata[$i]->minx;	



More information about the Mapbender_commits mailing list