コード例 #1
0
        public void TestFeatureClassBag()
        {
            //Arrange
            double            d;
            int               length = (int)1e3;
            List <MyFieldDef> fdefs  = new List <MyFieldDef>();

            fdefs.Add(new MyFieldDef(esriFieldType.esriFieldTypeString, "strFld"));
            fdefs.Add(new MyFieldDef(esriFieldType.esriFieldTypeDouble, "doubleFld"));
            IFieldsEdit      flds = AOUtilities.GetBareMetalFields(esriGeometryType.esriGeometryPoint, 3857, fdefs);
            List <MyFeature> pnts = new List <MyFeature>();

            for (int j = 0; j < length; ++j)
            {
                pnts.Add(new MyFeature(esriFeatureType.esriFTSimple, esriGeometryType.esriGeometryPoint, new PointClass()
                {
                    X = randomDouble(-180, 180), Y = randomDouble(-90, 90)
                }, j, new List <object>()
                {
                    j.ToString(), randomDouble(0, 100)
                }));
            }

            //Act
            using (IFeatureClassBag bag1 = new InMemoryFeatureClassBag("wname1", AOUtilities.GetInMemoryWorkspaceFactory()))
            {
                Assert.IsTrue(bag1.CreateFeatureClass("foo", flds, esriFeatureType.esriFTSimple, "Shape"));
                Assert.IsTrue(bag1.AddFeatures("foo", pnts, fdefs.Count));
                List <IFeature> ftrs = new List <IFeature>();
                foreach (var f in bag1.GetFeatures("foo", false))
                {
                    ftrs.Add(f);
                }
                object o1 = ftrs[0].get_Value(2);
                object o2 = ftrs[0].get_Value(3);

                object o3 = ftrs[length - 1].get_Value(2);
                object o4 = ftrs[length - 1].get_Value(3);

                //Assert
                Assert.IsTrue(ftrs.Count == pnts.Count);
                Assert.IsTrue(null != o1 && o1.ToString() == "0");
                Assert.IsTrue(null != o3 && o3.ToString() == "999");
                Assert.IsTrue(null != o2 && double.TryParse(o2.ToString(), out d));
                Assert.IsTrue(null != o4 && double.TryParse(o4.ToString(), out d));
                //Assert
                //The following should fall through, GetFeatures actually returns nothing instead of an IEnumerable<IFeature>
                foreach (var f in bag1.GetFeatures("bar", true))
                {
                    continue;
                }
            }


            IFeatureClassBag bag2 = new InMemoryFeatureClassBag("wname2", AOUtilities.GetInMemoryWorkspaceFactory());
            IFeatureClassBag bag3 = new InMemoryFeatureClassBag("wname3", AOUtilities.GetInMemoryWorkspaceFactory());

            bag2.Dispose();
            bag3.Dispose();
        }
コード例 #2
0
        public void FeatureClassBagRAMProfile()
        {
            //more detailed approach is necessary
            //Arrange
            //1,000,000 points will take roughly 500 MB RAM on my desktop

            /*int length = (int)1e6;
             * List<MyFeature> pnts = new List<MyFeature>();
             * for (int i = 0; i < length; ++i)
             *  pnts.Add(new MyFeature(esriFeatureType.esriFTSimple, esriGeometryType.esriGeometryPoint, new PointClass() { X = randomDouble(-180, 180), Y = randomDouble(-90, 90) }));
             */
            //Act
            for (int i = 0; i < 5; ++i)
            {
                int length            = (int)1e6;
                List <MyFeature> pnts = new List <MyFeature>();
                for (int j = 0; j < length; ++j)
                {
                    pnts.Add(new MyFeature(esriFeatureType.esriFTSimple, esriGeometryType.esriGeometryPoint, new PointClass()
                    {
                        X = randomDouble(-180, 180), Y = randomDouble(-90, 90)
                    }, j, null));
                }
                using (InMemoryFeatureClassBag bag1 = new InMemoryFeatureClassBag("wname1", AOUtilities.GetInMemoryWorkspaceFactory()))
                {
                    IFieldsEdit flds = AOUtilities.GetBareMetalFields(esriGeometryType.esriGeometryPoint, 3857, null);
                    Assert.IsTrue(bag1.CreateFeatureClass("foo", flds, esriFeatureType.esriFTSimple, "Shape"));
                    Assert.IsTrue(bag1.AddFeatures("foo", pnts, 0));
                }
            }
        }