Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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());
        }