Пример #1
0
        private bool IntersectAll(IFeatureClass lineLayer, IPolygon polygon2, List <ziduan> list)
        {
            try
            {
                if (radioBtnKJ.Checked && polygon2 != null)
                {
                    //  根据组合成的面裁剪压力等值线
                    SpatialFilterClass qfilter = new SpatialFilterClass();
                    qfilter.Geometry   = polygon2;
                    qfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                    IFeatureCursor qfeatureCursor = lineLayer.Search(qfilter, false);

                    if (qfeatureCursor != null)
                    {
                        IFeature       feature       = qfeatureCursor.NextFeature();
                        IGeometryArray geometryArray = new GeometryArrayClass();
                        while (feature != null)
                        {
                            geometryArray.Add(feature.Shape);
                            feature = qfeatureCursor.NextFeature();
                        }

                        IGeometryServer2 geometryServer2 = new GeometryServerClass();
                        IGeometryArray   geometryArray2  = geometryServer2.Intersect(polygon2.SpatialReference, geometryArray, polygon2);
                        //DataEditCommon.DeleteFeatureByWhereClause(lineLayer, "");
                        IFeatureLayer pFeatureLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, EditLayerName) as IFeatureLayer;
                        DataEditCommon.CreateFeature(pFeatureLayer.FeatureClass, geometryArray2, list);
                    }
                }
                return(true);
            }
            catch
            { return(false); }
        }
Пример #2
0
        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);
        }
Пример #3
0
        private List <IPoint> ParseVirtualBarriers(JsonObject[] barrierJsonArray, uint epsg)//lazy here, just copy epsg from flag and assume barriers having the same one
        {
            List <IPoint> ret = null;

            if (null != barrierJsonArray && barrierJsonArray.Length > 0)
            {
                JsonObject     barrierFeature = null;
                IPoint         pnt            = null;
                IGeometryArray pntArr1        = new GeometryArrayClass();
                for (int i = 0; i < barrierJsonArray.Length; ++i)
                {
                    if (barrierJsonArray[i].TryGetJsonObject("geometry", out barrierFeature))
                    {
                        if (null != barrierFeature)
                        {
                            double?x, y;
                            //int? epsg;
                            if (barrierFeature.TryGetAsDouble("x", out x) && barrierFeature.TryGetAsDouble("y", out y))
                            {
                                pnt   = new PointClass();
                                pnt.X = x.Value;
                                pnt.Y = y.Value;
                                pntArr1.Add(pnt);
                            }
                        }
                    }
                }
                if (pntArr1.Count > 0)
                {
                    IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2(epsg, (uint)this.m_networkEPSG, pntArr1);
                    if (null != geomArr && geomArr.Count > 0)
                    {
                        ret = new List <IPoint>();
                        for (int i = 0; i < geomArr.Count; ++i)
                        {
                            ret.Add(geomArr.get_Element(i) as IPoint);
                        }
                    }
                }
            }
            return(ret);
        }
Пример #4
0
        private bool IntersectAll(IFeatureClass lineLayer, IPolygon polygon2, List<ziduan> list)
        {
            try
            {
                if (radioBtnKJ.Checked && polygon2 != null)
                {
                    //  根据组合成的面裁剪压力等值线
                    SpatialFilterClass qfilter = new SpatialFilterClass();
                    qfilter.Geometry = polygon2;
                    qfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                    IFeatureCursor qfeatureCursor = lineLayer.Search(qfilter, false);

                    if (qfeatureCursor != null)
                    {
                        IFeature feature = qfeatureCursor.NextFeature();
                        IGeometryArray geometryArray = new GeometryArrayClass();
                        while (feature != null)
                        {
                            geometryArray.Add(feature.Shape);
                            feature = qfeatureCursor.NextFeature();
                        }

                        IGeometryServer2 geometryServer2 = new GeometryServerClass();
                        IGeometryArray geometryArray2 = geometryServer2.Intersect(polygon2.SpatialReference, geometryArray, polygon2);
                        //DataEditCommon.DeleteFeatureByWhereClause(lineLayer, "");
                        IFeatureLayer pFeatureLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, EditLayerName) as IFeatureLayer;
                        DataEditCommon.CreateFeature(pFeatureLayer.FeatureClass, geometryArray2, list);

                    }
                }
                return true;
            }
            catch
            { return false; }
        }
