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); }
private void LoadNetwork(IPropertySet props) { if (null != props.GetProperty("NetworkName")) { m_networkName = props.GetProperty("NetworkName") as string; } else { throw new ArgumentNullException("NetworkName is unspecified."); } if (null == props.GetProperty("MaxFeatureCount") || false == int.TryParse(props.GetProperty("MaxFeatureCount") as string, out this.m_maxFeatureCount)) { this.m_maxFeatureCount = 5000; } this.m_outputFields = new List <string>() { "Shape_Length" }; this.m_networkContext = new NetworkContext(m_networkName, new List <string>() { FlowLineName }, new List <string>() { JunctionName, BarrierJunctionName }); this.m_networkContext.LoadGeometricNetwork(null, this.serverObjectHelper, this.logger); this.m_isReady = this.m_networkContext.IsNetworkLoaded; if (this.m_isReady) { this.m_disabledFeatureClassIDs = new List <int>() { this.m_networkContext.GetJunctionFeatureClassIdByAliasName(BarrierJunctionName).FeatureClassID }; IFeatureClass flowlineFeatureClass = this.m_networkContext.GetEdgeFeatureClassByAliasName(FlowLineName); ISpatialReference srs = AOUtilities.GetFeatureClassSpatialReference(flowlineFeatureClass, false); if (null != srs) { this.m_networkEPSG = srs.FactoryCode; } else { this.m_isReady = false; } this.m_flowDirFieldIndex = AOUtilities.GetFieldIndexByName(flowlineFeatureClass, "FlowDir"); if (this.m_flowDirFieldIndex < 0) { this.m_isReady = false; } } }
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()); }