[fusion-commits] r1802 - trunk/layers/MapServer/php
svn_fusion at osgeo.org
svn_fusion at osgeo.org
Tue Mar 3 16:36:56 EST 2009
Author: pdeschamps
Date: 2009-03-03 16:36:55 -0500 (Tue, 03 Mar 2009)
New Revision: 1802
Modified:
trunk/layers/MapServer/php/Selection.php
Log:
closes #217: Added logic to recalc bbox if layer is in a different
projection then the map
Modified: trunk/layers/MapServer/php/Selection.php
===================================================================
--- trunk/layers/MapServer/php/Selection.php 2009-02-23 21:12:17 UTC (rev 1801)
+++ trunk/layers/MapServer/php/Selection.php 2009-03-03 21:36:55 UTC (rev 1802)
@@ -34,16 +34,17 @@
include('../../../common/php/Utilities.php');
include ("Utilities.php");
-
if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
$oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
}
$result = NULL;
$result->layers = array();
+$oMapProjection = $oMap->getProjection();
-if (isset($_REQUEST['queryfile']) && $_REQUEST['queryfile'] != "")
+
+if (isset($_REQUEST['queryfile']) && $_REQUEST['queryfile'] != "")
{
$oMap->loadquery($_REQUEST['queryfile']);
@@ -58,7 +59,7 @@
$aLayers = split(",", $_REQUEST['layers']);
$bAllLayers = 0;
}
-
+
$aStartCount = array();
if (isset($_REQUEST['startcount']) && $_REQUEST['startcount'] !='')
{
@@ -71,7 +72,7 @@
echo "error : number of layers and number of startcount should be the same";
exit;
}
-
+
$properties = $_SESSION['selection_array'];
$aSelectedLayers = $properties->layers;
if (count($aSelectedLayers) > 0)
@@ -85,7 +86,7 @@
for ($i=0; $i<count($aSelectedLayers); $i++)
{
$layerName = $aSelectedLayers[$i];
- if (($bAllLayers || in_array($layerName, $aLayers)) &&
+ if (($bAllLayers || in_array($layerName, $aLayers)) &&
$properties->$layerName->numelements > 0)
{
array_push($result->layers, $layerName);
@@ -93,10 +94,10 @@
$result->$layerName->propertyvalues = $properties->$layerName->propertyvalues;
$result->$layerName->propertytypes = $properties->$layerName->propertytypes;
$result->$layerName->metadatanames = $properties->$layerName->metadatanames;
-
+ $result->$layerName->bbox = getBBox($layerName);
/*if start and count are given, validate them. If valid return the valid elements.
if not return all elements. */
-
+
$start = -1;
$count = -1;
if (count($aStartCount) > 0)
@@ -116,7 +117,7 @@
}
/*invalid entries*/
- if ($start < 0 || $count <=0 ||
+ if ($start < 0 || $count <=0 ||
$start >= $properties->$layerName->numelements ||
$count > $properties->$layerName->numelements ||
($start + $count) > $properties->$layerName->numelements)
@@ -134,15 +135,40 @@
}
//print_r($properties->$layerName);
$result->$layerName->numelements = $count;
-
+
$result->$layerName->values = array();
$result->$layerName->metadata = array();
$iIndice = 0;
+
for ($j=$start; $j<($start+$count); $j++)
{
+ $szLayerProjection = getLayerProjection($oMap,$layerName);
+
+ $oLayerExtents = $result->$layerName->bbox;
+
+ if($szLayerProjection){
+ if($szLayerProjection != $oMapProjection){
+
+ $minx = $oLayerExtents->minx;
+ $miny =$oLayerExtents->miny;
+ $maxx = $oLayerExtents->maxx;
+ $maxy =$oLayerExtents->maxy;
+
+ reprojectPoint( &$minx, &$miny, $szLayerProjection, $oMapProjection );
+ reprojectPoint( &$maxx, &$maxy, $szLayerProjection, $oMapProjection );
+
+ $result->extents->minx = $minx;
+ $result->extents->miny = $miny;
+ $result->extents->maxx = $maxx;
+ $result->extents->maxy= $maxy;
+
+ }
+ }
+
$result->$layerName->values[$iIndice] = $properties->$layerName->values[$j];
$result->$layerName->metadata[$iIndice] = $properties->$layerName->metadata[$j];
$iIndice++;
+
}
}
}
@@ -154,6 +180,72 @@
header('X-JSON: true');
echo var2json($result);
+function getBBox($layername){
+ global $properties;
+ foreach($properties->$layername->metadatanames as $key=>$value){
+ if($value == "bbox"){
+ $aBBox = split(",",$properties->$layername->metadata[0][$key]);
+ $oBBox->minx = $aBBox[0];
+ $oBBox->miny = $aBBox[1];
+ $oBBox->maxx = $aBBox[2];
+ $oBBox->maxy= $aBBox[3];
+ return $oBBox;
+ }
+ }
+ return false;
+}
+function getLayerProjection($oMap,$szLayerName){
+ $oLayer = &$oMap->getLayerByName($szLayerName);
+ if($oLayer){
+ $szProjection = $oLayer->getProjection();
+ if($szProjection){
+ return $szProjection;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+}
+function reprojectPoint( &$nX, &$nY, $szFrom, $szTo )
+{
+ //echo "reproject $nX,$nY from $szFrom to $szTo\n";
+
+ //check to see if reprojection is necessary
+ if ($szFrom == '' || $szTo == '')
+ {
+ return;
+ }
+
+ if (stristr($szFrom, "epsg") !== false &&
+ stristr( $szFrom, "init=") == false)
+ {
+ $szFrom = "init=".strtolower($szFrom);
+ }
+ if (stristr($szTo, "epsg") !== false &&
+ stristr( $szTo, "init=") == false)
+ {
+ $szTo = "init=".strtolower($szTo);
+ }
+
+ if ($szFrom == $szTo)
+ {
+ return;
+ }
+
+ $oPoint = ms_newPointObj();
+ $oPoint->setXY( $nX, $nY );
+ $oPoint->project( ms_newProjectionObj( $szFrom ),
+ ms_newProjectionObj( $szTo )
+ );
+ $nX = $oPoint->x;
+ $nY = $oPoint->y;
+ //echo " :".$nX." ,".$nY."<br>";
+}
?>
More information about the fusion-commits
mailing list