Пример #5
0
        public void CoordinatesReProjection()
        {
            //Arrange
            IPoint pnt1 = new PointClass();

            pnt1.X = -9569447.832126;
            pnt1.Y = 5524225.232441;
            //pnt1.SpatialReference = AOUtilities.GetSpatialReference(3857);
            IGeometryArray pntArr1 = new GeometryArrayClass();

            pntArr1.Add(pnt1);

            //Act
            //The SpatialReference property for all returned geometries will be null.  It is the consumers responsibility to assign the
            //spatial reference to each geometry returned, if desired.  In this case, the spatial reference is assumed to be the output spatial reference defined for the Project operation.
            IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2(3857, 4269, pntArr1);
            //It appears IGeometryServer2.Project will NOT throw an error if the coordinates don't match the given epsg
            //instead, it simply returns the input coordinates as output...
            IGeometryArray geomArr1 = AOUtilities.TransfromGeometriesFrom2(4326, 4269, pntArr1);

            //Assert
            Assert.IsNotNull(geomArr);
            Assert.IsNotNull(geomArr1);
            Assert.AreEqual <int>(pntArr1.Count, geomArr.Count);
            Assert.AreEqual <int>(pntArr1.Count, geomArr1.Count);
            IPoint pnt2 = geomArr.get_Element(0) as IPoint;

            Assert.IsNotNull(pnt2);
            pnt2 = geomArr1.get_Element(0) as IPoint;
            Assert.IsNotNull(pnt2);

            //Act
            geomArr1 = AOUtilities.TransfromGeometriesFrom2(4269, 4326, geomArr);
            //Assert
            Assert.IsNotNull(geomArr1);
            Assert.AreEqual <int>(geomArr1.Count, geomArr.Count);
            pnt2 = geomArr1.get_Element(0) as IPoint;
            IPoint pnt3 = geomArr.get_Element(0) as IPoint;

            Assert.IsNotNull(pnt2);
            //Since the output geometry will not have spatial reference assigned, we can't verify if the output are in the desired projection through this shortcut.
            //Assert.IsTrue(4326 == pnt2.SpatialReference.FactoryCode);
            //Assert.IsTrue(4269 == pnt3.SpatialReference.FactoryCode);

            //Arrange
            pntArr1.RemoveAll();
            pntArr1.Add(pnt2);

            //Act
            geomArr = AOUtilities.TransfromGeometriesFrom2(4269, 3857, pntArr1);

            //Assert
            Assert.IsNotNull(geomArr);
            Assert.AreEqual <int>(pntArr1.Count, geomArr.Count);
            pnt2 = geomArr.get_Element(0) as IPoint;
            Assert.IsNotNull(pnt2);
            Assert.IsTrue((Math.Abs(pnt2.X - pnt1.X) < 1e-7) && (Math.Abs(pnt2.Y - pnt1.Y) < 1e-7));

            //Arrange
            pnt1.X = double.MinValue;
            pnt1.Y = double.PositiveInfinity;
            pntArr1.RemoveAll();
            pntArr1.Add(pnt1);

            //Act
            geomArr = AOUtilities.TransfromGeometriesFrom2(3857, 4269, pntArr1);
            pnt2    = geomArr.get_Element(0) as IPoint;

            //Assert
            Assert.IsTrue(pnt2.IsEmpty);
            double x = pnt2.X;
        }
