Пример #1
0
        /// <summary>
        /// 创建区间线段
        /// </summary>
        /// <param name="pLine">输入的线图形</param>
        /// <param name="p1">插入的其中一个点</param>
        /// <param name="p2">插入的一种一个点</param>
        /// <returns>这两点间的线段</returns>
        /// 创建人 : zw
        private IPolyline BuildLine(IPolyline pLine, IPoint p1, IPoint p2, Boolean Reverse)
        {
            if (Reverse)
            {
                pLine.ReverseOrientation();
            }
            bool isSplit;
            int  splitIndex, segIndex;

            //插入第一点,segIndex记录插入点的相对线的节点位置
            pLine.SplitAtPoint(p1, true, false, out isSplit, out splitIndex, out segIndex);
            int fIndex = segIndex;

            //插入第二点
            pLine.SplitAtPoint(p2, true, false, out isSplit, out splitIndex, out segIndex);
            int sIndex = segIndex;

            //比较一下插入第一点和第二点的节点次序
            if (fIndex > sIndex)
            {
                int temp = fIndex;
                fIndex = sIndex;
                sIndex = temp;
            }
            IPointCollection pPointCol = new PolylineClass();
            object           o         = Type.Missing;
            //利用两点区间,获取线上区间所在的点,并将其转换为线
            IPointCollection LineCol = pLine as IPointCollection;

            for (int i = fIndex; i <= sIndex; i++)
            {
                pPointCol.AddPoint(LineCol.get_Point(i), ref o, ref o);
            }
            return(pPointCol as IPolyline);
        }
Пример #2
0
 //根据第一应急处置空间位置点,将即将污染的河流切割成两段
 public IPolyline GetPointSplitAtPoint(IPolyline InputLine, IPoint point)
 {
     try
     {
         IPolyline[] pLines     = new IPolyline[2];
         IPolyline   pSplitLine = new PolylineClass();
         pSplitLine = InputLine;
         IPolyline StarttoPointLine = new PolylineClass();
         IPolyline EndtoPointLine = new PolylineClass();
         bool      projectOnto = true, createPart = false;
         bool      SplitHappened;
         int       partindex, segmentindex;
         object    pObject = Type.Missing;
         pSplitLine.SplitAtPoint(point, projectOnto, createPart, out SplitHappened, out partindex, out segmentindex);
         ISegmentCollection lineSegCol  = pSplitLine as ISegmentCollection;
         ISegmentCollection startSegCol = StarttoPointLine as ISegmentCollection;
         ISegmentCollection endSegCol   = EndtoPointLine as ISegmentCollection;
         for (int i = 0; i < segmentindex; i++)
         {
             startSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject);
         }
         for (int j = segmentindex; j < lineSegCol.SegmentCount; j++)
         {
             endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject);
         }
         pLines[0] = endSegCol as IPolyline;
         pLines[1] = startSegCol as IPolyline;
         return(pLines[0]);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
         return(null);
     }
 }
Пример #3
0
        //获取将输入点最近点,该线段分割成两段
        public static IPolyline[] GetSubLine(IPoint point, IFeature pFeature)
        {
            try
            {
                IPolyline   pLine            = pFeature.Shape as IPolyline;
                IPolyline[] pLines           = new IPolyline[2];
                IPolyline   StarttoPointLine = new PolylineClass();
                IPolyline   EndtoPointLine   = new PolylineClass();
                bool        splithappened;
                int         partindex, segmentindex;
                object      pObject = Type.Missing;
                //IPoint IPoint = GetNearestPoint(point);
                pLine.SplitAtPoint(point, false, false, out splithappened, out partindex, out segmentindex);
                ISegmentCollection lineSegCol = (ISegmentCollection)pLine;
                ISegmentCollection newSegCol  = (ISegmentCollection)StarttoPointLine;
                ISegmentCollection endSegCol  = EndtoPointLine as ISegmentCollection;
                for (int i = 0; i < segmentindex; i++)
                {
                    newSegCol.AddSegment(lineSegCol.get_Segment(i), ref pObject, ref pObject);
                }
                for (int j = segmentindex; j < lineSegCol.SegmentCount; j++)
                {
                    endSegCol.AddSegment(lineSegCol.get_Segment(j), ref pObject, ref pObject);
                }

                lineSegCol.RemoveSegments(0, segmentindex, true);
                pLines[0] = newSegCol as IPolyline;
                pLines[1] = endSegCol as IPolyline;
                return(pLines);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "异常");
                return(null);
            }
        }
