[fusion-commits] r2636 - in sandbox/adsk/2.3r.sce/layers/MapGuide: . php

svn_fusion at osgeo.org svn_fusion at osgeo.org
Sun Jan 27 22:05:36 PST 2013


Author: liuar
Date: 2013-01-27 22:05:35 -0800 (Sun, 27 Jan 2013)
New Revision: 2636

Modified:
   sandbox/adsk/2.3r.sce/layers/MapGuide/MapGuide.js
   sandbox/adsk/2.3r.sce/layers/MapGuide/php/GetSelectionProperties.php
   sandbox/adsk/2.3r.sce/layers/MapGuide/php/SaveSelection.php
Log:
Submit on behalf of Andy Zhang

This is special submission only for SCE customer. SCE uses Teradata database and encounters significant performance issue especially when selecting features. After investigation, we found that Teradata has performance issue when processing long SQL statements. When selecting features, the SQL statement is like 'SELECT col1, col2, ... FROM table WHERE key=xxx OR key=yyy OR ...'. If we select a large dataset, there might be thousands of ORs in the SQL statement. The performance is very bad in this case. 

Therefore, we create a special hotfix for Teradata. We still use SQL 'SELECT col1, col2, ... FROM table WHERE geomCondition' to render the selection image and fill out the selection panel. The APIs SelectionBase::SetGeometry() and SelectionBase::GetGeometry() are added. If the web-tier side code sets the geometry filter of the selection, Sever side will parse this geometry filter and generate SQL statement according to the geometry filter. Then the SQL statement will not be too long. This change improves Teradata's selection performance significantly in my test. The time of selecting 10,000 features is from 8m to 50s. 

We created a new branch 2.3r.sce for this change. All the related code are submitted to this new branch. The changes will not impact other users.


Modified: sandbox/adsk/2.3r.sce/layers/MapGuide/MapGuide.js
===================================================================
--- sandbox/adsk/2.3r.sce/layers/MapGuide/MapGuide.js	2013-01-28 03:04:24 UTC (rev 2635)
+++ sandbox/adsk/2.3r.sce/layers/MapGuide/MapGuide.js	2013-01-28 06:05:35 UTC (rev 2636)
@@ -799,26 +799,26 @@
      * Updates the current map selection with the provided XML selection string.
      * Optionally zooms to the new selection on the map, if zoomTo is set to true.
      */
