[mapguide-commits] r7259 - in sandbox/adsk/2.3r: Common/PlatformBase/MapLayer Web/src/mapviewernet

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Dec 11 21:30:47 PST 2012


Author: hubu
Date: 2012-12-11 21:30:47 -0800 (Tue, 11 Dec 2012)
New Revision: 7259

Modified:
   sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.cpp
   sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.h
   sandbox/adsk/2.3r/Web/src/mapviewernet/getselectedfeatures.aspx
Log:
Submit on behalf of Andy Zhang
Implement ticket http://trac.osgeo.org/mapguide/ticket/2193

There is a publish Api MgSelectionBase::GenerateFilter(MgLayerBase* layer, CREFSTRING className) in class MgSelectBase, which generates a Fdo filter text for the selections of the specified layer and class. If the key of the layer has more than one column e.g. K1 and K2, the generated filter text is like '(K1=xxx AND K2=xxx) OR (K1=xxx AND K2=xxx) OR ...'. This kind of fitler text cannot be broken into small pieces by MgSelectCommand. If the selection set is very big, it is possible that the generated filter text exceed the max length of Sql statement. 
So now we make the method MgSelectionBase::GenerateFilters(MgLayerBase* layer, CREFSTRING className, INT32 selectionSize) to be a published Api. The caller (php, asp from web-tier side) can use this method to get several smaller filter text of a selection to avoid the filter text exceed the length limit. 

This submission also updated Web/src/mapviewernet/getselectedfeatures.aspx to use the new API to get selection properties.

Modified: sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.cpp
===================================================================
--- sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.cpp	2012-12-12 03:15:05 UTC (rev 7258)
+++ sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.cpp	2012-12-12 05:30:47 UTC (rev 7259)
@@ -816,17 +816,22 @@
             STRING clsName = layer->GetFeatureClassName();
             STRING geomName = layer->GetFeatureGeometryName();
 
-            STRING filterText = this->GenerateFilter(layer, clsName);
+            Ptr<MgStringCollection> filters = GenerateFilters(layer, clsName, 30000 /* magic number */);
+            INT32 numFilter = (NULL == filters)? 0 : filters->GetCount();
 
-            Ptr<MgEnvelope> clsEnv = GetFeatureExtents(featureService, featureResId, clsName, filterText, geomName);
-            if (env != NULL)
+            for (INT32 j = 0; j < numFilter; ++j)
             {
-                env->ExpandToInclude(clsEnv);
+                STRING filterText = filters->GetItem(j);
+                Ptr<MgEnvelope> clsEnv = GetFeatureExtents(featureService, featureResId, clsName, filterText, geomName);
+                if (env != NULL)
+                {
+                    env->ExpandToInclude(clsEnv);
+                }
+                else
+                {
+                    env = clsEnv.Detach();
+                }
             }
-            else
-            {
-                env = clsEnv.Detach();
-            }
         }
     }
     return env.Detach();

Modified: sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.h
===================================================================
--- sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.h	2012-12-12 03:15:05 UTC (rev 7258)
+++ sandbox/adsk/2.3r/Common/PlatformBase/MapLayer/SelectionBase.h	2012-12-12 05:30:47 UTC (rev 7259)
@@ -393,6 +393,27 @@
     ///
     STRING GenerateFilter(MgLayerBase* layer, CREFSTRING className);
 
+    //////////////////////////////////////////////////////////////////
+    /// \brief
+    /// Generates a collection of FDO filter strings for the selections
+    /// of the specified layer and class
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// string GenerateFilters(MgLayerBase layer, string className, int selectionSize);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// String GenerateFilters(MgLayerBase layer, String className, int selectionSize);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// string GenerateFilters(MgLayerBase layer, string className, int selectionSize);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \return
+    /// Returns the collection of FDO filter strings
+    ///
+    MgStringCollection* GenerateFilters(MgLayerBase* layer, CREFSTRING className, INT32 selectionSize);
+
     ///////////////////////////////////////////////////////////////////////////
     /// \brief
     /// Gets the extents of the selection set.
@@ -518,16 +539,6 @@
 
     //////////////////////////////////////////////////////////////////
     /// \brief
-    /// Generate a collection of FDO filter strings for the selections
-    /// of the specified layer and class.
-    ///
-    /// \return
-    /// Collection of FDO filter strings.
-    ///
-    MgStringCollection* GenerateFilters(MgLayerBase* layer, CREFSTRING className, INT32 selectionSize);
-
-    //////////////////////////////////////////////////////////////////
-    /// \brief
     /// Serialize data to a stream
     ///
     /// \param stream

