[Mapbender-commits] r7803 - in trunk/mapbender: . conf http/php
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Tue May 10 06:06:07 EDT 2011
Author: armin11
Date: 2011-05-10 03:06:07 -0700 (Tue, 10 May 2011)
New Revision: 7803
Added:
trunk/mapbender/http/php/mod_exportISOMetadata.php
trunk/mapbender/metadata/
Modified:
trunk/mapbender/conf/mapbender.conf-dist
trunk/mapbender/http/php/mod_layerISOMetadataWriteToFolder.php
Log:
Possibility to export mapbenders layer- and dataset-metadata as iso19139 into folder metadata
Modified: trunk/mapbender/conf/mapbender.conf-dist
===================================================================
--- trunk/mapbender/conf/mapbender.conf-dist 2011-05-10 05:57:54 UTC (rev 7802)
+++ trunk/mapbender/conf/mapbender.conf-dist 2011-05-10 10:06:07 UTC (rev 7803)
@@ -152,6 +152,15 @@
#---------------------------------------------
define("PREVIEW_DIR", "../geoportal/preview");
+#---------------------------------------------
+# METADATA
+# This path is defined to allow a saving of iso19139 xml files which are generated by mapbender and metador
+# The folder should be owned by the webserver user to allow writing of files which are generated from a php
+# script. The content of the folder may be harvested
+#---------------------------------------------
+define("METADATA_DIR", "../../metadata");
+
+
# --------------------------------------------
# UPLOAD
# --------------------------------------------
Added: trunk/mapbender/http/php/mod_exportISOMetadata.php
===================================================================
--- trunk/mapbender/http/php/mod_exportISOMetadata.php (rev 0)
+++ trunk/mapbender/http/php/mod_exportISOMetadata.php 2011-05-10 10:06:07 UTC (rev 7803)
@@ -0,0 +1,111 @@
+<?php
+#http://www.geoportal.rlp.de/mapbender/php/mod_exportISOMetadata.php?
+# $Id: mod_exportISOMetadata.php 235
+# http://www.mapbender.org/index.php/Inspire_Metadata_Editor
+# Copyright (C) 2002 CCGIS
+#
+# 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)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
+require_once(dirname(__FILE__) . "/../classes/class_connector.php");
+
+$con = db_connect(DBSERVER,OWNER,PW);
+db_select_db(DB,$con);
+
+//define the view or table where to read out the layer ids for which metadatafiles should be generated
+$wmsView = "search_wms_view";
+//parse request parameter
+//make all parameters available as upper case
+foreach($_REQUEST as $key => $val) {
+ $_REQUEST[strtoupper($key)] = $val;
+}
+//validate request params
+
+//
+if (!isset($_REQUEST['TYPE'])) {
+ echo 'GET Parameter Type lacks';
+ die();
+}
+if (isset($_REQUEST['TYPE']) and $_REQUEST['TYPE'] != "ALL") {
+ //
+ echo 'validate: <b>'.$_REQUEST['TYPE'].'</b> is not valid.<br/>';
+ die();
+}
+$sql = "SELECT layer_id ";
+$sql .= "FROM ".$wmsView;
+//$sql .= "FROM layer WHERE layer_id IN (20203,20202)";
+$v = array();
+$t = array();
+$res = db_prep_query($sql,$v,$t);
+
+$generatorScript = '/mapbender/php/mod_layerISOMetadata.php?';
+$generatorBaseUrl = 'http://'.$_SERVER['HTTP_HOST'].$generatorScript;
+
+$generatorScriptMetadata = '/mapbender/php/mod_dataISOMetadata.php?';
+$generatorBaseUrlMetadata = 'http://'.$_SERVER['HTTP_HOST'].$generatorScriptMetadata;
+
+$countLayer = 0;
+$countMetadataURL = 0;
+
+while($row = db_fetch_array($res)){
+ $generatorUrl = $generatorBaseUrl."SERVICE=WMS&outputFormat=iso19139&id=".$row['layer_id'];
+ echo "URL requested : ".$generatorUrl."<br>";
+ $generatorInterfaceObject = new connector($generatorUrl);
+ $ISOFile = $generatorInterfaceObject->file;
+ $layerId = $row['layer_id'];
+ echo "File for layer ".$layerId." will be generated<br>";
+ //generate temporary files under tmp
+ if($h = fopen(METADATA_DIR."/mapbenderServiceMetadata_".$layerId."_iso19139.xml","w")){
+ if(!fwrite($h,$ISOFile)){
+ $e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".METADATA_DIR."/mapbenderLayerMetadata_".$row['layer_id']."_iso19139.xml");
+ }
+ echo "Service metadata file for layer ".$layerId." written to ".METADATA_DIR."<br>";
+ fclose($h);
+ }
+
+ //get all connected metadata for this layer and save it too
+ $sql = <<<SQL
+
+SELECT metadata_id, uuid, link, linktype, md_format, origin FROM mb_metadata
+INNER JOIN (SELECT * from ows_relation_metadata
+WHERE fkey_layer_id = $layerId ) as relation ON
+mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.export2csw = TRUE
+
+SQL;
+ $countMetadataURL = 0;
+ $res_metadata = db_query($sql);
+ while ($row_metadata = db_fetch_array($res_metadata)) {
+ $generatorUrlMetadata = $generatorBaseUrlMetadata."outputFormat=iso19139&id=".$row_metadata['uuid'];
+ echo "<BLOCKQUOTE>URL requested : ".$generatorUrlMetadata."<br>";
+ $generatorInterfaceObject = new connector($generatorUrlMetadata);
+ $ISOFile = $generatorInterfaceObject->file;
+ echo "Metadata uuid: ".$row_metadata['uuid']."<br>";
+ //generate temporary files under tmp
+ if($h = fopen(METADATA_DIR."/mapbenderDataMetadata_".$layerId."_".$row_metadata['uuid']."_iso19139.xml","w")){
+ if(!fwrite($h,$ISOFile)){
+ $e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".METADATA_DIR."/metadata/mapbenderMetadata_".$layerId."_".$row_metadata['uuid']."_iso19139.xml");
+ }
+ echo "Data metadate file for layer ".$row['layer_id']." and metadata ".$row_metadata['uuid']." written to ".METADATA_DIR."</BLOCKQUOTE><br>";
+ fclose($h);
+ }
+ $countMetadataURL++;
+ }
+ $countLayer++;
+}
+echo "Number of generated Service Metadata Records (one for each layer): ".$countLayer."<br>";
+echo "Number of generated Data Metadata Records (multiple for each layer): ".$countLayer."<br>";
+
+
+
Modified: trunk/mapbender/http/php/mod_layerISOMetadataWriteToFolder.php
===================================================================
--- trunk/mapbender/http/php/mod_layerISOMetadataWriteToFolder.php 2011-05-10 05:57:54 UTC (rev 7802)
+++ trunk/mapbender/http/php/mod_layerISOMetadataWriteToFolder.php 2011-05-10 10:06:07 UTC (rev 7803)
@@ -1,6 +1,6 @@
<?php
-#http://www.geoportal.rlp.de/mapbender/php/mod_layerISOMetadataWriteToFolder.php?SERVICE=WMS&outputFormat=iso19139&Id=24356
-# $Id: mod_layerISOMetadata.php 235
+#http://www.geoportal.rlp.de/mapbender/php/mod_exportISOMetadata.php?
+# $Id: mod_exportISOMetadata.php 235
# http://www.mapbender.org/index.php/Inspire_Metadata_Editor
# Copyright (C) 2002 CCGIS
#
@@ -18,7 +18,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
require_once(dirname(__FILE__) . "/../../core/globalSettings.php");
require_once(dirname(__FILE__) . "/../classes/class_connector.php");
@@ -26,7 +25,7 @@
db_select_db(DB,$con);
//define the view or table where to read out the layer ids for which metadatafiles should be generated
-$wmsView = "wms_search_table";
+$wmsView = "search_wms_view";
//$wmsView = '';
//parse request parameter
//make all parameters available as upper case
@@ -48,8 +47,9 @@
die();
}
-$sql = "SELECT layer_id ";
-$sql .= "FROM ".$wmsView;
+$sql = "SELECT layer_id, uuid ";
+//$sql .= "FROM ".$wmsView;
+$sql .= "FROM layer WHERE layer_id IN (20203,20202)";
$v = array();
$t = array();
$res = db_prep_query($sql,$v,$t);
@@ -57,6 +57,9 @@
$generatorScript = '/mapbender/php/mod_layerISOMetadata.php?';
$generatorBaseUrl = 'http://'.$_SERVER['HTTP_HOST'].$generatorScript;
+$generatorScriptMetadata = '/mapbender/php/mod_dataISOMetadata.php?';
+$generatorBaseUrlMetadata = 'http://'.$_SERVER['HTTP_HOST'].$generatorScriptMetadata;
+
echo $generatorBaseUrl."<br>";
while($row = db_fetch_array($res)){
@@ -64,34 +67,44 @@
echo "URL requested : ".$generatorUrl."<br>";
$generatorInterfaceObject = new connector($generatorUrl);
$ISOFile = $generatorInterfaceObject->file;
- #echo "Returned value: ".$ISOFile."<br>";
- //generate file identifier:
- $fileId = guid();
- echo "File ID ".$fileId." generated<br>";
+ $layerId = $row['layer_id'];
+ echo "File for layer ".$row['layer_id']." will be generated<br>";
//generate temporary files under tmp
- if($h = fopen(TMPDIR."/metadata/mapbenderLayerMetadata_".$row['layer_id']."_".$fileId."_iso19139.xml","w")){
+ if($h = fopen(TMPDIR."/metadata/mapbenderServiceMetadata_".$layerId."_iso19139.xml","w")){
if(!fwrite($h,$ISOFile)){
- $e = new mb_exception("mod_layerISOMetadata: cannot write to file: ".TMPDIR."/mapbenderLayerMetadata_".$row['layer_id']."_".$fileId."_iso19139.xml");
+ $e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".TMPDIR."/mapbenderLayerMetadata_".$row['layer_id']."_iso19139.xml");
}
- echo "File for ID ".$fileId." written to TMP<br>";
+ echo "Service metadata file for layer ".$row['layer_id']." written to TMP<br>";
fclose($h);
+ //get all connected metadata for this layer and save it too
+ $sql = <<<SQL
+
+SELECT metadata_id, uuid, link, linktype, md_format, origin FROM mb_metadata
+INNER JOIN (SELECT * from ows_relation_metadata
+WHERE fkey_layer_id = $layerId ) as relation ON
+mb_metadata.metadata_id = relation.fkey_metadata_id WHERE mb_metadata.export2csw = TRUE
+
+SQL;
+ $i = 0;
+ $res_metadata = db_query($sql);
+ while ($row_metadata = db_fetch_array($res_metadata)) {
+ $generatorUrlMetadata = $generatorBaseUrlMetadata."outputFormat=iso19139&id=".$row_metadata['uuid'];
+ echo "URL requested : ".$generatorUrlMetadata."<br>";
+ $generatorInterfaceObject = new connector($generatorUrlMetadata);
+ $ISOFile = $generatorInterfaceObject->file;
+ echo "Metadata uuid: ".$row_metadata['uuid']."<br>";
+ //generate temporary files under tmp
+ if($h = fopen(TMPDIR."/metadata/mapbenderMetadata_".$layerId."_".$row_metadata['uuid']."_iso19139.xml","w")){
+ if(!fwrite($h,$ISOFile)){
+ $e = new mb_exception("mod_exportISOMetadata.php: cannot write to file: ".TMPDIR."/metadata/mapbenderMetadata_".$layerId."_".$row_metadata['uuid']."_iso19139.xml");
+ }
+ echo "Data metadate file for layer ".$row['layer_id']." and metadata ".$row_metadata['uuid']." written to TMP<br>";
+ fclose($h);
+ $i++;
}
}
-function guid(){
- if (function_exists('com_create_guid')){
- return com_create_guid();
- }else{
- mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
- $charid = strtoupper(md5(uniqid(rand(), true)));
- $hyphen = chr(45);// "-"
- $uuid = chr(123)// "{"
- .substr($charid, 0, 8).$hyphen
- .substr($charid, 8, 4).$hyphen
- .substr($charid,12, 4).$hyphen
- .substr($charid,16, 4).$hyphen
- .substr($charid,20,12)
- .chr(125);// "}"
- return $uuid;
- }
-}
+
+
+
+
More information about the Mapbender_commits
mailing list