Ejemplo n.º 1
0
        /// <summary>
        /// 将导入路线和已有路线进行叠加分析,找到交叉点
        /// </summary>
        /// <param name="line"></param>
        /// <param name="roadFC"></param>
        /// <returns></returns>
        private static List<CrossingInfo> QueryIntersect(IPolyline line, IFeatureClass roadFC)
        {
            var cursor = roadFC.Search(new SpatialFilterClass { Geometry = line, SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects }, true);
            var topo = line as ITopologicalOperator;
            var rel = line as IRelationalOperator;
            var f = cursor.NextFeature();
            var list = new List<CrossingInfo>();

            while (f != null)
            {
                var shp = f.ShapeCopy;
                line.SpatialReference = shp.SpatialReference;
                var pc2 = shp as IPointCollection;

                var ret = topo.Intersect(shp, esriGeometryDimension.esriGeometry0Dimension);
                if (ret.IsEmpty == false)
                {
                    if (ret is IPoint || ret is IPointCollection)
                    {
                        var info = new RoadCrossInfo
                        {
                            Geometry = (IPolyline)shp,
                            Id = f.OID,
                            Text = f.get_Value(f.Fields.FindField(RoadNameFieldName)).ToString(),
                            No = f.get_Value(f.Fields.FindField(IDFieldName)).ToString()
                        };

                        if (ret is IPoint)
                        {
                            list.Add(new CrossingInfo { Crossing = (ret as IPoint), Road = info });
                        }
                        else
                        {
                            var pc = ret as IPointCollection;
                            for (var i = 0; i < pc.PointCount; i++)
                            {
                                list.Add(new CrossingInfo { Crossing = pc.Point[i], Road = info });
                            }
                        }
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("道路相交结果的类型‘{0}’不被支持", ret.GetType()));
                    }
                }
                f = cursor.NextFeature();
            }

            Marshal.ReleaseComObject(cursor);
            return list;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 切掉路线两边出头的线头
        /// </summary>
        /// <param name="line"></param>
        private static void CutFragments(RoadCrossInfo line)
        {
            if (line.Enabled == false) return;

            var pts = new List<IPoint>();
            if(line.HeadCrossing != null) pts.Add(line.HeadCrossing);
            if(line.TailCrossing != null) pts.Add(line.TailCrossing);

            foreach(var pt in pts)
            {
                var ret = SplitLine(line.Geometry, pt);
                if (ret!=null&&ret.Count > 1)
                {
                    line.Geometry = (ret[0].Length > ret[1].Length) ? ret[0] : ret[1];
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取路线两边的线头(填充HeadCrossing和TailCrossing)
        /// </summary>
        /// <param name="line"></param>
        private static void QueryFragments(RoadCrossInfo line)
        {
            if (line.Enabled == false) return;
            line.TailCrossing = null;
            line.HeadCrossing = null;
            double min = double.MaxValue;
            double min2 = double.MaxValue;
            var length = GetProjectedLength(line.Geometry);
            var topo = line.Geometry as ITopologicalOperator;
            var pt = new PointClass();
            for(var i=0;i<line.Crossings.Count;i++)
            {
                if(line.Crossings[i].Enabled == false) continue;

                double distance = 0, b = 0;
                bool rightSide = false;
                line.Geometry.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, line.Crossings[i].Crossing, false, pt, ref distance, ref b, ref rightSide);
                distance = GetProjectedDistance(pt, distance);
                if(distance<min && distance < FragmentThreshold){
                    min = distance;
                    line.HeadCrossing = line.Crossings[i].Crossing;
                    line.HeadLength = min;
                }else if(length-distance<min2 && length-distance < FragmentThreshold){
                    min2 = length-distance;
                    line.TailCrossing = line.Crossings[i].Crossing;
                    line.TailLength = min2;
                }
            }

            if (line.TailCrossing != null)
            {
                var ret = SplitLine(line.Geometry, line.TailCrossing);
                if (ret!=null&&ret.Count > 1)
                {
                    line.Tail = (ret[0].Length > ret[1].Length) ? ret[1] : ret[0];
                }
            }

            if(line.HeadCrossing != null)
            {
                var ret = SplitLine(line.Geometry, line.HeadCrossing);
                if (ret!=null&& ret.Count > 1)
                {
                    line.Head = (ret[0].Length > ret[1].Length) ? ret[1] : ret[0];
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 创建导入线列表
        /// </summary>
        /// <param name="lines"></param>
        /// <returns></returns>
        private static List<RoadCrossInfo> CreateList(List<IPolyline> lines)
        {
            //var list = SplitLine(lines);
            var lst = new List<RoadCrossInfo>();
            for (var i = 0; i < lines.Count; i++)
            {
                var entity = new RoadCrossInfo()
                {
                    Id = -i,
                    Text = "[新导入道路]",
                    No = "[新编号]",
                    Geometry = lines[i]
                };
                lst.Add(entity);

            }
            return lst;
        }