-    setSelection: function (selText, zoomTo) {
+    setSelection: function (selText, zoomTo, geometry) {
 
         //TODO Update this.previousSelection when the selection is set using
         //this API to allow the selection to be extended with a shift-click.
 
         if(selText != "" && selText != null) {
-            this.updateSelection(selText, zoomTo, false);
+            this.updateSelection(selText, zoomTo, false, geometry);
         }
         else {
             this.clearSelection();
         }
     },
 
-    updateSelection: function (selText, zoomTo, extendSelection) {
-        this.updateMapSelection(selText, zoomTo);
-        this.getSelectedFeatureProperties(selText);
+    updateSelection: function (selText, zoomTo, extendSelection, geometry) {
+        this.updateMapSelection(selText, zoomTo, geometry);
+        this.getSelectedFeatureProperties(selText, geometry);
     },
 
 
-    getSelectedFeatureProperties: function (selText) {
+    getSelectedFeatureProperties: function (selText, geometry) {
       this.mapWidget._addWorker();
       var sl = Fusion.getScriptLanguage();
       var getPropertiesScript = 'layers/' + this.arch + '/' + sl  + '/GetSelectionProperties.' + sl;
@@ -826,14 +826,15 @@
           'mapname': this.getMapName(),
           'session': this.getSessionID(),
           'selection': selText,
-          'seq': Math.random()
+          'seq': Math.random(),
+          'geometry': geometry
       };
       var options = {onSuccess: OpenLayers.Function.bind(this.processSelectedFeatureProperties, this),
                      parameters:params};
       Fusion.ajaxRequest(getPropertiesScript, options);
     },
 
-    updateMapSelection: function (selText, zoomTo) {
+    updateMapSelection: function (selText, zoomTo, geometry) {
       this.mapWidget._addWorker();
       var sl = Fusion.getScriptLanguage();
       var updateSelectionScript = 'layers/' + this.arch + '/' + sl  + '/SaveSelection.' + sl;
@@ -842,7 +843,8 @@
           'session': this.getSessionID(),
           'selection': selText,
           'seq': Math.random(),
-          'getextents' : zoomTo ? 'true' : 'false'
+          'getextents' : zoomTo ? 'true' : 'false',
+          'geometry': geometry
       };
       var options = {onSuccess: OpenLayers.Function.bind(this.renderSelection, this, zoomTo),
                      parameters:params};
@@ -1052,7 +1054,7 @@
                                                                 options.filter,
                                                                 options.layers,
                                                                 layerAttributeFilter);
-        var callback = (options.extendSelection == true) ? OpenLayers.Function.bind(this.processAndMergeFeatureInfo, this) : OpenLayers.Function.bind(this.processFeatureInfo, this);
+        var callback = (options.extendSelection == true) ? OpenLayers.Function.bind(this.processAndMergeFeatureInfo, this) : OpenLayers.Function.bind(this.processFeatureInfo, this, options.geometry);
         Fusion.oBroker.dispatchRequest(r, OpenLayers.Function.bind(Fusion.xml2json, this, callback));
     },
 
@@ -1063,7 +1065,8 @@
             this.drawMap();
         }
         if (this.queryLayer) {
-            this.queryLayer.setVisibility(true);
+            //this.queryLayer.setVisibility(true);
+            this.drawSelection();
         }
     },
 
@@ -1074,7 +1077,8 @@
             this.drawMap();
         }
         if (this.queryLayer) {
-            this.queryLayer.setVisibility(false);
+            //this.queryLayer.setVisibility(false);
+            this.drawSelection();
         }
     },
 
@@ -1096,7 +1100,8 @@
             }
         }
         if (this.queryLayer) {
-            this.queryLayer.setVisibility(true);
+            //this.queryLayer.setVisibility(true);
+            this.drawSelection();
         }
     },
     hideGroup: function( group, noDraw ) {
@@ -1117,7 +1122,8 @@
             }
         }
         if (this.queryLayer) {
-            this.queryLayer.setVisibility(false);
+            //this.queryLayer.setVisibility(false);
+            this.drawSelection();
         }
     },
     refreshLayer: function( layer ) {
@@ -1318,14 +1324,14 @@
 
 
     processAndMergeFeatureInfo: function (r) {
-        this.processSelectedFeatureInfo(r, true);
+        this.processSelectedFeatureInfo(r, true, "");
     },
 
-    processFeatureInfo: function (r) {
-        this.processSelectedFeatureInfo(r, false);
+    processFeatureInfo: function (geometry, r) {
+        this.processSelectedFeatureInfo(r, false, geometry);
     },
 
-    processSelectedFeatureInfo: function (r, mergeSelection) {
+    processSelectedFeatureInfo: function (r, mergeSelection, geometry) {
         eval('o='+r.responseText);
 
         var newSelection = new Fusion.SimpleSelectionObject(o);
@@ -1336,7 +1342,7 @@
         this.previousSelection = newSelection;
 
         var selText = newSelection.getSelectionXml();
-        this.setSelection(selText, false);
+        this.setSelection(selText, false, geometry);
         this.mapWidget._removeWorker();
     }
 

Modified: sandbox/adsk/2.3r.sce/layers/MapGuide/php/GetSelectionProperties.php
===================================================================
--- sandbox/adsk/2.3r.sce/layers/MapGuide/php/GetSelectionProperties.php	2013-01-28 03:04:24 UTC (rev 2635)
+++ sandbox/adsk/2.3r.sce/layers/MapGuide/php/GetSelectionProperties.php	2013-01-28 06:05:35 UTC (rev 2636)
@@ -34,6 +34,7 @@
 include('Utilities.php');
 
     $selText = "";
+    $geometry = "";
     GetRequestParameters();
 
     try
@@ -90,19 +91,41 @@
                 }
             }
 
+            $srsLayer = NULL;
+            $spatialContext = $featureService->GetSpatialContexts($featureResId, true);
+            $srsLayerWkt = NULL;
+            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);
+            $trans = $srsFactory->GetTransform($srsMap, $srsLayer);
+            if ($geometry != "") {
+                $wktReader = new MgWktReaderWriter();
+                $geom = $wktReader->Read($geometry, $trans);
+            }
+
             //Add geometry property in all cases.
             $geomName = $oLayer->GetFeatureGeometryName();
             $queryOptions->AddFeatureProperty($geomName);
