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(); }
public void CopyFeatureClassTemplate() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); IFeatureClass fc = ctx.GetJunctionFeatureClassIdByAliasName("Barriers"); //Act AbstractFeatureClassBag fcb = new InMemoryFeatureClassBag("in memory", AOUtilities.GetInMemoryWorkspaceFactory()); bool ret = fcb.CreateFeatureClass(fc, "clone barrier"); fcb.Dispose(); //Assert Assert.IsTrue(ret); }