Пример #6
0
 public static void CreateFeature(IFeatureClass featureClass, IGeometry geometry, List<ziduan> list)
 {
     IGeometryArray pArry = new GeometryArrayClass();
     pArry.Add(geometry);
     CreateFeature(featureClass, pArry, list);
 }
        private void btnup_Click(object sender, EventArgs e)
        {
            //设置一个最小值
            progressBarControl1.Properties.Minimum = 0;

            //设置步长,即每次增加的数
            progressBarControl1.Properties.Step = 1;
            //设置进度条的样式
            progressBarControl1.Properties.ProgressViewStyle = DevExpress.XtraEditors.Controls.ProgressViewStyle.Solid;
            progressBarControl1.Position = 0;

            //设置一个最小值
            progressBarControl2.Properties.Minimum = 0;
            //设置一个最大值
            progressBarControl2.Properties.Maximum = listView1.CheckedItems.Count * 2;
            //设置步长,即每次增加的数
            progressBarControl2.Properties.Step = 1;
            //设置进度条的样式
            progressBarControl2.Properties.ProgressViewStyle = DevExpress.XtraEditors.Controls.ProgressViewStyle.Solid;
            progressBarControl2.Position = 0;

            ////设置一个最小值
            //progressBar2.Minimum = 0;
            ////设置一个最大值
            //progressBar2.Maximum = listView1.CheckedItems.Count * 2;
            ////设置步长,即每次增加的数
            //progressBar2.Step = 1;
            //progressBar2.Value = 0;

            IFeatureClass tFeatureClass = pFeatureLayer_QYYJY.FeatureClass;
            DataEditCommon.DeleteFeatureByWhereClause(tFeatureClass, "");
            IGeometryArray pgeoArrayHong = new GeometryArrayClass();
            IGeometryArray pgeoArrayHang = new GeometryArrayClass();
            for (int i = 0; i < listView1.CheckedItems.Count; i++)
            {
                string layer = listView1.CheckedItems[i].SubItems[1].Text.ToString();
                ILayer pLayer = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, layer);
                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                if (pFeatureLayer == null)
                    continue;
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                //设置一个最大值
                progressBarControl1.Properties.Maximum = pFeatureClass.FeatureCount(null);
                IFeatureCursor pCursor = pFeatureClass.Search(null, false);
                IFeature pFeature = pCursor.NextFeature();

                while (pFeature != null)
                {
                    ITopologicalOperator pTopo = (ITopologicalOperator)pFeature.Shape;
                    IGeometry pGeo = pTopo.Buffer(hongse);
                    pgeoArrayHong.Add(pGeo);
                    IGeometry pGeoH = pTopo.Buffer(huangse);
                    if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        pTopo = (ITopologicalOperator)pGeoH;
                        pGeoH = pTopo.Difference(pGeo);
                    }
                    pgeoArrayHang.Add(pGeoH);
                    pFeature = pCursor.NextFeature();
                    this.progressBarControl1.PerformStep();
                    Application.DoEvents();
                }
                List<ziduan> list = new List<ziduan>();
                list.Add(new ziduan("dengji", "1"));
                list.Add(new ziduan("layername", layer));
                list.Add(new ziduan("BID", "0"));
                DataEditCommon.CreateFeature(tFeatureClass, pgeoArrayHong, list);
                this.progressBarControl2.PerformStep();
                //progressBar2.Value += 1;
                Application.DoEvents();
                List<ziduan> listH = new List<ziduan>();
                listH.Add(new ziduan("dengji", "2"));
                listH.Add(new ziduan("layername", layer));
                listH.Add(new ziduan("BID", "0"));
                DataEditCommon.CreateFeature(tFeatureClass, pgeoArrayHang, listH);
                this.progressBarControl2.PerformStep();
                //progressBar2.Value += 1;
                Application.DoEvents();
            }
            if (pFeatureLayer_QYYJY.Visible == false)
                pFeatureLayer_QYYJY.Visible = true;
            DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            MessageBox.Show("完成!");
        }
