[Mapbender-commits] r8699 - in trunk/mapbender: conf http/php http/plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue Sep 3 06:25:20 PDT 2013
Author: armin11
Date: 2013-09-03 06:25:18 -0700 (Tue, 03 Sep 2013)
New Revision: 8699
Added:
trunk/mapbender/conf/mimetype.conf
Modified:
trunk/mapbender/http/php/mod_inspireDownloadFeed.php
trunk/mapbender/http/plugins/mb_metadata_addon.php
Log:
New possibility to fully support INSPIRE Downloadservices with the OpenSearch interface (GetSpatialDataset/DescribeSpatialDataset operations).
Added: trunk/mapbender/conf/mimetype.conf
===================================================================
--- trunk/mapbender/conf/mimetype.conf (rev 0)
+++ trunk/mapbender/conf/mimetype.conf 2013-09-03 13:25:18 UTC (rev 8699)
@@ -0,0 +1,26 @@
+<?php
+//Mapping hashtable mediatypes and file formats of corresponding metadata (iso19139) - in mb_metadata table
+//http://inspire.ec.europa.eu/media-types/
+$formatsMimetype = array(
+ "Esri Shape" => "application/x-shapefile",
+ "Esri File Geodatabase" => "application/x-filegdb",
+ "GeoTIFF" => "image/tiff" ,
+ "GML" => "application/gml+xml",
+ "Zipped GML" => "application/x-gmz",
+ "KML" => "application/vnd.google-earth.kml+xml",
+ "KMZ" => "application/vnd.google-earth.kmz",
+ "JPEG 2000" => "image/jp2",
+ "MapInfo Tab file" => "application/x-tab",
+ "MapInfo Tab raster file" => "application/x-tab-raster",
+ "CSV" => "text/csv",
+ "Database" => "text/sql"
+);
+$formats = array(
+ "Database",
+ "Esri Shape",
+ "MapInfo Tab file",
+ "CSV",
+ "GML",
+ "GeoTIFF"
+);
+?>
Modified: trunk/mapbender/http/php/mod_inspireDownloadFeed.php
===================================================================
--- trunk/mapbender/http/php/mod_inspireDownloadFeed.php 2013-08-29 14:57:08 UTC (rev 8698)
+++ trunk/mapbender/http/php/mod_inspireDownloadFeed.php 2013-09-03 13:25:18 UTC (rev 8699)
@@ -1,6 +1,6 @@
<?php
//2012-06-15-http://localhost/mapbender/php/mod_inspireDownloadFeed.php?id=70e0c3e5-707c-f8e1-8037-7b38702176d9&type=SERVICE&generatefrom=all
-
+//example: 2013-09-03 http://www.geoportal.rlp.de/mapbender/php/mod_inspireDownloadFeed.php?id=e9d22d13-e045-f0e0-25cc-1f146d681216&type=DATASET&generateFrom=wfs&wfsid=216&OPENSEARCH=true&spatial_dataset_identifier_code=e9d22d13-e045-f0e0-25cc-1f146d681216&spatial_dataset_identifier_namespace=http%3A%2F%2Fwww.geoportal.rlp.de&crs=EPSG:25832&language=de
//20648
// $Id: mod_inspireDownloadFeed.php 235
// http://www.mapbender.org/index.php/
@@ -27,6 +27,8 @@
require_once(dirname(__FILE__) . "/../classes/class_administration.php");
require_once dirname(__FILE__) . "/../../core/epsg.php";
require_once(dirname(__FILE__) . "/../classes/class_Uuid.php");
+require_once(dirname(__FILE__) . "/../../conf/mimetype.conf");
+
//check_epsg_wms_13($tmp_epsg)
//http://www.weichand.de/inspire/dls/verwaltungsgrenzen.xml
$con = db_connect(DBSERVER,OWNER,PW);
@@ -42,6 +44,11 @@
$maxFeatureCount = 100;
$alterAxisOrder = false;
+
+$numberOfTiles = 0;
+
+$furtherLink = array();
+
//pull the needed things from tables datalink, md_metadata, layer, wms
//parse request parameter
@@ -150,6 +157,68 @@
$testMatch = NULL;
}
+//parse opensearch parameters - used if $openSearch=true
+//q, spatial_dataset_identifier_namespace, spatial_dataset_identifier_code, crs, language
+if (isset($_REQUEST['q']) & $_REQUEST['q'] != "") {
+ //validate type
+ $testMatch = $_REQUEST["q"];
+ /*if ($testMatch != 'wmslayer' && $testMatch != 'dataurl' && $testMatch != 'wfs' && $testMatch != 'all'){
+ //echo 'GENERATEFROM: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>GENERATEFROM</b> is not valid (wmslayer,dataurl,wfs,all).<br/>';
+ die();
+ }*/
+ $osQuery = $testMatch;
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST['spatial_dataset_identifier_namespace']) & $_REQUEST['spatial_dataset_identifier_namespace'] != "") {
+ //validate type
+ $testMatch = $_REQUEST["spatial_dataset_identifier_namespace"];
+ /*if ($testMatch != 'wmslayer' && $testMatch != 'dataurl' && $testMatch != 'wfs' && $testMatch != 'all'){
+ //echo 'GENERATEFROM: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>GENERATEFROM</b> is not valid (wmslayer,dataurl,wfs,all).<br/>';
+ die();
+ }*/
+ $osDatasetNamespace = $testMatch;
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST['spatial_dataset_identifier_code']) & $_REQUEST['spatial_dataset_identifier_code'] != "") {
+ //validate type
+ $testMatch = $_REQUEST["spatial_dataset_identifier_code"];
+ /*if ($testMatch != 'wmslayer' && $testMatch != 'dataurl' && $testMatch != 'wfs' && $testMatch != 'all'){
+ //echo 'GENERATEFROM: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>GENERATEFROM</b> is not valid (wmslayer,dataurl,wfs,all).<br/>';
+ die();
+ }*/
+ $osDatasetIdentifier = $testMatch;
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST['crs']) & $_REQUEST['crs'] != "") {
+ //validate type TODO
+ $testMatch = $_REQUEST["crs"];
+ /*if ($testMatch != 'wmslayer' && $testMatch != 'dataurl' && $testMatch != 'wfs' && $testMatch != 'all'){
+ //echo 'GENERATEFROM: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>GENERATEFROM</b> is not valid (wmslayer,dataurl,wfs,all).<br/>';
+ die();
+ }*/
+ $osCrs = $testMatch;
+ $testMatch = NULL;
+}
+
+if (isset($_REQUEST['language']) & $_REQUEST['language'] != "") {
+ //validate type TODO
+ $testMatch = $_REQUEST["language"];
+ /*if ($testMatch != 'wmslayer' && $testMatch != 'dataurl' && $testMatch != 'wfs' && $testMatch != 'all'){
+ //echo 'GENERATEFROM: <b>'.$testMatch.'</b> is not valid.<br/>';
+ echo 'Parameter <b>GENERATEFROM</b> is not valid (wmslayer,dataurl,wfs,all).<br/>';
+ die();
+ }*/
+ $osLanguage = $testMatch;
+ $testMatch = NULL;
+}
+
if ($generateFrom == "wmslayer") {
//check if layerId is set too
if (isset($_REQUEST['LAYERID']) & $_REQUEST['LAYERID'] != "") {
@@ -192,8 +261,171 @@
$feedDoc->preserveWhiteSpace = false;
$feedDoc->formatOutput = true;
+
+/*function addToQuery($paramName,$queryString,$string,$queryList) {
+ //test if string was part of query before, if so, don't extent the query
+ //TODO: the strings come from json and so they are urlencoded! maybe we have to decode them to find the commata
+ $queryListComma = urldecode($queryList);
+ $queryListC = ",".$queryListComma.",";
+ $pattern = ','.$string.',';
+ if (!preg_match($pattern, $queryListC)){
+ //append the new element
+ $queryListNew = $queryListC.$string;
+ //echo "query string new: ".$queryListNew."<br>";
+ //delete the commatas
+ $queryListNew = ltrim($queryListNew,',');
+ //generate the new query string
+ $queryStringNew = str_replace($paramName.'='.$queryList,$paramName.'='.$queryListNew,$queryString);
+ return $queryStringNew;
+ } else {
+ return $queryString;
+ }
+}*/
+
+// function to delete one GET parameter totally from a query url
+function delTotalFromQuery($paramName,$queryString) {
+ $queryString = "&".$queryString;
+ $queryStringNew = preg_replace('/\b'.$paramName.'\=[^&]+&?/',$str2exchange,$queryString);
+ $queryStringNew = ltrim($queryStringNew,'&');
+ $queryStringNew = rtrim($queryStringNew,'&');
+ return $queryStringNew;
+}
+
+
+function answerOpenSearchRequest () {
+ global $admin, $type, $mapbenderMetadata, $indexMapbenderMetadata, $layerId, $wfsId, $mapbenderPath, $epsgId, $alterAxisOrder, $departmentMetadata, $userMetadata, $hasPermission, $m, $crs, $crsUpper, $countRessource, $furtherLink, $osDatasetIdentifier, $osQuery, $osDatasetNamespace, $osCrs, $osLanguage;
+ //service feed url
+ $serviceFeed = delTotalFromQuery("getopensearch",$mapbenderPath."..".$_SERVER['REQUEST_URI']);//delete GETOPENSEARCH
+ $serviceFeed = delTotalFromQuery("OPENSEARCH",$serviceFeed);
+ //echo $serviceFeed;
+ //die();
+ //datasetfeed url
+ $datasetFeed = str_replace("=SERVICE&","=DATASET&",$serviceFeed);
+ //echo $datasetFeed;
+ //die();
+ $returnFile = false;
+ switch ($generateFrom) {
+ case "dataurl":
+ $mimetype = $formatsMimetype[$mapbenderMetadata[$m]->format];
+ break;
+ case "wmslayer":
+ $mimetype = "image/tiff";
+ break;
+ case "wfs":
+ $mimetype = "application/gml+xml";
+ break;
+ }
+ //check correct headers
+ foreach (apache_request_headers() as $name => $value) {
+ if ($name == "Accept" && $value == $mimetype) {
+ $returnFile = true;
+ }
+ }
+ //TODO comment this line in productive environment - see inspire guidance for opensearch script
+ $returnFile = true;
+ //check for identifier
+ /*$e = new mb_exception("mod_inspireDownloadFeed.php: osDatasetIdentifier: ".$osDatasetIdentifier);
+ $e = new mb_exception("mod_inspireDownloadFeed.php: osQuery: ".$osQuery);
+ $e = new mb_exception("mod_inspireDownloadFeed.php: osDatasetNamespace: ".$osDatasetNamespace);
+ $e = new mb_exception("mod_inspireDownloadFeed.php: numberOfTiles: ".$numberOfTiles);*/
+ if (!$osDatasetIdentifier) {
+ if (!$osQuery) {
+ //redirect to service feed
+ header("Location: ".$serviceFeed);
+ die();
+ }
+ //the query search for an identifier ?
+ $osDatasetIdentifier = $osQuery;
+ }
+
+ //check namespace
+ if (!$osDatasetNamespace) {
+ echo "No namespace given!";
+ die();
+ }
+ //check crs and language
+ if ($osCrs && $osCrs != $crs) {
+ echo "Dataset not available in requested crs!";
+ die();
+ }
+ if (!$osLanguage || $osLanguage == "*") {
+ $osLanguage = "de";
+ }
+ if ($osLanguage != "de") {
+ echo "Dataset not available in requested language!";
+ die();
+ }
+ //check count of links
+ //redirect to downloadlink
+ //parse dataset atom feed and count links - maybe one or multiple!!!!
+ $links = getDatasetFeedLinks($datasetFeed);
+ $numberOfTiles = count($links);
+ //$e = new mb_exception("mod_inspireDownloadFeed.php: numberOfTiles: ".$numberOfTiles);
+ if ($numberOfTiles > 1) {
+ //redirect to dataset atom feed
+ header("Location: ".$datasetFeed);
+ } else {
+ if ($returnFile) {
+ //echo "links[0]:". $links[0];
+ //die();
+ header("Location: ".$links[0]);
+ } else {
+ //redirect to datasetfeed
+ header("Location: ".$datasetFeed);
+ }
+ }
+ die();
+}
+
+function getDatasetFeedLinks($datasetFeedUrl) {
+ //$links = array();
+ //get feed from remote server
+ $feedConnector = new connector($datasetFeedUrl);
+ $feedConnector->set("timeOut", "10");
+ $feedFile = $feedConnector->file;
+ libxml_use_internal_errors(true);
+ try {
+ $feedXML = simplexml_load_string($feedFile);
+ if ($feedXML === false) {
+ foreach(libxml_get_errors() as $error) {
+ $err = new mb_exception("mod_inspireDownloadFeed.php:".$error->message);
+ }
+ throw new Exception("mod_inspireDownloadFeed.php:".'Cannot parse Feed!');
+ return false;
+ }
+ }
+ catch (Exception $e) {
+ $err = new mb_exception("mod_inspireDownloadFeed.php:".$e->getMessage());
+ return false;
+ }
+ if ($feedXML != false) {
+ $feedXML->registerXPathNamespace("georss", "http://www.georss.org/georss");
+ $feedXML->registerXPathNamespace("inspire_dls", "http://inspire.ec.europa.eu/schemas/inspire_dls/1.0");
+ $feedXML->registerXPathNamespace("defaultns", "http://www.w3.org/2005/Atom");
+ $title = $feedXML->xpath('/defaultns:feed/defaultns:entry/defaultns:title');
+ //TODO: This is only possible, if one entry is available as it is now. Maybe altered later.
+ $title = $title[0];
+ //for ($i=0; $i<=(count($title)-1); $i++) {
+ $links = $feedXML->xpath('/defaultns:feed/defaultns:entry[1]/defaultns:link/@href');
+ //}
+ }
+ return $links;
+}
+
+
function generateOpenSearchDescription($feedDoc, $recordId, $generateFrom) {
- global $admin, $type, $mapbenderMetadata, $indexMapbenderMetadata, $layerId, $wfsId, $mapbenderPath, $epsgId, $alterAxisOrder, $departmentMetadata, $userMetadata, $hasPermission, $m, $crs, $crsUpper, $countRessource;
+ global $admin, $type, $mapbenderMetadata, $indexMapbenderMetadata, $layerId, $wfsId, $mapbenderPath, $epsgId, $alterAxisOrder, $departmentMetadata, $userMetadata, $hasPermission, $m, $crs, $crsUpper, $countRessource, $numberOfTiles;
+ switch ($generateFrom) {
+ case "dataurl":
+ $mimetype = $formatsMimetype[$mapbenderMetadata[$m]->format];
+ break;
+ case "wmslayer":
+ $mimetype = "image/tiff";
+ break;
+ case "wfs":
+ $mimetype = "application/gml+xml";
+ break;
+ }
//part which generates the feed
$feed = $feedDoc->createElementNS('http://a9.com/-/spec/opensearch/1.1/', 'OpenSearchDescription');
$feed = $feedDoc->appendChild($feed);
@@ -215,26 +447,34 @@
$urlSelf = $feedDoc->createElement("Url");
$urlSelf->setAttribute("type", "application/opensearchdescription+xml");
$urlSelf->setAttribute("rel", "self");
- $urlSelf->setAttribute("template", $mapbenderPath."..".$_SERVER['SCRIPT_NAME']."?getopensearch=true");
+ $urlSelf->setAttribute("template", $mapbenderPath."..".$_SERVER['REQUEST_URI']);
$feed->appendChild($urlSelf);
//Url - results Atom
$urlSelf = $feedDoc->createElement("Url");
$urlSelf->setAttribute("type", "application/atom+xml");
$urlSelf->setAttribute("rel", "results");
- $urlSelf->setAttribute("template", $mapbenderPath."..".$_SERVER['SCRIPT_NAME']."?q={searchTerms}");
+ $urlSelf->setAttribute("template", str_replace("=SERVICE&","=DATASET&",$mapbenderPath."..".$_SERVER['REQUEST_URI']).str_replace("&","&","&OPENSEARCH=true&q={searchTerms}"));
$feed->appendChild($urlSelf);
//Url - describedby
$urlDescribedby = $feedDoc->createElement("Url");
$urlDescribedby->setAttribute("type", "application/atom+xml");
$urlDescribedby->setAttribute("rel", "describedby");
- $urlDescribedby->setAttribute("template", $mapbenderPath."..".$_SERVER['SCRIPT_NAME']."?spatial_dataset_identifier_code={inspire_dls:spatial_dataset_identifier_code?}&spatial_dataset_identifier_namespace={inspire_dls:spatial_dataset_identifier_namespace?}&crs={inspire_dls:crs?}&language={language?}&q={searchTerms?}");
+ //see documentation
+ $urlDescribedby->setAttribute("template", str_replace("=SERVICE&","=DATASET&",$mapbenderPath."..".$_SERVER['REQUEST_URI']).str_replace("&","&","&OPENSEARCH=true&spatial_dataset_identifier_code={inspire_dls:spatial_dataset_identifier_code?}&spatial_dataset_identifier_namespace={inspire_dls:spatial_dataset_identifier_namespace?}&crs={inspire_dls:crs?}&language={language?}&q={searchTerms?}"));
$feed->appendChild($urlDescribedby);
//Url - results single part (e.g. zipfile)
$urlResults = $feedDoc->createElement("Url");
- $urlResults->setAttribute("type", "application/zip");
+ $urlResults->setAttribute("type", $mimetype);//TODO give reasonable format!! - mimetypes??? geotiff/gml/other - see format of metadata
$urlResults->setAttribute("rel", "results");
- $urlResults->setAttribute("template", $mapbenderPath."..".$_SERVER['SCRIPT_NAME']."?spatial_dataset_identifier_code={inspire_dls:spatial_dataset_identifier_code?}&spatial_dataset_identifier_namespace={inspire_dls:spatial_dataset_identifier_namespace?}&crs={inspire_dls:crs?}&language={language?}&q={searchTerms?}");
+ $urlResults->setAttribute("template", str_replace("=SERVICE&","=DATASET&",$mapbenderPath."..".$_SERVER['REQUEST_URI']).str_replace("&","&","&OPENSEARCH=true&spatial_dataset_identifier_code={inspire_dls:spatial_dataset_identifier_code?}&spatial_dataset_identifier_namespace={inspire_dls:spatial_dataset_identifier_namespace?}&crs={inspire_dls:crs?}&language={language?}&q={searchTerms?}"));
$feed->appendChild($urlResults);
+ //for firefox?
+ $urlResults = $feedDoc->createElement("Url");
+ $urlResults->setAttribute("type", "text/html");//TODO give reasonable format!! - mimetypes??? geotiff/gml/other - see format of metadata - see https://developer.mozilla.org/de/docs/OpenSearch_Plugin_f%C3%BCr_Firefox_erstellen
+ $urlResults->setAttribute("rel", "results");
+ $urlResults->setAttribute("template", str_replace("=SERVICE&","=DATASET&",$mapbenderPath."..".$_SERVER['REQUEST_URI']).str_replace("&","&","&OPENSEARCH=true&spatial_dataset_identifier_code={inspire_dls:spatial_dataset_identifier_code?}&spatial_dataset_identifier_namespace={inspire_dls:spatial_dataset_identifier_namespace?}&crs={inspire_dls:crs?}&language={language?}&q={searchTerms?}"));
+ $feed->appendChild($urlResults);
+
//Url -results multi part
/*
$urlResults = $feedDoc->createElement("Url");
@@ -494,7 +734,7 @@
// -
function generateFeed($feedDoc, $recordId, $generateFrom) {
- global $admin, $type, $imageResolution, $maxImageSize, $maxFeatureCount, $mapbenderMetadata, $indexMapbenderMetadata, $layerId, $wfsId, $mapbenderPath, $epsgId, $alterAxisOrder, $departmentMetadata, $userMetadata, $hasPermission, $m, $crs, $crsUpper,$countRessource;
+ global $admin, $type, $imageResolution, $maxImageSize, $maxFeatureCount, $mapbenderMetadata, $indexMapbenderMetadata, $layerId, $wfsId, $mapbenderPath, $epsgId, $alterAxisOrder, $departmentMetadata, $userMetadata, $hasPermission, $m, $crs, $crsUpper,$countRessource, $numberOfTiles, $furtherLink;
//part which generates the feed
$feed = $feedDoc->createElementNS('http://www.w3.org/2005/Atom', 'feed');
@@ -1258,9 +1498,10 @@
return $feedDoc->saveXML();
}
+
//function to give away the xml data
function pushOpenSearch($feedDoc, $recordId, $generateFrom) {
- header("Content-type: application/xhtml+xml; charset=UTF-8");
+ header("Content-type: application/opensearchdescription+xml; charset=UTF-8");
$xml = generateOpenSearchDescription($feedDoc, $recordId, $generateFrom);
echo $xml;
die();
@@ -1372,15 +1613,21 @@
}
}
-
-if ($getOpenSearch) {
+if ($openSearch) {
readInfoFromDatabase($recordId, $generateFrom);
- pushOpenSearch($feedDoc, $recordId, $generateFrom);
+ //generate rss to get number of tiles!
+ //generateFeed($feedDoc, $recordId, $generateFrom);//TODO: maybe call feed from cache first - we have to parse the feed - it is mor simple than generate it !!!!
+ answerOpenSearchRequest($feedDoc, $recordId, $generateFrom);
+
} else {
- readInfoFromDatabase($recordId, $generateFrom);
- pushFeed($feedDoc, $recordId, $generateFrom); //throw it out to world!
+ if ($getOpenSearch) {
+ readInfoFromDatabase($recordId, $generateFrom);
+ pushOpenSearch($feedDoc, $recordId, $generateFrom);
+ } else {
+ readInfoFromDatabase($recordId, $generateFrom);
+ pushFeed($feedDoc, $recordId, $generateFrom); //throw it out to world!
+ }
}
-
?>
Modified: trunk/mapbender/http/plugins/mb_metadata_addon.php
===================================================================
--- trunk/mapbender/http/plugins/mb_metadata_addon.php 2013-08-29 14:57:08 UTC (rev 8698)
+++ trunk/mapbender/http/plugins/mb_metadata_addon.php 2013-09-03 13:25:18 UTC (rev 8699)
@@ -1,6 +1,6 @@
<?php
require_once dirname(__FILE__) . "/../../core/globalSettings.php";
-
+ require_once(dirname(__FILE__) . "/../../conf/mimetype.conf");
function displayCategories ($sql) {
if (Mapbender::session()->get("mb_lang") === "de") {
@@ -84,12 +84,14 @@
<fieldset id="data_format">
<legend><?php echo _mb("Encoding");?><img class="help-dialog" title="<?php echo _mb("Help");?>" help="{text:'<?php echo _mb("Description of the computer language construct(s) specifying the representation of data objects in a record, file, message, storage device or transmission channel.");?>'}" src="../img/questionmark.png" alt="" /></legend>
<select class="required format_selectbox" id='format' name='format'>
- <option value="database"><?php echo _mb("Database");?></option>
- <option value="shapefile"><?php echo _mb("Esri Shape");?></option>
- <option value="tab"><?php echo _mb("MapInfo Tab file");?></option>
- <option value="csv"><?php echo _mb("CSV");?></option>
- <option value="gml"><?php echo _mb("GML");?></option>
- <option value="geotiff"><?php echo _mb("GeoTIFF");?></option>
+ <!--Format List from conf file -->
+ <?php $str ="";
+ foreach ($formats as $format) {
+ $str .= "<option value='" . $format . "'>"._mb($format)."</option>";
+
+ }
+ echo $str;
+ ?>
</select>
</fieldset>
<fieldset id="charset">
More information about the Mapbender_commits
mailing list