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

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Tue Jan 26 07:35:00 PST 2016


Author: armin11
Date: 2016-01-26 07:35:00 -0800 (Tue, 26 Jan 2016)
New Revision: 9388

Modified:
   trunk/mapbender/http/php/mod_inspireDownloadFeed.php
Log:
Enhancement of ATOM Feed generator to serve different output_formats for wfs based  feeds

Modified: trunk/mapbender/http/php/mod_inspireDownloadFeed.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireDownloadFeed.php	2016-01-26 15:25:15 UTC (rev 9387)
+++ trunk/mapbender/http/php/mod_inspireDownloadFeed.php	2016-01-26 15:35:00 UTC (rev 9388)
@@ -1307,8 +1307,8 @@
 
 					$bboxFilter = '<Filter xmlns:gml="http://www.opengis.net/gml"><BBOX>';
 					//$bboxFilter .= '<gml:Box srsName="EPSG:'.$epsgId[1].'"';
-					$bboxFilter .= '<ogc:PropertyName>the_geom</ogc:PropertyName>';//TODO parse DescribeFeatureType for geom property
-					
+					//$bboxFilter .= '<ogc:PropertyName>the_geom</ogc:PropertyName>';//TODO parse DescribeFeatureType for geom property
+					$bboxFilter .= '<ogc:PropertyName>'.$mapbenderMetadata[$i]->geometry_field_name[0].'</ogc:PropertyName>';
 					$bboxFilter .= '<gml:Box>';
 					$bboxFilter .= '<gml:coordinates>';
 					$currentBbox = explode(',',$bboxWfs[$mapbenderMetadata[$i]->featuretype_name][$l]);
@@ -1321,6 +1321,10 @@
 					$gFLink = $mapbenderMetadata[$i]->wfs_getfeature."SERVICE=WFS&REQUEST=GetFeature&VERSION=";
 					$gFLink .= $mapbenderMetadata[$i]->wfs_version."&typeName=".$mapbenderMetadata[$i]->featuretype_name;
 					$gFLink .= "&maxFeatures=".$featureHits[$i]."&srsName=".$mapbenderMetadata[$i]->featuretype_srs;
+					if (count($mapbenderMetadata[$i]->output_formats) >= 1) {
+						//use first output format which have been found - TODO - check if it should be pulled from featuretype instead from wfs 
+						$gFLink .= "&outputFormat=".urlencode($mapbenderMetadata[$i]->output_formats[0]);
+					}
 					$gFLink .= "&FILTER=".$bboxFilter;
 					$getFeatureLink[] = $gFLink;
 					$featureTypeName[] = $mapbenderMetadata[$i]->featuretype_name;
@@ -1374,7 +1378,9 @@
 				break;
 				case "wfs":
 					$ressourceDataFeedEntryTitle = $ressourceTitle." - generiert über WFS GetFeature Aufrufe";
-					$resourceFormat = "application/gml+xml";
+					//$resourceFormat = "application/gml+xml";
+					//first format from wfs server
+					$resourceFormat = $mapbenderMetadata[$i]->output_formats[0];
 				break;
 				case "metadata":
 					$ressourceDataFeedEntryTitle = $ressourceTitle." - generiert über Downloadlinks aus Metadatensatz";
@@ -1523,6 +1529,8 @@
 				case "wfs":
 					//example:
 					//http://localhost/cgi-bin/mapserv?map=/data/umn/geoportal/karte_rp/testinspiredownload.map&VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&LAYERS=inspirewms&STYLES=&SRS=EPSG:4326&BBOX=6.92134,50.130465,6.93241,50.141535000000005&WIDTH=200&HEIGHT=200&FORMAT=image/png&BGCOLOR=0xffffff&TRANSPARENT=TRUE&EXCEPTIONS=application/vnd.ogc.se_inimage
+					//for each possibly format do following
+					//foreach ($mapbenderMetadata[$i]->output_formats as $output_format) {
 					$furtherLink = array();
 					$furtherLinkType = array();
 					$furtherLinkTitle = array();
@@ -1532,16 +1540,19 @@
 					if (count($getFeatureLink) > 1) {
 						$feedEntryContent = $feedDoc->createElement("content");
 						$feedEntryContentText = $feedDoc->createTextNode("Datensatz wird in  in ".count($getFeatureLink)." einzelnen Teilen ausgeliefert.");
+						//TODO exchange text for output_format!
 						$feedEntryContent->appendChild($feedEntryContentText);
 						$feedEntry->appendChild($feedEntryContent);
 					}
 					for ($m = 0; $m < count($getFeatureLink); $m++ ) {
+						//TODO exchange text for output_format!
 						$furtherLink[$m] = $getFeatureLink[$m];//was computed before
 						//discard filter if only one request is needed - problem with epsg codes? TODO solve problem
 						if (count($getFeatureLink) == 1) {
 							$splittedLink = explode('&FILTER=',$furtherLink[$m]);
 							$furtherLink[$m] = $splittedLink[0];
 						}
+						//TODO exchange text for output_format - maybe match them before?
 						$furtherLinkType[$m] = "application/gml+xml";//inspire media type registry http://inspire.ec.europa.eu/media-types/
 						$currentIndex = $m+1;
 						$furtherLinkTitle[$m] = $ressourceTitle." im CRS ".$mapbenderMetadata[$i]->metadata_ref_system." - ".$resourceFormat." - Teil ".$currentIndex." von ".count($getFeatureLink)."";//TODO: set right format for wfs version!
@@ -1559,9 +1570,10 @@
 						$feedEntryLink->setAttribute("hreflang", "de");
 						$feedEntryLink->setAttribute("title", $furtherLinkTitle[$m]);
 						$feedEntryLink->setAttribute("bbox", str_replace(","," ",$furtherLinkBbox[$m]));
-						$feedEntry->appendChild($feedEntryLink);	
-					}
-				break;
+						$feedEntry->appendChild($feedEntryLink);
+					}	
+					//} end of foreach output_format
+				break;//end for service type wfs
 			}
 		}
 		//In the case of dynamically build entries for a raster based wms - not the dataurl but another the dyn ulrs will be used in the next feed