+            if ($geometry != "") {
+                $queryOptions->SetSpatialFilter($geomName, $geom, MgFeatureSpatialOperations::Intersects);
+                $layerFilter = $oLayer->GetFilter();
+                if ($layerFilter != "") {
+                    $queryOptions->SetFilter($layerFilter);
+                }
+            }
+            else {
+                $filter = $selection->GenerateFilter($oLayer, $class);
+                $queryOptions->SetFilter($filter);
+            }
 
-            $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
+            $featureReader = NULL;
+            $featureReader = $featureService->SelectFeatures($featureResId, $class, $queryOptions);
 
             $layerName = $oLayer->GetName();
             array_push($properties->layers, $layerName);
@@ -111,20 +134,7 @@
             $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);
-
+            if ($bComputedProperties) {
                 // exclude layer if:
                 //  the map is non-arbitrary and the layer is arbitrary or vice-versa
                 //     or
@@ -142,12 +152,10 @@
                 }
             }
 
-            $properties = BuildSelectionArrayEx($featureReaders, $layerName, $properties,
+            $properties = BuildSelectionArray($featureReader, $layerName, $properties,
                                               $bComputedProperties,
                                              $srsLayer, $bNeedsTransform, $oLayer);
-            foreach ($featureReaders as $featureReader) {
-                $featureReader->Close();
-            }
+            $featureReader->Close();
         }
 
         $result = NULL;
@@ -186,8 +194,6 @@
             $_SESSION['selection_array'] = $properties;
         }
         echo var2json($result);
-
-
     } catch(MgException $e) {
         echo "ERROR: " . $e->GetDetails() . "\n";
     }
@@ -195,8 +201,10 @@
 function GetParameters($params)
 {
     global $selText;
+    global $geometry;
 
     $selText = UnescapeMagicQuotes($params['selection']);
+    $geometry = UnescapeMagicQuotes($params['geometry']);
 }
 
 

Modified: sandbox/adsk/2.3r.sce/layers/MapGuide/php/SaveSelection.php
===================================================================
--- sandbox/adsk/2.3r.sce/layers/MapGuide/php/SaveSelection.php	2013-01-28 03:04:24 UTC (rev 2635)
+++ sandbox/adsk/2.3r.sce/layers/MapGuide/php/SaveSelection.php	2013-01-28 06:05:35 UTC (rev 2636)
@@ -34,6 +34,7 @@
 include('Utilities.php');
 
     $selText = "";
+    $geometry = "";
     $getExtents = false;
 
     GetRequestParameters();
@@ -49,6 +50,9 @@
         if($selText != "") {
             $selection->FromXml($selText);
         }
+        if ($geometry != "") {
+            $selection->SetGeometry($geometry);
+        }
         $selection->Save($resourceService, $mapName);
 
         //now return a data struture which is the same as Query.php
@@ -100,9 +104,11 @@
 {
     global $selText;
     global $getExtents;
+    global $geometry;
 
     $selText = UnescapeMagicQuotes($params['selection']);
     $getExtents = ($params['getextents'] == "true") ? true : false;
+    $geometry = UnescapeMagicQuotes($params['geometry']);
 }
 
 



More information about the fusion-commits mailing list