Пример #8
0
        private byte[] NetworkTraceHandler(NameValueCollection boundVariables,
                                           JsonObject operationInput,
                                           string outputFormat,
                                           string requestProperties,
                                           out string responseProperties)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            responseProperties = null;

            string traceTypeStr;
            bool   found = operationInput.TryGetString(TracingDirParameterName, out traceTypeStr);

            if (!found || string.IsNullOrEmpty(traceTypeStr))
            {
                throw new ArgumentNullException(TracingDirParameterName + " is required");
            }
            traceTypeStr = traceTypeStr.ToUpper();
            bool?isUpstream = null;

            if ("TRACE_UPSTREAM" == traceTypeStr)
            {
                isUpstream = true;
            }
            else if ("TRACE_DOWNSTREAM" == traceTypeStr)
            {
                isUpstream = false;
            }
            if (false == isUpstream.HasValue)
            {
                throw new ArgumentException("Not valid Trace_Task_type");
            }

            long?outEPSG;

            found = operationInput.TryGetAsLong(OutputEPSGParameterName, out outEPSG);
            if (!found || !outEPSG.HasValue || outEPSG <= 0)
            {
                throw new ArgumentNullException(OutputEPSGParameterName + " is required");
            }
            if (outEPSG < 1)
            {
                throw new ArgumentException(OutputEPSGParameterName + " is not valid");
            }

            JsonObject flagJSON = null;

            object[]     flagArray     = null;
            JsonObject[] flagJsonArray = null;
            if (false == operationInput.TryGetJsonObject(FlagParameterName, out flagJSON) || null == flagJSON)
            {
                throw new ArgumentNullException(FlagParameterName + " is required");
            }
            if (flagJSON.TryGetArray("features", out flagArray))
            {
                try
                {
                    flagJsonArray = flagArray.Cast <JsonObject>().ToArray();
                }
                catch
                {
                    throw new ArgumentException("invalid Flags json format");
                }
            }
            //Found the flag
            List <int> ftrList = null;

            if (null != flagJsonArray && 1 == flagJsonArray.Length)
            {
                JsonObject flagFeature = null;
                if (flagJsonArray[0].TryGetJsonObject("geometry", out flagFeature))
                {
                    if (null == flagFeature)
                    {
                        throw new ArgumentException("invalid Flags json format with geometry");
                    }
                    double?    x, y;
                    long?      epsg;
                    JsonObject srsObj;
                    if (true == flagFeature.TryGetJsonObject("spatialReference", out srsObj))
                    {
                        if (false == srsObj.TryGetAsLong("wkid", out epsg) || epsg <= 0)
                        {
                            throw new ArgumentException("No valid wikd found for flag feature.");
                        }
                    }
                    else
                    {
                        throw new ArgumentException("No spatial reference found for flag feature.");
                    }
                    if (flagFeature.TryGetAsDouble("x", out x) && flagFeature.TryGetAsDouble("y", out y))
                    {
                        if (!x.HasValue || !y.HasValue)
                        {
                            throw new ArgumentException("invalid Flag coordinate");
                        }
                        IPoint pnt1 = new PointClass();
                        pnt1.X = x.Value;
                        pnt1.Y = y.Value;
                        IGeometryArray pntArr1 = new GeometryArrayClass();
                        pntArr1.Add(pnt1);
                        IGeometryArray geomArr = AOUtilities.TransfromGeometriesFrom2((uint)epsg, (uint)this.m_networkEPSG, pntArr1);
                        if (null == geomArr || 1 != geomArr.Count)
                        {
                            throw new ArgumentException("invalid Flag coordinate for reprojection");
                        }
                        pnt1 = geomArr.get_Element(0) as IPoint;
                        StartFlagEdge    flag     = NetworkHelper.GetStartFlagEdge(this.m_networkContext, pnt1.X, pnt1.Y, TracingSOE.m_searchDistance, TracingSOE.m_searchTolerance, FlowLineName, this.m_flowDirFieldIndex, InvalidFlowDirValue, logger);
                        StopperJunctions stoppers = null;
                        if (null != flag)
                        {
                            List <IPoint> barrierPnts      = null;
                            JsonObject    barriersJSON     = null;
                            object[]      barrierArray     = null;
                            JsonObject[]  barrierJsonArray = null;
                            if (true == operationInput.TryGetJsonObject(BarrierParameterName, out barriersJSON) || null != barriersJSON)
                            {
                                if (barriersJSON.TryGetArray("features", out barrierArray))
                                {
                                    try
                                    {
                                        barrierJsonArray = barrierArray.Cast <JsonObject>().ToArray();
                                        barrierPnts      = ParseVirtualBarriers(barrierJsonArray, (uint)epsg);
                                    }
                                    catch
                                    {
                                        throw new ArgumentException("invalid Barriers json format");
                                    }
                                }
                                if (null != barrierPnts && barrierPnts.Count > 0)
                                {
                                    stoppers = NetworkHelper.GetStoppers(this.m_networkContext, barrierPnts, isUpstream.Value, TracingSOE.m_searchDistance, TracingSOE.m_searchTolerance, FlowLineName, JunctionName, logger);
                                }
                            }
                        }
                        ftrList = AOUtilities.StreamTrace(this.m_networkContext.GeometricNetwork, flag, this.m_disabledFeatureClassIDs, stoppers, isUpstream.Value, this.m_maxFeatureCount, logger);
                    }
                }
            }
            IRecordSet records = null;

            if (null != ftrList && ftrList.Count > 0)
            {
                records = AOUtilities.GetRecordSetFromFeatureClass(this.m_networkContext.GetEdgeFeatureClassByAliasName(FlowLineName), ftrList, this.m_outputFields, (uint)outEPSG.Value);
            }
            JsonObject result = new JsonObject();

            if (null != records)
            {
                result.AddJsonObject("value", new JsonObject(System.Text.Encoding.UTF8.GetString(Conversion.ToJson(records))));
            }
            else
            {
                result.AddString("output", "{}");
            }
            watch.Stop();
            this.logger.LogMessage(ServerLogger.msgType.debug, "NetworkTraceHandler", 973, "Tracing taked: " + watch.ElapsedMilliseconds.ToString() + " ms");
            result.AddLong("time(ms)", watch.ElapsedMilliseconds);
            return(Encoding.UTF8.GetBytes(result.ToJson()));
        }
