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

svn_fusion at osgeo.org svn_fusion at osgeo.org
Thu Feb 21 16:28:59 PST 2013


Author: liuar
Date: 2013-02-21 16:28:59 -0800 (Thu, 21 Feb 2013)
New Revision: 2643

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.

This submission is refines change list #2632 which implemented ticket #2193. 
In previous change #2632, I updated the web side PHP files to Use API MgSelectionBase::GenerateFilters instead of MgSelectionBase::GenerateFilter to avoid the filter text exceed the SQL length limit. We find the performance of 'select features' degrades a lot when selecting many features after this change. The reason is that previous change results in multiple DB queries + multiple request/response traffic between Web Server and Map Server, which will impact the performance a lot. 
Because the case that 'filter text exceed the SQL length limit' only happens when the PK of a feature class has more than one columns, and now most databases support very long SQL statement (actually only one customer reported this issue until now), we decide to partially revert the change #2632 to still uses API GenerateFilter in the PHP files. 



Modified: trunk/layers/MapGuide/php/Constants.php
===================================================================
--- trunk/layers/MapGuide/php/Constants.php	2013-02-20 07:00:22 UTC (rev 2642)
+++ trunk/layers/MapGuide/php/Constants.php	2013-02-22 00:28:59 UTC (rev 2643)
@@ -1871,13 +1871,4 @@
    
 }
 
-////////////////////////////////////////////////////////////////////////////////
-/// <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-02-20 07:00:22 UTC (rev 2642)
+++ trunk/layers/MapGuide/php/GetSelectionProperties.php	2013-02-22 00:28:59 UTC (rev 2643)
@@ -60,7 +60,6 @@
         /*holds selection array*/
         $properties = NULL;
         $properties->layers = array();
-        $properties->envelope = NULL;
 
         //process
         header('Content-type: application/json');
@@ -76,7 +75,7 @@
 
             /* select the features */
             $queryOptions = new MgFeatureQueryOptions();
-
+            $geomName = $oLayer->GetFeatureGeometryName();
             //TODO : seems that property mapping breaks the selection ????
             //could it be that $selection->AddFeatures($layerObj, $featureReader, 0) is
             //the one causing a problem when the properies are limited ?
@@ -84,70 +83,64 @@
                 $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];
                 if (count($mappings) > 0) {
                     foreach($mappings as $name => $value) {
-                        $queryOptions->AddFeatureProperty($name);
-                        //echo "$name $value <br>\n";
+                        if ($geomName != $name) {
+                            $queryOptions->AddFeatureProperty($name);
+                            //echo "$name $value <br>\n";
+                        }
                     }
                 }
             }
 
             //Add geometry property in all cases.
-            $geomName = $oLayer->GetFeatureGeometryName();
             $queryOptions->AddFeatureProperty($geomName);
 
-            $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);
-            }
+            $filter = $selection->GenerateFilter($oLayer, $class);
+            $queryOptions->SetFilter($filter);
+            $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
             //$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 = BuildSelectionArrayEx($featureReaders, $layerName, $properties,
+            $properties = BuildSelectionArray($featureReader, $layerName, $properties,
                                               $bComputedProperties,
                                               $srsLayer, $bNeedsTransform, $oLayer, true);
-            foreach ($featureReaders as $featureReader) {
-                $featureReader->Close();
-            }
+            $featureReader->Close();
         }
 
         $result = NULL;
@@ -155,7 +148,7 @@
         if ($layers && $layers->GetCount() >= 0)
         {
             $result->hasSelection = true;
-            $oExtents = $properties->envelope;
+            $oExtents = $selection->GetExtents($featureService);
             if ($oExtents)
             {
                 $oMin = $oExtents->GetLowerLeftCoordinate();

Modified: trunk/layers/MapGuide/php/Utilities.php
===================================================================
--- trunk/layers/MapGuide/php/Utilities.php	2013-02-20 07:00:22 UTC (rev 2642)
+++ trunk/layers/MapGuide/php/Utilities.php	2013-02-22 00:28:59 UTC (rev 2643)
@@ -891,154 +891,6 @@
     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