Modified: sandbox/adsk/2.3r/Web/src/mapviewernet/getselectedfeatures.aspx
===================================================================
--- sandbox/adsk/2.3r/Web/src/mapviewernet/getselectedfeatures.aspx	2012-12-12 03:15:05 UTC (rev 7258)
+++ sandbox/adsk/2.3r/Web/src/mapviewernet/getselectedfeatures.aspx	2012-12-12 05:30:47 UTC (rev 7259)
@@ -81,6 +81,7 @@
     String sessionId;
     String locale;
     CultureInfo culture;
+    const int RenderSelectionBatchSize = 30000; /* default filter size */
 
     static NameValueCollection GetLayerPropertyMappings(MgResourceService resSvc, MgLayerBase layer)
     {
@@ -307,64 +308,68 @@
                 }
 
                 query.AddFeatureProperty(geomName);
-                String filter = selection.GenerateFilter(layer, className);
-                query.SetFilter(filter);
+                MgStringCollection filters = selection.GenerateFilters(layer, className, RenderSelectionBatchSize);
+                for (int j = 0; j < filters.GetCount(); j++)
+                {
+                    String filter = filters.GetItem(j);
+                    query.SetFilter(filter);
 
-                MgFeatureReader reader = layer.SelectFeatures(query);
+                    MgFeatureReader reader = layer.SelectFeatures(query);
 
-                MgClassDefinition clsDef = reader.GetClassDefinition();
-                MgPropertyDefinitionCollection props = clsDef.GetProperties();
+                    MgClassDefinition clsDef = reader.GetClassDefinition();
+                    MgPropertyDefinitionCollection props = clsDef.GetProperties();
 
-                while (reader.ReadNext())
-                {
-                    Feature feat = new Feature(layerName);
-                    ZoomPoint zoom = null;
-
-                    for (int k = 0; k < props.Count; k++)
+                    while (reader.ReadNext())
                     {
-                        MgPropertyDefinition propDef = props[k];
-                        String propName = propDef.Name;
-                        int propType = reader.GetPropertyType(propName);
+                        Feature feat = new Feature(layerName);
+                        ZoomPoint zoom = null;
 
-                        if (mappings[propName] != null || propType == MgPropertyType.Geometry)
+                        for (int k = 0; k < props.Count; k++)
                         {
-                            String value = "";
-                            if (!reader.IsNull(propName))
+                            MgPropertyDefinition propDef = props[k];
+                            String propName = propDef.Name;
+                            int propType = reader.GetPropertyType(propName);
+
+                            if (mappings[propName] != null || propType == MgPropertyType.Geometry)
                             {
-                                if (propName == geomName)
+                                String value = "";
+                                if (!reader.IsNull(propName))
                                 {
-                                    MgByteReader agf = reader.GetGeometry(propName);
-                                    MgGeometry geom = agfRW.Read(agf);
+                                    if (propName == geomName)
+                                    {
+                                        MgByteReader agf = reader.GetGeometry(propName);
+                                        MgGeometry geom = agfRW.Read(agf);
 
-                                    MgEnvelope env = geom.Envelope();
-                                    MgCoordinate ll = env.GetLowerLeftCoordinate();
-                                    MgCoordinate ur = env.GetUpperRightCoordinate();
+                                        MgEnvelope env = geom.Envelope();
+                                        MgCoordinate ll = env.GetLowerLeftCoordinate();
+                                        MgCoordinate ur = env.GetUpperRightCoordinate();
 
-                                    zoom = new ZoomPoint();
-                                    zoom.X = (ll.X + ur.X) / 2;
-                                    zoom.Y = (ll.Y + ur.Y) / 2;
+                                        zoom = new ZoomPoint();
+                                        zoom.X = (ll.X + ur.X) / 2;
+                                        zoom.Y = (ll.Y + ur.Y) / 2;
 
-                                    feat.Zoom = zoom;
-                                }
-                                else
-                                {
-                                    value = GetPropertyValueFromFeatureReader(reader, agfRW, propType, propName);
-                                }
+                                        feat.Zoom = zoom;
+                                    }
+                                    else
+                                    {
+                                        value = GetPropertyValueFromFeatureReader(reader, agfRW, propType, propName);
+                                    }
 
-                                if (mappings[propName] != null)
-                                {
-                                    FeatureProperty fp = new FeatureProperty();
-                                    fp.Name = mappings[propName];
-                                    fp.Value = value;
+                                    if (mappings[propName] != null)
+                                    {
+                                        FeatureProperty fp = new FeatureProperty();
+                                        fp.Name = mappings[propName];
+                                        fp.Value = value;
 
-                                    feat.AddProperty(fp);
+                                        feat.AddProperty(fp);
+                                    }
                                 }
                             }
                         }
+                        selectionSet.AddFeature(feat);
                     }
-                    selectionSet.AddFeature(feat);
+                    reader.Close();
                 }
-                reader.Close();
             }
 
             //Now output the selection set



More information about the mapguide-commits mailing list