Пример #9
0
        private void btnup_Click(object sender, EventArgs e)
        {
            //设置一个最小值
            progressBarControl1.Properties.Minimum = 0;

            //设置步长,即每次增加的数
            progressBarControl1.Properties.Step = 1;
            //设置进度条的样式
            progressBarControl1.Properties.ProgressViewStyle = DevExpress.XtraEditors.Controls.ProgressViewStyle.Solid;
            progressBarControl1.Position = 0;

            //设置一个最小值
            progressBarControl2.Properties.Minimum = 0;
            //设置一个最大值
            progressBarControl2.Properties.Maximum = listView1.CheckedItems.Count * 2;
            //设置步长,即每次增加的数
            progressBarControl2.Properties.Step = 1;
            //设置进度条的样式
            progressBarControl2.Properties.ProgressViewStyle = DevExpress.XtraEditors.Controls.ProgressViewStyle.Solid;
            progressBarControl2.Position = 0;

            ////设置一个最小值
            //progressBar2.Minimum = 0;
            ////设置一个最大值
            //progressBar2.Maximum = listView1.CheckedItems.Count * 2;
            ////设置步长,即每次增加的数
            //progressBar2.Step = 1;
            //progressBar2.Value = 0;


            IFeatureClass tFeatureClass = pFeatureLayer_QYYJY.FeatureClass;

            DataEditCommon.DeleteFeatureByWhereClause(tFeatureClass, "");
            IGeometryArray pgeoArrayHong = new GeometryArrayClass();
            IGeometryArray pgeoArrayHang = new GeometryArrayClass();

            for (int i = 0; i < listView1.CheckedItems.Count; i++)
            {
                string        layer         = listView1.CheckedItems[i].SubItems[1].Text.ToString();
                ILayer        pLayer        = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, layer);
                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                if (pFeatureLayer == null)
                {
                    continue;
                }
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
                //设置一个最大值
                progressBarControl1.Properties.Maximum = pFeatureClass.FeatureCount(null);
                IFeatureCursor pCursor  = pFeatureClass.Search(null, false);
                IFeature       pFeature = pCursor.NextFeature();

                while (pFeature != null)
                {
                    ITopologicalOperator pTopo = (ITopologicalOperator)pFeature.Shape;
                    IGeometry            pGeo  = pTopo.Buffer(hongse);
                    pgeoArrayHong.Add(pGeo);
                    IGeometry pGeoH = pTopo.Buffer(huangse);
                    if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        pTopo = (ITopologicalOperator)pGeoH;
                        pGeoH = pTopo.Difference(pGeo);
                    }
                    pgeoArrayHang.Add(pGeoH);
                    pFeature = pCursor.NextFeature();
                    this.progressBarControl1.PerformStep();
                    Application.DoEvents();
                }
                List <ziduan> list = new List <ziduan>();
                list.Add(new ziduan("dengji", "1"));
                list.Add(new ziduan("layername", layer));
                list.Add(new ziduan("BID", "0"));
                DataEditCommon.CreateFeature(tFeatureClass, pgeoArrayHong, list);
                this.progressBarControl2.PerformStep();
                //progressBar2.Value += 1;
                Application.DoEvents();
                List <ziduan> listH = new List <ziduan>();
                listH.Add(new ziduan("dengji", "2"));
                listH.Add(new ziduan("layername", layer));
                listH.Add(new ziduan("BID", "0"));
                DataEditCommon.CreateFeature(tFeatureClass, pgeoArrayHang, listH);
                this.progressBarControl2.PerformStep();
                //progressBar2.Value += 1;
                Application.DoEvents();
            }
            if (pFeatureLayer_QYYJY.Visible == false)
            {
                pFeatureLayer_QYYJY.Visible = true;
            }
            DataEditCommon.g_pMyMapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            MessageBox.Show("完成!");
        }