[fusion-commits] r2632 - trunk/layers/MapGuide/php

svn_fusion at osgeo.org svn_fusion at osgeo.org
Fri Jan 4 23:44:51 PST 2013


Author: liuar
Date: 2013-01-04 23:44:50 -0800 (Fri, 04 Jan 2013)
New Revision: 2632

Modified:
   trunk/layers/MapGuide/php/Constants.php
   trunk/layers/MapGuide/php/GetSelectionProperties.php
   trunk/layers/MapGuide/php/Utilities.php
Log:
Submit on behalf of: Andy Zhang
Integrate revision 2625 to trunk.
Use API MgSelectionBase::GenerateFilters instead of MgSelectionBase::GenerateFilter to avoid the filter text exceed the SQL length limit.


Modified: trunk/layers/MapGuide/php/Constants.php
===================================================================
--- trunk/layers/MapGuide/php/Constants.php	2013-01-05 07:20:18 UTC (rev 2631)
+++ trunk/layers/MapGuide/php/Constants.php	2013-01-05 07:44:50 UTC (rev 2632)
@@ -1871,4 +1871,13 @@
    
 }
 
+////////////////////////////////////////////////////////////////////////////////
+/// <summary>
+/// The batch size to use when rendering a selection.
+/// </summary>
+class MgSelectionBatchSize
+{
+   const RenderSelectionBatchSize = 30000 ; 
+}
+
 ?>
\ No newline at end of file

Modified: trunk/layers/MapGuide/php/GetSelectionProperties.php
===================================================================
--- trunk/layers/MapGuide/php/GetSelectionProperties.php	2013-01-05 07:20:18 UTC (rev 2631)
+++ trunk/layers/MapGuide/php/GetSelectionProperties.php	2013-01-05 07:44:50 UTC (rev 2632)
@@ -60,6 +60,7 @@
         /*holds selection array*/
         $properties = NULL;
         $properties->layers = array();
+        $properties->envelope = NULL;
 
         //process
         header('Content-type: application/json');