@@ -1648,6 +1660,19 @@
 		$feedEntry->appendChild($feedEntryCategory);*/
 	//</entry>
 		$feed->appendChild($feedEntry);
+		//duplicate feed entry for other formats if one is given
+		if ($type == 'DATASET' && $generateFrom == 'wfs' && count($mapbenderMetadata[$i]->output_formats) > 1) {
+			for ($j=1; $j < count($mapbenderMetadata[$i]->output_formats-1); $j++) {
+				$feedEntryCopy = $feedEntry;
+				$feedEntryCopyXml = $feedDoc->saveXML($feedEntry);
+				//exchange formats
+				$feedEntryCopyXml = str_replace($mapbenderMetadata[$i]->output_formats[0],$mapbenderMetadata[$i]->output_formats[$j],$feedEntryCopyXml);
+				$feedEntryCopyXml = str_replace(urlencode($mapbenderMetadata[$i]->output_formats[0]),$mapbenderMetadata[$i]->output_formats[$j],$feedEntryCopyXml);
+				$feedEntryCopyXmlDOM = $feedDoc->createDocumentFragment();
+				$feedEntryCopyXmlDOM->appendXML($feedEntryCopyXml);
+				$feed->appendChild($feedEntryCopyXmlDOM);
+			}
+		}
 	}
 	//}
 	//store feed to variable:
@@ -1815,6 +1840,7 @@
 				$mapbenderMetadata[$indexMapbenderMetadata]->featuretype_name = $row['featuretype_name'];
 				$mapbenderMetadata[$indexMapbenderMetadata]->featuretype_srs = $row['featuretype_srs'];
 				$mapbenderMetadata[$indexMapbenderMetadata]->featuretype_title = $row['featuretype_title'];
+				$mapbenderMetadata[$indexMapbenderMetadata]->featuretype_id = $row['featuretype_id'];
 				$mapbenderMetadata[$indexMapbenderMetadata]->wfs_title = $row['wfs_title'];
 				$mapbenderMetadata[$indexMapbenderMetadata]->wfs_id = $row['wfs_id'];
 				$mapbenderMetadata[$indexMapbenderMetadata]->wfs_abstract = $row['wfs_abstract'];
@@ -1840,6 +1866,38 @@
 					$mapbenderMetadata[$indexMapbenderMetadata]->miny = $latlonbbox[1];
 					$mapbenderMetadata[$indexMapbenderMetadata]->maxx = $latlonbbox[2];
 					$mapbenderMetadata[$indexMapbenderMetadata]->maxy = $latlonbbox[3];
+					//do a special select to get all outputformats from database
+					$mapbenderMetadata[$indexMapbenderMetadata]->output_formats = array();
+					//$e = new mb_exception("php/mod_inspireDownloadFeed.php: owfsId: ".$mapbenderMetadata[$indexMapbenderMetadata]->wfs_id);
+					$sql = "SELECT output_format from wfs_output_formats WHERE fkey_wfs_id = $1";			
+					$v = array($mapbenderMetadata[$indexMapbenderMetadata]->wfs_id);
+					$t = array('i');
+					$res = db_prep_query($sql,$v,$t);
+					while ($row = db_fetch_array($res)) {
+						$mapbenderMetadata[$indexMapbenderMetadata]->output_formats[] = $row['output_format'];
+						//$e = new mb_exception("php/mod_inspireDownloadFeed.php: output_format for wfs: ".$row['output_format']);
+					}
+					if (count($mapbenderMetadata[$indexMapbenderMetadata]->output_formats) < 1) {
+						//set default output format to gml2 TODO - check if senseful
+						$mapbenderMetadata[$indexMapbenderMetadata]->output_formats = "text/xml; subtype=gml/2.1.2";
+					}
+					//get geometry field name from featuretype information out of mapbender database
+					$sql = "SELECT element_name, element_type from wfs_element WHERE fkey_featuretype_id = $1";			
+					$v = array($mapbenderMetadata[$indexMapbenderMetadata]->featuretype_id);
+					$t = array('i');
+					$res = db_prep_query($sql,$v,$t);
+					//pull first element with type is string like "PropertyType"
+					while ($row = db_fetch_array($res)) {
+						//$e = new mb_notice("php/mod_inspireDownloadFeed.php: test element_type: ".$row['element_type']);
+						if (strpos($row['element_type'], "PropertyType") !== false) {
+							$mapbenderMetadata[$indexMapbenderMetadata]->geometry_field_name[] = $row['element_name'];
+							$e = new mb_notice("php/mod_inspireDownloadFeed.php: element_name of geometry field (type name like PropertyName) found: ".$row['element_name']);
+							break;
+						} else {
+							//set default value
+							$mapbenderMetadata[$indexMapbenderMetadata]->geometry_field_name[] = "the_geom";
+						}
+					}
 				}
 				//overwrite mapbenderMetadata->minx ... which came from layer/featuretype metadata with bbox of metadata itself, if given
 				if (isset($mapbenderMetadata[$indexMapbenderMetadata]->metadata_bbox) && $mapbenderMetadata[$indexMapbenderMetadata]->metadata_bbox !== "") {



More information about the Mapbender_commits mailing list