Пример #4
0
        public static bool Trim(ITopology pTopology, ITopologyErrorFeature pTopoErrorFeat)
        {
            IFeatureClass class2 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.OriginClassID);
            IFeatureClass class3 = null;

            try
            {
                if (pTopoErrorFeat.DestinationClassID != 0)
                {
                    class3 = (pTopology as IFeatureClassContainer).get_ClassByID(pTopoErrorFeat.DestinationClassID);
                }
            }
            catch
            {
            }
            IFeature feature = null;

            if (pTopoErrorFeat.TopologyRuleType == esriTopologyRuleType.esriTRTLineNoDangles)
            {
                feature = class2.GetFeature(pTopoErrorFeat.OriginOID);
                IPoint             shape    = (pTopoErrorFeat as IFeature).Shape as IPoint;
                IPolyline          polyline = feature.Shape as IPolyline;
                double             num      = CommonHelper.distance(polyline.FromPoint, shape);
                double             num2     = CommonHelper.distance(polyline.ToPoint, shape);
                ISegmentCollection segments = polyline as ISegmentCollection;
                ILine          line         = null;
                IConstructLine line2        = new LineClass();
                if (num < num2)
                {
                    line = segments.get_Segment(0) as ILine;
                }
                else
                {
                    line = segments.get_Segment(segments.SegmentCount - 1) as ILine;
                }
                IPolyline polyline2 = new PolylineClass();
                object    before    = Missing.Value;
                (polyline2 as ISegmentCollection).AddSegment(line as ISegment, ref before, ref before);
                ISpatialFilter filter = new SpatialFilterClass
                {
                    Geometry   = polyline2,
                    SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
                };
                IFeatureCursor       o         = class2.Search(filter, false);
                ITopologicalOperator operator2 = polyline2 as ITopologicalOperator;
                IFeature             feature3  = o.NextFeature();
                bool     flag       = true;
                double   num3       = 0.0;
                ICurve   curve      = null;
                IPoint   splitPoint = null;
                IFeature feature4   = null;
                while (feature3 != null)
                {
                    if (feature3.OID != feature.OID)
                    {
                        double    num4;
                        IGeometry geometry2 = operator2.Intersect(feature3.Shape,
                                                                  esriGeometryDimension.esriGeometry0Dimension);
                        if (geometry2 is IPoint)
                        {
                            num4 = CommonHelper.distance(geometry2 as IPoint, shape);
                            if (flag)
                            {
                                flag       = false;
                                num3       = num4;
                                splitPoint = geometry2 as IPoint;
                                curve      = feature3.Shape as ICurve;
                                feature4   = feature3;
                            }
                            else if (num3 > num4)
                            {
                                num3       = num4;
                                splitPoint = geometry2 as IPoint;
                                curve      = feature3.Shape as ICurve;
                                feature4   = feature3;
                            }
                        }
                        if (geometry2 is IPointCollection)
                        {
                            IPointCollection points = geometry2 as IPointCollection;
                            for (int i = 0; i < points.PointCount; i++)
                            {
                                IPoint point3 = points.get_Point(i);
                                num4 = CommonHelper.distance(point3, shape);
                                if (flag)
                                {
                                    flag       = false;
                                    num3       = num4;
                                    splitPoint = point3;
                                    curve      = feature3.Shape as ICurve;
                                    feature4   = feature3;
                                }
                                else if (num3 > num4)
                                {
                                    num3       = num4;
                                    splitPoint = point3;
                                    curve      = feature3.Shape as ICurve;
                                    feature4   = feature3;
                                }
                            }
                        }
                    }
                    feature3 = o.NextFeature();
                }
                ComReleaser.ReleaseCOMObject(o);
                if (curve != null)
                {
                    bool flag2;
                    int  num6;
                    int  num7;
                    polyline.SplitAtPoint(splitPoint, true, false, out flag2, out num6, out num7);
                    if (num < num2)
                    {
                        if (num6 > 0)
                        {
                            (polyline as IGeometryCollection).RemoveGeometries(0, num6);
                        }
                        if (num7 > 0)
                        {
                            (polyline as ISegmentCollection).RemoveSegments(0, num7, false);
                        }
                    }
                    else
                    {
                        if (num6 > 0)
                        {
                            (polyline as IGeometryCollection).RemoveGeometries(num6 + 1,
                                                                               (polyline as IGeometryCollection).GeometryCount - num6);
                        }
                        if (num7 > 0)
                        {
                            (polyline as ISegmentCollection).RemoveSegments(num7 + 1,
                                                                            (polyline as ISegmentCollection).SegmentCount - num7, false);
                        }
                    }
                    if (polyline.IsEmpty)
                    {
                        feature.Delete();
                    }
                    else
                    {
                        feature.Shape = polyline;
                        feature.Store();
                    }
                    (curve as IPolycurve).SplitAtPoint(splitPoint, true, false, out flag2, out num6, out num7);
                    feature4.Shape = curve;
                    feature4.Store();
                    return(true);
                }
            }
            return(false);
        }
