[fusion-commits] r2677 - sandbox/adsk/2.4j/layers/MapGuide/php

svn_fusion at osgeo.org svn_fusion at osgeo.org
Mon Mar 25 00:59:46 PDT 2013


Author: liuar
Date: 2013-03-25 00:59:45 -0700 (Mon, 25 Mar 2013)
New Revision: 2677

Modified:
   sandbox/adsk/2.4j/layers/MapGuide/php/Constants.php
   sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php
   sandbox/adsk/2.4j/layers/MapGuide/php/Utilities.php
Log:
Submit on behalf of Andy Zhang

Revert change #2631 since it degrades performance a lot.

Modified: sandbox/adsk/2.4j/layers/MapGuide/php/Constants.php
===================================================================
--- sandbox/adsk/2.4j/layers/MapGuide/php/Constants.php	2013-03-25 03:52:08 UTC (rev 2676)
+++ sandbox/adsk/2.4j/layers/MapGuide/php/Constants.php	2013-03-25 07:59:45 UTC (rev 2677)
@@ -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: sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php
===================================================================
--- sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php	2013-03-25 03:52:08 UTC (rev 2676)
+++ sandbox/adsk/2.4j/layers/MapGuide/php/GetSelectionProperties.php	2013-03-25 07:59:45 UTC (rev 2677)
@@ -60,7 +60,6 @@
         /*holds selection array*/
         $properties = NULL;
         $properties->layers = array();
-        $properties->envelope = NULL;
 
         //process
         header('Content-type: application/json');
@@ -81,73 +80,66 @@
             //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()];
-                if (count($mappings) > 0) {
+                $mappings = $_SESSION['property_mappings'][$oLayer->GetObjectId()];                
+				if (count($mappings) > 0) {
                     foreach($mappings as $name => $value) {
                         $queryOptions->AddFeatureProperty($name);
                         //echo "$name $value <br>\n";
                     }
                 }
             }
+			
+			//Add geometry property in all cases.
+			$geomName = $oLayer->GetFeatureGeometryName();
+			$queryOptions->AddFeatureProperty($geomName);
 
-            //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 +147,7 @@
         if ($layers && $layers->GetCount() >= 0)
         {
             $result->hasSelection = true;
-            $oExtents = $properties->envelope;
+            $oExtents = $selection->GetExtents($featureService);
             if ($oExtents)
             {
                 $oMin = $oExtents->GetLowerLeftCoordinate();

Modified: sandbox/adsk/2.4j/layers/MapGuide/php/Utilities.php
===================================================================
--- sandbox/adsk/2.4j/layers/MapGuide/php/Utilities.php	2013-03-25 03:52:08 UTC (rev 2676)
+++ sandbox/adsk/2.4j/layers/MapGuide/php/Utilities.php	2013-03-25 07:59:45 UTC (rev 2677)
@@ -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