public void TestIdentifyUninitializedStreamSegment() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); //Get FlowDir index IFeatureClass fc = ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"); int idx = AOUtilities.GetFieldIndexByName(fc, "FlowDir"); IPoint pnt = new PointClass() { X = -85.04465103149414, Y = 43.27143070627271 }; IGeometryArray pntArr = new GeometryArrayClass(); pntArr.Add(pnt); IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2(4326, 4269, pntArr); IPoint pnt1 = geomArr.get_Element(0) as IPoint; //Act StartFlagEdge flag = NetworkHelper.GetStartFlagEdge(ctx, pnt1.X, pnt1.Y, 200, 5, "FlowlineMerge", idx, "0", null); //Assert Assert.IsNull(flag); }
public void ConstrcutStartEdge() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); //Flag IPoint pnt = new PointClass(); pnt.X = -86.291; pnt.Y = 43.941; IFeatureClass fc = ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"); int idx = AOUtilities.GetFieldIndexByName(fc, "FlowDir"); //Act StartFlagEdge flag = NetworkHelper.GetStartFlagEdge(ctx, -86.291, 43.941, 100, 5, "FlowlineMerge", idx, "0", null); //Assert Assert.IsNotNull(flag); Assert.IsTrue(flag.FeatureID == 1927894); }
public void FindNearestEdgeAtLocation() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); IPoint pnt = new PointClass(); pnt.X = -86.118; pnt.Y = 43.971; Tuple <double, double> distD = GLC.AO.AOUtilities.GetEstimatedDistInDegree(pnt.X, pnt.Y, 1500, 0.1); //Act Tuple <int, IFeature, double> edgeFlag = GLC.AO.AOUtilities.FindNearestFeature(pnt, ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"), distD.Item1, null); //Assert Assert.IsTrue(edgeFlag.Item1 > 0 && edgeFlag.Item2 != null); //Arrange pnt.X = 86.118; pnt.Y = -43.971; distD = GLC.AO.AOUtilities.GetEstimatedDistInDegree(pnt.X, pnt.Y, 1500, 0.1); //Act edgeFlag = GLC.AO.AOUtilities.FindNearestFeature(pnt, ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"), distD.Item1, null); //Assert Assert.IsNull(edgeFlag); }
public void GetFeatureClassEPSG() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); //Act ISpatialReference srs = AOUtilities.GetFeatureClassSpatialReference(ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"), false); //Assert Assert.IsTrue(4269 == srs.FactoryCode); }
public void ConstructStoppersOnAllExistingBarriersEIDs() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); //Act StopperJunctions stoppers = NetworkHelper.GetStoppersEID(ctx, "Barriers"); //Assert Assert.IsNotNull(stoppers); Assert.IsTrue(stoppers.Stoppers != null && stoppers.Stoppers.Length > 0); }
public void FindJunctionsOnEdge() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); IPoint pnt = new PointClass(); pnt.X = -86.118; pnt.Y = 43.971; IFeatureClass edgeFeatureClass = ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"); IFeatureClass junctionFeatureClass = ctx.GetJunctionFeatureClassIdByAliasName("Hydro_Net_Junctions"); Tuple <double, double> distD = GLC.AO.AOUtilities.GetEstimatedDistInDegree(pnt.X, pnt.Y, 1500, 0.1); Tuple <int, IFeature, double> edgeFlag = GLC.AO.AOUtilities.FindNearestFeature(pnt, edgeFeatureClass, distD.Item1, null); //Act Tuple <int, int> juncFrom2 = NetworkHelper.FindJunctionsOnEdge(edgeFlag.Item2, junctionFeatureClass, null); //Assert Assert.IsNotNull(juncFrom2); Assert.IsTrue(juncFrom2.Item1 > 0 && juncFrom2.Item2 > 0); //Arrange pnt.X = -86.218; pnt.Y = 43.937; distD = GLC.AO.AOUtilities.GetEstimatedDistInDegree(pnt.X, pnt.Y, 1500, 0.1); edgeFlag = GLC.AO.AOUtilities.FindNearestFeature(pnt, edgeFeatureClass, distD.Item1, null); //Act juncFrom2 = NetworkHelper.FindJunctionsOnEdge(edgeFlag.Item2, junctionFeatureClass, null); //Arrange Assert.IsNotNull(juncFrom2); Assert.IsTrue(juncFrom2.Item1 > 0 && juncFrom2.Item2 == -1); }
public void ConstructStoppersOnVirtualBarriers() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); IPoint pnt = new PointClass(); pnt.X = -86.313; pnt.Y = 43.922; IPoint pnt1 = new PointClass(); pnt1.X = -86.31; pnt1.Y = 43.92; List <IPoint> pnts = new List <IPoint>() { pnt, pnt1 }; //Act StopperJunctions stoppers = NetworkHelper.GetStoppers(ctx, pnts, true, 200, 5, "FlowlineMerge", "Hydro_Net_Junctions", null); //Assert Assert.IsNotNull(stoppers); Assert.IsTrue(stoppers.Stoppers != null && stoppers.Stoppers.Length == 2); Assert.IsTrue(stoppers.Stoppers[0] == 624591 && stoppers.Stoppers[1] == 624974); //Act stoppers = NetworkHelper.GetStoppers(ctx, pnts, false, 200, 5, "FlowlineMerge", "Hydro_Net_Junctions", null); Assert.IsNotNull(stoppers); Assert.IsTrue(stoppers.Stoppers != null && stoppers.Stoppers.Length == 2); Assert.IsTrue(stoppers.Stoppers[0] == 624381 && stoppers.Stoppers[1] == 624391); }
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); }
public void TestGetFieldIndexAndValues() { //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.GetEdgeFeatureClassByAliasName("FlowlineMerge"); //Act int idx = AOUtilities.GetFieldIndexByName(fc, "FlowDir"); Dictionary <string, Tuple <int, esriFieldType> > fldDict = AOUtilities.GetFieldIndexes(fc); //Assert Assert.IsTrue(idx >= 0); Assert.IsNotNull(fldDict); Assert.IsTrue(idx == fldDict["FlowDir"].Item1); }
public void TraceStream() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); ctx.LoadGeometricNetwork(GN_Path, null, null); //Flag IFeatureClass fc = ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"); int idx = AOUtilities.GetFieldIndexByName(fc, "FlowDir"); StartFlagEdge flag = NetworkHelper.GetStartFlagEdge(ctx, -85.062153, 44.003813, 1000, 5, "FlowlineMerge", idx, "0", null); //All Existing Barriers List <int> fcid = new List <int>() { ctx.GetJunctionFeatureClassIdByAliasName("Barriers").FeatureClassID }; //Virtual Barriers IPoint pnt = new PointClass(); pnt.X = -85.021764; pnt.Y = 44.122331; IPoint pnt1 = new PointClass(); pnt1.X = -84.974754; pnt1.Y = 44.162720; IPoint pnt2 = new PointClass(); pnt2.X = -84.896625; pnt2.Y = 44.128; List <IPoint> pnts = new List <IPoint>() { pnt, pnt1, pnt2 }; StopperJunctions stoppers1 = NetworkHelper.GetStoppers(ctx, pnts, true, 1000, 5, "FlowlineMerge", "Hydro_Net_Junctions", null); //Act //Do upstream first List <int> ftrList = AOUtilities.StreamTrace(ctx.GeometricNetwork, flag, fcid, stoppers1, true, 1000, null); //Assert Assert.IsNotNull(ftrList); List <string> ids = new List <string>(); foreach (var ftr in ftrList) { ids.Add(ftr.ToString()); } //System.Diagnostics.Debug.WriteLine(string.Join(",", ids.ToArray())); //Act //Do upstream again without stoppers to test if the previous setting is gone ftrList = AOUtilities.StreamTrace(ctx.GeometricNetwork, flag, fcid, null, true, 1000, null); //Assert Assert.IsNotNull(ftrList); ids = new List <string>(); foreach (var ftr in ftrList) { ids.Add(ftr.ToString()); } //System.Diagnostics.Debug.WriteLine(string.Join(",", ids.ToArray())); //Act //downstream ftrList = AOUtilities.StreamTrace(ctx.GeometricNetwork, flag, fcid, null, false, 1000, null); //Assert Assert.IsNotNull(ftrList); ids = new List <string>(); foreach (var ftr in ftrList) { ids.Add(ftr.ToString()); } //System.Diagnostics.Debug.WriteLine(string.Join(",", ids.ToArray())); IRecordSet records = AOUtilities.GetRecordSetFromFeatureClass(ctx.GetEdgeFeatureClassByAliasName("FlowlineMerge"), ftrList, new List <string>() { "Shape_Length" }, 3857); Assert.IsNotNull(records); //How to update a feature //http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/0001000002rs000000.htm /*ICursor ftrCursor = records.get_Cursor(true); * try * { * IRow row = ftrCursor.NextRow(); * IFeature ftr = row as IFeature; * esriFeatureType type = ftr.FeatureType; * esriGeometryType t1 = ftr.Shape.GeometryType; * * IRow row1 = ftrCursor.NextRow(); * IFeature ftr1 = row as IFeature; * * ftr.Shape = ftr1.ShapeCopy; * } * catch(Exception e) * { * string err = e.Message; * } * finally * { * AOUtilities.ReleaseCOMObj(ftrCursor); * }*/ JsonObject json = new JsonObject(System.Text.Encoding.UTF8.GetString(Conversion.ToJson(records))); Assert.IsNotNull(json); //System.Diagnostics.Debug.WriteLine(json.ToJson()); }
public void LoadGeometricNetworkFromFileGeoDatabase() { //Arrange NetworkContext ctx = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); //Act bool ret = ctx.LoadGeometricNetwork(GN_Path, null, null);//new Mock<IServerObjectHelper>().Object, new ServerLogger()); //Assert Assert.IsTrue(ret && ctx.IsNetworkLoaded); //Arrange NetworkContext ctx1 = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); //moq doesn't work on sealed class //Mock<ServerLogger> MockServerLogger = new Mock<ServerLogger>(); //Act on a nonexist path ret = ctx1.LoadGeometricNetwork("abc", null, null);//MockServerLogger.Object); //Assert Assert.IsFalse(ret); //Arrange NetworkContext ctx2 = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge", "foobar" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); //Act, although the network can be loaded, we have fed some extra feature class that doesn't exist in the //current network. So IsLoaded is still false. ret = ctx2.LoadGeometricNetwork(GN_Path, null, null); //Assert Assert.IsTrue(false == ret && false == ctx2.IsNetworkLoaded); //MockServerLogger.Verify(t => t.LogMessage(ServerLogger.msgType.error, It.IsAny<string>(), It.Is<int>(tt => tt == GLC.AO.AOUtilities.ErrorCode), It.IsAny<string>())); //Arrange NetworkContext ctx3 = new NetworkContext("Hydro", new List <string>() { "FlowlineMerge" }, new List <string>() { "Hydro_Net_Junctions", "Barriers" }); //Act //ctx can't be populated more than once, otherwise throw exception ctx3.LoadGeometricNetwork(GN_Path, null, null); ctx3.LoadGeometricNetwork(GN_Path, null, null); }