[mapguide-commits] r8268 - in sandbox/jng/convenience_apis: Common/MapGuideCommon/MapLayer Common/PlatformBase/MapLayer UnitTest/WebTier/DotNet/TestCommon/ExternalTests

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jun 27 03:24:46 PDT 2014


Author: jng
Date: 2014-06-27 03:24:46 -0700 (Fri, 27 Jun 2014)
New Revision: 8268

Modified:
   sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp
   sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h
   sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.cpp
   sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.h
   sandbox/jng/convenience_apis/UnitTest/WebTier/DotNet/TestCommon/ExternalTests/ConvenienceTests.cs
Log:
Add SelectFeatures with coordinate system option to MgLayerBase. .net test case included.

Modified: sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp
===================================================================
--- sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp	2014-06-27 09:35:56 UTC (rev 8267)
+++ sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.cpp	2014-06-27 10:24:46 UTC (rev 8268)
@@ -285,6 +285,23 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 /// \brief
+/// Selects features from a feature source according to the
+/// criteria set in the MgFeatureQueryOptions argument The
+/// criteria are applied to all of the features in the feature
+/// source. If you want to apply the criteria to a subset of the
+/// features, use the MgFeatureService::SelectAggregate Method.
+///
+MgFeatureReader* MgLayer::SelectFeatures(MgFeatureQueryOptions* options, CREFSTRING coordinateSystem)
+{
+    Ptr<MgFeatureService> featureService = dynamic_cast<MgFeatureService*>(
+        GetMap()->GetService(MgServiceType::FeatureService));
+    Ptr<MgResourceIdentifier> resourceId = new MgResourceIdentifier(m_featureSourceId);
+
+    return featureService->SelectFeatures(resourceId, m_featureName, options, coordinateSystem);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief
 /// Selects groups of features from a feature source and applies
 /// filters to each of the groups according to the criteria set
 /// in the MgFeatureAggregateOptions argument. If you want to

Modified: sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h
===================================================================
--- sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h	2014-06-27 09:35:56 UTC (rev 8267)
+++ sandbox/jng/convenience_apis/Common/MapGuideCommon/MapLayer/Layer.h	2014-06-27 10:24:46 UTC (rev 8268)
@@ -131,6 +131,44 @@
 
     //////////////////////////////////////////////////////////////////
     /// \brief
+    /// Selects features from a feature source according to the
+    /// criteria set in the MgFeatureQueryOptions argument The
+    /// criteria are applied to all of the features in the feature
+    /// source. If you want to apply the criteria to a subset of the
+    /// features, use the \link MgFeatureService::SelectAggregate MgFeatureService::SelectAggregate Method \endlink.
+    /// See \link FiltersAndExpressions Filters and expressions \endlink.
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgFeatureReader SelectFeatures(MgFeatureQueryOptions options);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgFeatureReader SelectFeatures(MgFeatureQueryOptions options);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgFeatureReader SelectFeatures(MgFeatureQueryOptions options);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param options (MgFeatureQueryOptions)
+    /// MgFeatureQueryOptions instance
+    /// containing all required filters for this
+    /// select operation.
+    /// \param coordinateSystem (String/string)
+    /// The coordinate system to transform features to
+    ///
+    /// \return
+    /// Returns an MgFeatureReader containing the set of selected
+    /// features.
+    ///
+    /// \exception MgFeatureServiceException
+    /// \exception MgInvalidArgumentException
+    /// \exception MgFdoException
+    ///
+    /// \since 3.0
+    virtual MgFeatureReader* SelectFeatures(MgFeatureQueryOptions* options, CREFSTRING coordinateSystem);
+
+    //////////////////////////////////////////////////////////////////
+    /// \brief
     /// Selects groups of features from a feature source and applies
     /// filters to each of the groups according to the criteria set
     /// in the MgFeatureAggregateOptions argument. If you want to

Modified: sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.cpp
===================================================================
--- sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.cpp	2014-06-27 09:35:56 UTC (rev 8267)
+++ sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.cpp	2014-06-27 10:24:46 UTC (rev 8268)
@@ -776,6 +776,20 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 /// \brief
+/// Selects features from a feature source according to the
+/// criteria set in the MgFeatureQueryOptions argument The
+/// criteria are applied to all of the features in the feature
+/// source. If you want to apply the criteria to a subset of the
+/// features, use the MgFeatureService::SelectAggregate Method.
+///
+MgFeatureReader* MgLayerBase::SelectFeatures(MgFeatureQueryOptions* options, CREFSTRING coordinateSystem)
+{
+    throw new MgNotImplementedException(L"MgLayerBase.SelectFeatures",
+        __LINE__, __WFILE__, NULL, L"", NULL);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// \brief
 /// Selects groups of features from a feature source and applies
 /// filters to each of the groups according to the criteria set
 /// in the MgFeatureAggregateOptions argument. If you want to

Modified: sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.h
===================================================================
--- sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.h	2014-06-27 09:35:56 UTC (rev 8267)
+++ sandbox/jng/convenience_apis/Common/PlatformBase/MapLayer/LayerBase.h	2014-06-27 10:24:46 UTC (rev 8268)
@@ -779,6 +779,44 @@
 
     //////////////////////////////////////////////////////////////////
     /// \brief
+    /// Selects features from a feature source according to the
+    /// criteria set in the MgFeatureQueryOptions argument The
+    /// criteria are applied to all of the features in the feature
+    /// source. If you want to apply the criteria to a subset of the
+    /// features, use the \link MgFeatureService::SelectAggregate MgFeatureService::SelectAggregate Method \endlink.
+    /// See \link FiltersAndExpressions Filters and expressions \endlink.
+    ///
+    /// <!-- Syntax in .Net, Java, and PHP -->
+    /// \htmlinclude DotNetSyntaxTop.html
+    /// virtual MgFeatureReader SelectFeatures(MgFeatureQueryOptions options);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude JavaSyntaxTop.html
+    /// virtual MgFeatureReader SelectFeatures(MgFeatureQueryOptions options);
+    /// \htmlinclude SyntaxBottom.html
+    /// \htmlinclude PHPSyntaxTop.html
+    /// virtual MgFeatureReader SelectFeatures(MgFeatureQueryOptions options);
+    /// \htmlinclude SyntaxBottom.html
+    ///
+    /// \param options (MgFeatureQueryOptions)
+    /// MgFeatureQueryOptions instance
+    /// containing all required filters for this
+    /// select operation.
+    /// \param coordinateSystem (String/string)
+    /// The coordinate system to transform features to
+    ///
+    /// \return
+    /// Returns an MgFeatureReader containing the set of selected
+    /// features.
+    ///
+    /// \exception MgFeatureServiceException
+    /// \exception MgInvalidArgumentException
+    /// \exception MgFdoException
+    ///
+    /// \since 3.0
+    virtual MgFeatureReader* SelectFeatures(MgFeatureQueryOptions* options, CREFSTRING coordinateSystem);
+
+    //////////////////////////////////////////////////////////////////
+    /// \brief
     /// Selects groups of features from a feature source and applies
     /// filters to each of the groups according to the criteria set
     /// in the MgFeatureAggregateOptions argument. If you want to

Modified: sandbox/jng/convenience_apis/UnitTest/WebTier/DotNet/TestCommon/ExternalTests/ConvenienceTests.cs
===================================================================
--- sandbox/jng/convenience_apis/UnitTest/WebTier/DotNet/TestCommon/ExternalTests/ConvenienceTests.cs	2014-06-27 09:35:56 UTC (rev 8267)
+++ sandbox/jng/convenience_apis/UnitTest/WebTier/DotNet/TestCommon/ExternalTests/ConvenienceTests.cs	2014-06-27 10:24:46 UTC (rev 8268)
@@ -565,4 +565,116 @@
         }
     }
 
