[Mapbender-commits] r7167 - trunk/mapbender/http/classes
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Fri Nov 26 05:53:13 EST 2010
Author: verenadiewald
Date: 2010-11-26 02:53:13 -0800 (Fri, 26 Nov 2010)
New Revision: 7167
Modified:
trunk/mapbender/http/classes/class_wms.php
Log:
http://trac.osgeo.org/mapbender/ticket/726 and http://trac.osgeo.org/mapbender/ticket/727
Modified: trunk/mapbender/http/classes/class_wms.php
===================================================================
--- trunk/mapbender/http/classes/class_wms.php 2010-11-26 10:17:26 UTC (rev 7166)
+++ trunk/mapbender/http/classes/class_wms.php 2010-11-26 10:53:13 UTC (rev 7167)
@@ -1790,7 +1790,113 @@
}
}
}
- function insertLayerEPSG($i){
+ function isSupportedSRS($epsg,$layerId) {
+ //request the original capabilities from service
+ $sql = "SELECT layer.layer_name AS layer_name, wms.wms_getcapabilities_doc AS cap from layer,wms WHERE layer.layer_id=".$layerId." AND layer.fkey_wms_id=wms.wms_id";
+ $res = db_query($sql);
+ $row = db_fetch_array($res);
+ //parse capabilities to php object - check if it is still loaded to db
+ if ($row['cap'] == '') {
+ $wmsCapXml=simplexml_load_string($this->wms_getcapabilities_doc);
+ }
+ else {
+ $wmsCapXml=simplexml_load_string($row['cap']);
+ }
+
+ if(!isset($wmsCapXml)) {
+ $n = new mb_exception("Problem while parsing capabilities document with simplexml");
+ echo "Problem while parsing capabilities document with simplexml<br>";
+ return false;
+ }
+
+ //layer name from DB
+ $layerName=$row['layer_name'];
+ //defining the xpath for getting all Layer-tags
+ $xpathLayerName="//Layer[./Name =\"".$layerName."\"]";
+
+ $layerObject=$wmsCapXml->xpath($xpathLayerName);
+
+ //for none named layer (only title is set)
+ if(!isset($layerObject[0])) {
+ $n = new mb_notice("Layer has no name, BBOX will not be generated for ".$epsg);
+ return false;
+ }
+
+ //search for the SRS tag of specified layer
+ $srsElementArray=$layerObject[0]->xpath("SRS");
+ foreach($srsElementArray as $srsElement) {
+ //create an array of the given srsElements -> include also srs written as a space separated list
+ $srsArray = explode(" ",$srsElement);
+ foreach($srsArray as $srs) {
+ if(strtoupper($srs) == strtoupper($epsg)) {
+ $n = new mb_notice("Requested SRS: ".$epsg." is supported by layer: ".$layerName." with layerId: ".$layerId);
+ return true;
+ }
+ }
+ }
+
+ $n = new mb_notice("Requested SRS: ".$epsg." is not supported by layer: ".$layerName." with layerId: ".$layerId);
+ return false;
+ }
+ //get all supported srs as an intersection of the supported srs of the root layer and the SRS_ARRAY defined in mapbender.conf
+ function getSupportedSRS($layerId, $confSrsArray) {
+ //request the original capabilities from service
+ $sql = "SELECT layer.layer_name AS layer_name, wms.wms_getcapabilities_doc AS cap FROM layer, wms ".
+ "WHERE layer.fkey_wms_id IN (SELECT layer.fkey_wms_id FROM layer WHERE layer.layer_id = " . $layerId . ") ".
+ "AND layer.layer_parent = '' AND layer.fkey_wms_id=wms.wms_id";
+ $res = db_query($sql);
+ $row = db_fetch_array($res);
+
+ //parse capabilities to php object - check if it is still loaded to db
+ if ($row['cap'] == '') {
+ $wmsCapXml=simplexml_load_string($this->wms_getcapabilities_doc);
+ }
+ else {
+ $wmsCapXml=simplexml_load_string($row['cap']);
+ }
+
+ if(!isset($wmsCapXml)) {
+ $n = new mb_exception("Problem while parsing capabilities document with simplexml");
+ echo "Problem while parsing capabilities document with simplexml<br>";
+ return false;
+ }
+
+ //layer name from DB
+ $layerName=$row['layer_name'];
+ //defining the xpath for getting all Layer-tags
+ $xpathLayerName="//Layer[./Name =\"".$layerName."\"]";
+
+ $layerObject=$wmsCapXml->xpath($xpathLayerName);
+
+ //for none named layer (only title is set)
+ if(!isset($layerObject[0])) {
+ $n = new mb_notice("Layer has no name, didn't get supported srs for layer with id ".$layerId);
+ return false;
+ }
+
+ $supportedSrsArray = array();
+
+ //search for the SRS tag of specified layer
+ $srsElementArray=$layerObject[0]->xpath("SRS");
+
+ foreach($srsElementArray as $srsElement) {
+ //create an array of the given srsElements -> include also srs written as a space separated list
+ $srsArray = explode(" ",$srsElement);
+ foreach($srsArray as $srs) {
+ if(in_array(strtoupper($srs),$confSrsArray)) {
+ array_push($supportedSrsArray, strtoupper($srs));
+ $n = new mb_notice("Requested SRS: ".$epsg." is supported by layer: ".$layerName." with layerId: ".$layerId);
+ }
+ }
+ }
+
+ if(count($supportedSrsArray) == 0) {
+ $n = new mb_notice("Requested SRS: ".$epsg." is not supported by layer: ".$layerName." with layerId: ".$layerId);
+ }
+
+ return $supportedSrsArray;
+ }
+ function insertLayerEPSG($i) {
$sql = "DELETE FROM layer_epsg WHERE fkey_layer_id = $1";
$v = array($this->objLayer[$i]->db_id);
$t = array('i');
@@ -1808,6 +1914,63 @@
db_rollback();
}
}
+
+// GET SRS_ARRAY of mapbender.conf
+ if(SRS_ARRAY != "") {
+ $confSrsArray = split(",",SRS_ARRAY);
+ foreach($confSrsArray as &$srs) {
+ $srs = trim($srs);
+ }
+ }
+ for ($index = 0; $index < sizeof($confSrsArray); $index++) {
+ $confSrsArray[$index] = "EPSG:" . $confSrsArray[$index];
+ }
+
+ $sql_epsg = "SELECT * FROM layer_epsg WHERE fkey_layer_id = $1";
+ $v_epsg = array($this->objLayer[$i]->db_id);
+ $t_epsg = array('i');
+ $res_epsg = db_prep_query($sql_epsg,$v_epsg,$t_epsg);
+ $epsg = array();
+ $minx = array();
+ $miny = array();
+ $maxx = array();
+ $maxy = array();
+ $cnt = 0;
+ while($row_epsg = db_fetch_array($res_epsg)){
+ array_push($epsg,strtoupper($row_epsg['epsg']));
+ array_push($minx,$row_epsg['minx']);
+ array_push($miny,$row_epsg['miny']);
+ array_push($maxx,$row_epsg['maxx']);
+ array_push($maxy,$row_epsg['maxy']);
+ $cnt++;
+ }
+
+ //get all srs which are supported by the parent layer and in array SRS_ARRAY from mapbender.conf
+ $supportedSrs = $this->getSupportedSRS($this->objLayer[$i]->db_id, $confSrsArray);
+
+ for($k=0; $k < count($supportedSrs);$k++) {
+ if(!in_array($supportedSrs[$k],$epsg)) {
+ $n = new mb_notice("Calculation for: ".$supportedSrs[$k]);
+ $pointMin = new Mapbender_point($minx[0], $miny[0], $epsg[0]);
+ $pointMax = new Mapbender_point($maxx[0], $maxy[0], $epsg[0]);
+ $pointMin->transform($supportedSrs[$k]);
+ $pointMax->transform($supportedSrs[$k]);
+
+ if($pointMin->epsg != '' && $pointMin->x != '' && $pointMin->y != ''
+ && $pointMax->x != '' && $pointMax->y != '') {
+ $sql_bbox = "INSERT INTO layer_epsg (fkey_layer_id, epsg, minx, miny, maxx, maxy) ";
+ $sql_bbox .= "VALUES($1,$2,$3,$4,$5,$6)";
+ $v_bbox = array($this->objLayer[$i]->db_id,$pointMin->epsg,$pointMin->x,
+ $pointMin->y,$pointMax->x,$pointMax->y);
+ $t_bbox = array('i','s','d','d','d','d');
+ $res_bbox = db_prep_query($sql_bbox,$v_bbox,$t_bbox);
+ $n = new mb_notice("Calculation for: ".$supportedSrs[$k]." finished successful.");
+ }
+ else {
+ $e = new mb_exception("Could not transform ".strtoupper($epsg[0])." to ".$supportedSrs[$k].".");
+ }
+ }
+ }
}
function insertLayerStyle($i){
$sql = "DELETE FROM layer_style WHERE fkey_layer_id = $1";
More information about the Mapbender_commits
mailing list