@@ -80,7 +81,7 @@
             //could it be that $selection->AddFeatures($layerObj, $featureReader, 0) is
             //the one causing a problem when the properies are limited ?
             if (isset($_SESSION['property_mappings']) && isset($_SESSION['property_mappings'][$oLayer->GetObjectId()])) {
-                $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];                
+                $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];
                 if (count($mappings) > 0) {
                     foreach($mappings as $name => $value) {
                         $queryOptions->AddFeatureProperty($name);
@@ -93,53 +94,60 @@
             $geomName = $oLayer->GetFeatureGeometryName();
             $queryOptions->AddFeatureProperty($geomName);
 
-            $filter = $selection->GenerateFilter($oLayer, $class);
-            $queryOptions->SetFilter($filter);
-            $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
+            $filters = $selection->GenerateFilters($oLayer, $class, MgSelectionBatchSize::RenderSelectionBatchSize);
+            $featureReaders = NULL;
+            $featureReaders = array(); 
+            for ($j = 0; $j < $filters->GetCount(); $j++) {
+                $queryOptions->SetFilter($filters->GetItem($j));
+                $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);	
+                array_push($featureReaders, $featureReader);
+            }
             //$featureReader = $selection->GetSelectedFeatures($oLayer, $class, true );//this doesn't seem to work but would replace much of the above code
 
             $layerName = $oLayer->GetName();
             array_push($properties->layers, $layerName);
 
-        // TODO: Check if computed properties are needed?
+            // TODO: Check if computed properties are needed?
             $bComputedProperties = false;
             $bNeedsTransform = false;
             $srsLayer = NULL;
             if ($bComputedProperties)
             {
-        $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
-        $srsLayerWkt = false;
-        if($spatialContext != null && $spatialContext->ReadNext() != null) {
-            $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
-            /* skip this layer if the srs is empty */
-        }
-        if ($srsLayerWkt == null) {
-            $srsLayerWkt = $srsDefMap;
-        }
-        /* create a coordinate system from the layer's SRS wkt */
-        $srsLayer = $srsFactory->Create($srsLayerWkt);
+                $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
+                $srsLayerWkt = false;
+                if($spatialContext != null && $spatialContext->ReadNext() != null) {
+                    $srsLayerWkt = $spatialContext->GetCoordinateSystemWkt();
+                    /* skip this layer if the srs is empty */
+                }
+                if ($srsLayerWkt == null) {
+                    $srsLayerWkt = $srsDefMap;
+                }
+                /* create a coordinate system from the layer's SRS wkt */
+                $srsLayer = $srsFactory->Create($srsLayerWkt);
 
-        // exclude layer if:
-        //  the map is non-arbitrary and the layer is arbitrary or vice-versa
-        //     or
-        //  layer and map are both arbitrary but have different units
-        //
-        $bLayerSrsIsArbitrary = ($srsLayer->GetType() == MgCoordinateSystemType::Arbitrary);
-        $bMapSrsIsArbitrary = ($srsMap->GetType() == MgCoordinateSystemType::Arbitrary);
-        if (($bLayerSrsIsArbitrary != $bMapSrsIsArbitrary) ||
-            ($bLayerSrsIsArbitrary && ($srsLayer->GetUnits() != $srsMap->GetUnits()))) {
-            $bComputedProperties = false;
-        } else {
-            $srsTarget = null;
-            $srsXform = null;
-            $bNeedsTransform = ($srsLayer->GetUnitScale() != 1.0);
-        }
+                // exclude layer if:
+                //  the map is non-arbitrary and the layer is arbitrary or vice-versa
+                //     or
+                //  layer and map are both arbitrary but have different units
+                //
+                $bLayerSrsIsArbitrary = ($srsLayer->GetType() == MgCoordinateSystemType::Arbitrary);
+                $bMapSrsIsArbitrary = ($srsMap->GetType() == MgCoordinateSystemType::Arbitrary);
+                if (($bLayerSrsIsArbitrary != $bMapSrsIsArbitrary) ||
+                    ($bLayerSrsIsArbitrary && ($srsLayer->GetUnits() != $srsMap->GetUnits()))) {
+                    $bComputedProperties = false;
+                } else {
+                    $srsTarget = null;
+                    $srsXform = null;
+                    $bNeedsTransform = ($srsLayer->GetUnitScale() != 1.0);
+                }
             }
 
-            $properties = BuildSelectionArray($featureReader, $layerName, $properties,
+            $properties = BuildSelectionArrayEx($featureReaders, $layerName, $properties,
                                               $bComputedProperties,
                                               $srsLayer, $bNeedsTransform, $oLayer, true);
-            $featureReader->Close();
+            foreach ($featureReaders as $featureReader) {
+                $featureReader->Close();
+            }
         }
 
         $result = NULL;
@@ -147,7 +155,7 @@
         if ($layers && $layers->GetCount() >= 0)
         {
             $result->hasSelection = true;
-            $oExtents = $selection->GetExtents($featureService);
+            $oExtents = $properties->envelope;
             if ($oExtents)
             {
                 $oMin = $oExtents->GetLowerLeftCoordinate();

Modified: trunk/layers/MapGuide/php/Utilities.php
===================================================================
--- trunk/layers/MapGuide/php/Utilities.php	2013-01-05 07:20:18 UTC (rev 2631)
+++ trunk/layers/MapGuide/php/Utilities.php	2013-01-05 07:44:50 UTC (rev 2632)
@@ -891,6 +891,154 @@
     return $properties;
 }
 
+/**
+   keep all the attributes of selected features in an array
+ */
+function BuildSelectionArrayEx($featureReaders, $layerName, $properties, $bComputedProperties,
+                             $srsLayer, $bNeedsTransform, $layerObj, $isLayerNameEncoded)
+{
+    if (count($featureReaders) == 0)
+        return $properties;
+
+    if($isLayerNameEncoded)
+    {
+        // Add prefix to avoid layer name beginning with number
+        // So $isLayerNameEncoded should be true when and only when the properties will be stored in session
+        $layerName = GetEncodedLayerName($layerName);
+    }
+
+    $agf = new MgAgfReaderWriter();
+    $srsFactory = new MgCoordinateSystemFactory();
+
+    $properties->$layerName->propertynames = array();
+    $properties->$layerName->propertyvalues = array();
+    $properties->$layerName->propertytypes = array();
+    $properties->$layerName->numelements = 0;
+    $properties->$layerName->values = array();
+
+    $properties->$layerName->metadatanames= array();
+    array_push($properties->$layerName->metadatanames, 'dimension');
+    array_push($properties->$layerName->metadatanames, 'bbox');
+    array_push($properties->$layerName->metadatanames, 'center');
+    array_push($properties->$layerName->metadatanames, 'area');
+    array_push($properties->$layerName->metadatanames, 'length');
+
+    $featureReader = $featureReaders[0];
+    $mappings = $_SESSION['property_mappings'][$layerObj->GetObjectId()];
+    foreach((array)$mappings as $name => $value)
+    {
+        $propType = $featureReader->GetPropertyType($name);
+        array_push($properties->$layerName->propertynames, $name);
+        array_push($properties->$layerName->propertyvalues, $value);
+        array_push($properties->$layerName->propertytypes, $propType);
+    }
+
+    $srsTarget = null;
+    $srsXform = null;
+    //$envelope = new MgEnvelope();
+
+    foreach ($featureReaders as $featureReader) 
+    {
+        while ($featureReader->ReadNext())
+        {
+            $properties->$layerName->values[$properties->$layerName->numelements] = array();
+            $properties->$layerName->metadata[$properties->$layerName->numelements] = array();
+
+            $dimension = '';
+            $bbox = '';
+            $center = '';
+            $area = '';
+            $length = '';
+            if ($bComputedProperties)
+            {
+                $classDef = $featureReader->GetClassDefinition();
+                $geomName = $classDef->GetDefaultGeometryPropertyName();
+                if ($geomName != '') {
+                    $geomByteReader = $featureReader->GetGeometry($geomName);
+                    /* is this needed? We declare one outside the loop too?*/
+                    $agf = new MgAgfReaderWriter();
+                    $geom = $agf->Read($geomByteReader);
+
+                    $envelope = $geom->Envelope();
+                    $ll = $envelope->GetLowerLeftCoordinate();
+                    $ur = $envelope->GetUpperRightCoordinate();
+                    $bbox = $ll->GetX().','.$ll->GetY().','.$ur->GetX().','.$ur->GetY();
+                    $centroid = $geom->GetCentroid()->GetCoordinate();
+                    $center = $centroid->GetX().','.$centroid->GetY();
+
+                    /* 0 = point, 1 = curve, 2 = surface */
+                    $dimension = $geom->GetDimension();
+
+                    if ($geom->GetDimension() > 0) {
+                      //conver the geometry to UTM auto so that local measurements
+                      //are accruate in meters
+                        if ($bNeedsTransform && $srsTarget == null && $srsXform == null) {
+                            $wkt = getUtmWkt($centroid->GetX(),
+                                             $centroid->GetY());
+                            $srsTarget = $srsFactory->Create($wkt);
+                            $verMajor = subStr(GetSiteVersion(), 0,1);
+                            if ($verMajor == '1') {
+                              $srsXform = new MgCoordinateSystemTransform($srsLayer, $srsTarget);
+                            } else {
+                              $srsXform = $srsFactory->GetTransform($srsLayer, $srsTarget);
+                            }
+                        }
+                        if ($srsXform != null) {
+                            try {
+                                $ageom = $geom->Transform($srsXform);
+                                $geom = $ageom;
+                            } catch (MgException $ee) {
+                              echo "/*transform exception:";
+                              echo "ERROR: " . $ee->GetExceptionMessage() . "\n";
+                              echo $ee->GetDetails() . "\n*/";
+                            }
+                        }
+
+                        if ($geom->GetDimension() > 1) {
+                            $area = $geom->GetArea();
+                        }
+                        if ($geom->GetDimension() > 0) {
+                            $length = $geom->GetLength();
+                        }
+                    }
+                }
+            }
+            array_push($properties->$layerName->metadata[$properties->$layerName->numelements], $dimension);
+            array_push($properties->$layerName->metadata[$properties->$layerName->numelements], $bbox);
+            array_push($properties->$layerName->metadata[$properties->$layerName->numelements], $center);
+            array_push($properties->$layerName->metadata[$properties->$layerName->numelements], $area);
+            array_push($properties->$layerName->metadata[$properties->$layerName->numelements], $length);
+
+
+            $numproperties = count($properties->$layerName->propertynames);
+            for($j=0; $j<$numproperties; $j++) {
+                $propname = $properties->$layerName->propertynames[$j];
+                $propType = $properties->$layerName->propertytypes[$j];
+                if ($propname == '')
+                    continue;
+                if ($propType == MgPropertyType::Geometry) {
+                    $geomByteReader = $featureReader->GetGeometry($geomName);
+                    $geom = $agf->Read($geomByteReader);
+                    $geomEnv = $geom->Envelope();
+                    $properties->envolope->ExpandToInclude($geomEnv);
+                }
+                else {
+                    $value =  GetPropertyValueFromFeatReader($featureReader,
+                                                             $properties->$layerName->propertytypes[$j],
+                                                             $propname);
+                    $value = htmlentities($value, ENT_COMPAT, 'UTF-8');
+                    $value = addslashes($value);
+                    $value = preg_replace( "/\r?\n/", "<br>", $value );
+                    array_push($properties->$layerName->values[$properties->$layerName->numelements], $value);
+                    //$properties->$layerName->values[$properties->$layerName->numelements][$propname] = $value;
+                }
+            }
+            $properties->$layerName->numelements= $properties->$layerName->numelements+1;
+        }
+    }
+    return $properties;
+}
+
 function getUtmWkt($lon, $lat) {
     $siteVersion = explode(".",GetSiteVersion());
     if ((integer)$siteVersion[0] > 2 || (integer)$siteVersion[0] == 2 && (integer)$siteVersion[1] > 0) {  //v2.1.x or greater



More information about the fusion-commits mailing list