+    public class LayerSelectFeaturesWithTransform : IExternalTest
+    {
+        public void Execute(IPlatformFactory factory, ITestLogger logger)
+        {
+            var featSvc = (MgFeatureService)factory.CreateService(MgServiceType.FeatureService);
+            var resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);
+
+            //Create our test data store
+            MgFeatureSchema fs = new MgFeatureSchema("Default", "");
+            MgClassDefinition cls = new MgClassDefinition();
+            cls.SetName("Test");
+
+            MgDataPropertyDefinition id = new MgDataPropertyDefinition("ID");
+            id.SetAutoGeneration(true);
+            id.SetDataType(MgPropertyType.Int32);
+
+            MgGeometricPropertyDefinition geom = new MgGeometricPropertyDefinition("Geometry");
+            geom.SetGeometryTypes(MgFeatureGeometricType.Point);
+            geom.SetSpatialContextAssociation("Default");
+
+            MgPropertyDefinitionCollection props = cls.GetProperties();
+            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
+
+            props.Add(id);
+            props.Add(geom);
+            idProps.Add(id);
+
+            cls.SetDefaultGeometryPropertyName("Geometry");
+            MgClassDefinitionCollection classes = fs.GetClasses();
+            classes.Add(cls);
+
+            //We'll use a transform guaranteed to work. ArbitraryXY (unitA to unitB)
+            //We just check that the transformed values are not the original, that way
+            //we know that CS-Map did its job
+            MgCoordinateSystemFactory csFact = new MgCoordinateSystemFactory();
+            string srcWkt = csFact.ConvertCoordinateSystemCodeToWkt("XY-M");
+            string dstWkt = csFact.ConvertCoordinateSystemCodeToWkt("XY-IN");
+
+            MgGeometryFactory geomFact = new MgGeometryFactory();
+            MgAgfReaderWriter agfRw = new MgAgfReaderWriter();
+            MgFileFeatureSourceParams create = new MgFileFeatureSourceParams("OSGeo.SDF", "Default", srcWkt, fs);
+            MgResourceIdentifier fsId = new MgResourceIdentifier("Library://UnitTests/Data/TransformTest.FeatureSource");
+            featSvc.CreateFeatureSource(fsId, create);
+
+            MgMapBase map = factory.CreateMap(srcWkt, new MgEnvelope(-180, -90, 180, 90), "TestMap");
+            MgLayerCollection layers = map.GetLayers();
+
+            string layerXml = string.Format(Properties.Resources.TestLayer, fsId.ToString(), "Default:Test", "Geometry");
+            byte[] bytes = Encoding.UTF8.GetBytes(layerXml);
+            MgByteSource bs = new MgByteSource(bytes, bytes.Length);
+            MgByteReader br = bs.GetReader();
+
+            var ldfId = new MgResourceIdentifier("Library://UnitTests/Layers/TestLayer.LayerDefinition");
+            resSvc.SetResource(ldfId, br, null);
+
+            MgLayerBase layer = factory.CreateLayer(ldfId);
+            layers.Insert(0, layer);
+
+            //Populate data store with test points
+
+            MgCoordinate coord1 = geomFact.CreateCoordinateXY(-37.1020, 144.0020);
+            MgPoint pt1 = geomFact.CreatePoint(coord1);
+            MgByteReader agf1 = agfRw.Write(pt1);
+
+            MgPropertyCollection propVals = new MgPropertyCollection();
+            MgGeometryProperty pGeom = new MgGeometryProperty("Geometry", agf1);
+            propVals.Add(pGeom);
+
+            MgFeatureReader fr = layer.InsertFeatures(propVals);
+            fr.Close();
+
+            MgCoordinate coord2 = geomFact.CreateCoordinateXY(-37.2020, 144.2020);
+            MgPoint pt2 = geomFact.CreatePoint(coord2);
+            MgByteReader agf2 = agfRw.Write(pt2);
+
+            pGeom.SetValue(agf2);
+            fr = layer.InsertFeatures(propVals);
+            fr.Close();
+
+            //Now select from this data store
+            MgFeatureQueryOptions query = new MgFeatureQueryOptions();
+            MgReader reader = layer.SelectFeatures(query, dstWkt);
+
+            Assert.IsTrue(reader.ReadNext());
+            Assert.IsTrue(!reader.IsNull("Geometry"));
+
+            MgByteReader txAgf1 = reader.GetGeometry("Geometry");
+            MgGeometry txGeom1 = agfRw.Read(txAgf1);
+            MgPoint txPt1 = (MgPoint)txGeom1;
+            Assert.IsTrue(txPt1 != null);
+            MgCoordinate txCoord1 = txPt1.GetCoordinate();
+
+            //TODO: Maybe we should really check that it matches the expected transformed result
+            Assert.IsTrue(txCoord1.GetX() != -37.1020);
+            Assert.IsTrue(txCoord1.GetY() != 144.0020);
+
+            Assert.IsTrue(reader.ReadNext());
+            Assert.IsTrue(!reader.IsNull("Geometry"));
+
+            MgByteReader txAgf2 = reader.GetGeometry("Geometry");
+            MgGeometry txGeom2 = agfRw.Read(txAgf2);
+            MgPoint txPt2 = (MgPoint)txGeom2;
+            Assert.IsTrue(txPt2 != null);
+            MgCoordinate txCoord2 = txPt2.GetCoordinate();
+
+            //TODO: Maybe we should really check that it matches the expected transformed result
+            Assert.IsTrue(txCoord2.GetX() != -37.2020);
+            Assert.IsTrue(txCoord2.GetY() != 144.2020);
+
+            reader.Close();
+        }
+    }
 }



More information about the mapguide-commits mailing list