Пример #5
0
        public IPolyline Cut(IPoint ipoint_0, IPoint ipoint_1, double double_0)
        {
            IPoint    point;
            bool      flag;
            int       num;
            int       num1;
            IPoint    point1;
            int       num2;
            IPolyline polyline;
            IPolyline mPGeometry = this.m_pGeometry as IPolyline;
            bool      flag1      = false;
            int       num3       = -1;
            int       num4       = -1;
            double    num5       = 0;
            int       num6       = -1;
            int       num7       = -1;
            bool      flag2      = GeometryOperator.TestGeometryHit(double_0, ipoint_0, mPGeometry, out point, ref num5, ref num6,
                                                                    ref num3, out flag1);
            bool flag3 = flag2;

            if ((!flag2 ? false : !flag1))
            {
                mPGeometry.SplitAtPoint(point, true, false, out flag, out num, out num1);
                if (flag)
                {
                    GeometryOperator.TestGeometryHit(double_0, ipoint_0, mPGeometry, out point, ref num5, ref num6,
                                                     ref num3, out flag1);
                }
            }
            bool flag4 = GeometryOperator.TestGeometryHit(double_0, ipoint_1, mPGeometry, out point1, ref num5, ref num7,
                                                          ref num4, out flag1);
            bool flag5 = flag4;

            if ((!flag4 ? false : !flag1))
            {
                mPGeometry.SplitAtPoint(point, true, false, out flag, out num, out num1);
                if (flag)
                {
                    if (num3 >= num4)
                    {
                        num3++;
                    }
                    GeometryOperator.TestGeometryHit(double_0, ipoint_1, mPGeometry, out point1, ref num5, ref num7,
                                                     ref num4, out flag1);
                }
            }
            if ((!flag3 ? true : !flag5))
            {
                polyline = null;
            }
            else
            {
                if (num6 > num7)
                {
                    num2 = num6;
                    num6 = num7;
                    num7 = num2;
                    num2 = num3;
                    num3 = num4;
                    num4 = num2;
                }
                else if ((num6 != num7 ? false : num3 > num4))
                {
                    num2 = num3;
                    num3 = num4;
                    num4 = num2;
                }
                polyline = this.method_1(mPGeometry, num6, num3, num7, num4) as IPolyline;
            }
            return(polyline);
        }
Пример #6
0
        /// <summary>
        /// 在交点处打断导入线
        /// </summary>
        /// <param name="srcLine"></param>
        /// <param name="pt"></param>
        /// <returns></returns>
        private static List<IPolyline> SplitLine(IPolyline srcLine, IPoint pt)
        {
            var needSplit = false;
            var index1 = 0;
            var index2 = 0;
            srcLine.SplitAtPoint(pt, false, true, out needSplit, out index1, out index2);

            if (needSplit)
            {
                var gc = srcLine as IGeometryCollection;
                var list = new List<IPolyline>();
                for (var k = 0; k < gc.GeometryCount; k++)
                {
                    var g = gc.Geometry[k];
                    if (g is IPolyline)
                    {
                        list.Add(g as IPolyline);
                    }
                    else if (g is IPath)
                    {
                        var pl = new PolylineClass();
                        var gc2 = pl as IGeometryCollection;
                        gc2.AddGeometry(g as IPath);
                        list.Add(pl);
                    }
                    else
                    {
                        throw new NotSupportedException(string.Format("分割道路的结果类型'{0}'不被支持", g.GeometryType));
                    }
                }
                return list;
            }
            else
            {
                return null;
            }
        }