/// <summary> /// 验证指定的要素是否在裁切范围内 /// </summary> /// <param name="pFeatureGeometry"></param> /// <returns></returns> public virtual bool FeatureInCutRegion(IGeometry pFeatureGeometry) { try { if (pFeatureGeometry == null) return false; IRelationalOperator pRelation = m_CutGeometry as IRelationalOperator; if (pRelation.Crosses(pFeatureGeometry) || pRelation.Contains(pFeatureGeometry) || pRelation.Touches(pFeatureGeometry)|| pRelation.Overlaps(pFeatureGeometry) || pRelation.Within(pFeatureGeometry) || pRelation.Equals(pFeatureGeometry)) return true; return false; } catch (Exception ex) { LogAPI.WriteLog("判断裁切范围时出错,系统将不对【" + StructureNode.TableName + "】进行裁切!\r\n"); return false; } }
protected IArray SplitLine(IGeometryBag igeometryBag_0) { int i; IPolyline geometry; int j; IPointCollection pointCollection; IGeometryCollection igeometryBag0 = (IGeometryCollection)igeometryBag_0; IPointCollection[] multipointClass = new IPointCollection[igeometryBag0.GeometryCount]; for (i = 0; i < igeometryBag0.GeometryCount; i++) { multipointClass[i] = new Multipoint(); } for (i = 0; i < igeometryBag0.GeometryCount; i++) { geometry = igeometryBag0.Geometry[i] as IPolyline; if (geometry != null) { for (j = i + 1; j < igeometryBag0.GeometryCount; j++) { IPolyline polyline = igeometryBag0.Geometry[j] as IPolyline; if (polyline != null) { IRelationalOperator relationalOperator = (IRelationalOperator)geometry; ITopologicalOperator topologicalOperator = (ITopologicalOperator)geometry; if (relationalOperator.Crosses(polyline)) { IGeometry geometry1 = topologicalOperator.Intersect(polyline, esriGeometryDimension.esriGeometry0Dimension); if (geometry1 != null && geometry1 is IPointCollection) { pointCollection = multipointClass[i]; pointCollection.AddPointCollection((IPointCollection)geometry1); pointCollection = multipointClass[j]; pointCollection.AddPointCollection((IPointCollection)geometry1); } } } } } } IArray arrayClass = new Array(); try { for (i = 0; i < igeometryBag0.GeometryCount; i++) { geometry = igeometryBag0.Geometry[i] as IPolyline; if (geometry != null) { pointCollection = multipointClass[i]; if (pointCollection.PointCount != 0) { ((IPolycurve2)geometry).SplitAtPoints(pointCollection.EnumVertices, true, true, -1); IGeometryCollection geometryCollection = (IGeometryCollection)geometry; for (j = 0; j < geometryCollection.GeometryCount; j++) { IGeometry geometry2 = geometryCollection.Geometry[j]; IGeometryCollection polylineClass = new Polyline() as IGeometryCollection; polylineClass.AddGeometries(1, ref geometry2); if (!((ITopologicalOperator)polylineClass).IsSimple) { ((ITopologicalOperator)polylineClass).Simplify(); } this.method_0(arrayClass, polylineClass as IGeometry); } } else if (geometry.IsClosed) { this.method_0(arrayClass, geometry); } } } } catch { } return(arrayClass); }
private void DWIntersect(CPolyline pBSCpl, ref List <CPoint> cptlt, double dblIgnorableDis) { IPointCollection4 pCol = new PolylineClass(); for (int i = 0; i < cptlt.Count; i++) { cptlt[i].SetPoint(); pCol.AddPoint(cptlt[i].pPoint); } IPolyline5 ipl = pCol as IPolyline5; pBSCpl.SetPolyline(); IRelationalOperator pRel = pBSCpl.pPolyline as IRelationalOperator; bool isCrosses = pRel.Crosses(ipl); if (isCrosses == true) { ITopologicalOperator pTop = pBSCpl.pPolyline as ITopologicalOperator; IGeometry pGeoIntersect = pTop.Intersect(ipl, esriGeometryDimension.esriGeometry0Dimension); IPointCollection4 pColIntersect = pGeoIntersect as IPointCollection4; double dblMaxDis = 0; for (int j = 0; j < pColIntersect.PointCount; j++) { double dblDis = CGeoFunc.CalDistanceFromStartPoint(ipl, pColIntersect.get_Point(j), false); if (dblDis > dblMaxDis) { dblMaxDis = dblDis; } } ICurve pSubCurve; ipl.GetSubcurve(dblMaxDis, ipl.Length, false, out pSubCurve); //IPolyline5 Cutipl = pSubCurve as IPolyline5; IPointCollection4 iplCutCol = pSubCurve as IPointCollection4; //the new first segment IPointCollection4 pSegCol = new PolylineClass(); pSegCol.AddPoint(ipl.FromPoint, _Missing, _Missing); pSegCol.AddPoint(iplCutCol.get_Point(1), _Missing, _Missing); IPolyline5 seg = pSegCol as IPolyline5; bool isCrossesSeg; int intIndex = 0; while (intIndex < iplCutCol.PointCount - 1) { intIndex++; pSegCol.UpdatePoint(1, iplCutCol.get_Point(intIndex)); isCrossesSeg = pRel.Crosses(seg); if (isCrossesSeg == false) { iplCutCol.RemovePoints(1, intIndex - 1); iplCutCol.UpdatePoint(0, ipl.FromPoint); break; } if (seg.Length >= dblIgnorableDis) { double dblOriginalIntersectionDis = CGeoFunc.CalDistanceFromStartPoint(pBSCpl.pPolyline, pCol.get_Point(0), false); double dblRealisticIntersectionDis = CGeoFunc.CalDistanceFromStartPoint(pBSCpl.pPolyline, iplCutCol.get_Point(0), false); IPointCollection4 pColBSCpl = pBSCpl.pPolyline as IPointCollection4; double dblSumDis = 0; for (int i = 0; i < pColBSCpl.PointCount - 1; i++) { double dblDis = CGeoFunc.CalDis(pColBSCpl.get_Point(i), pColBSCpl.get_Point(i + 1)); dblSumDis += dblDis; if (dblSumDis >= dblRealisticIntersectionDis) { double dblDisPre = Math.Abs(dblSumDis - dblDis - dblOriginalIntersectionDis); double dblDisNext = Math.Abs(dblSumDis - dblOriginalIntersectionDis); IPoint intersectpt = new PointClass(); if (dblDisPre <= dblDisNext) { intersectpt = pColBSCpl.get_Point(i); } else { intersectpt = pColBSCpl.get_Point(i + 1); } iplCutCol.UpdatePoint(0, intersectpt); break; } } break; } } cptlt = CHelpFunc.GetCptEbByICol(iplCutCol).ToList(); } }
//剪裁输出forShp public static void cutExportShp(IFeatureCursor pfeaturecursor, IFeatureClass pfeatureclass, IGeometry pgeometry, int featurecount) { progressStep.Minimum = 0; progressStep.Maximum = featurecount; progressStep.Step = 1; IFeature pFeature = pfeaturecursor.NextFeature(); if (pFeature == null) { return; } IFeatureCursor pFeatureCursor = pfeatureclass.Insert(true); ISegmentCollection pSegmentCol = new PolygonClass(); if (pgeometry.GeometryType == esriGeometryType.esriGeometryEnvelope) { IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope = pgeometry as IEnvelope; pSegmentCol.SetRectangle(pEnvelope); pgeometry = pSegmentCol as IGeometry; } else if (pgeometry.GeometryType == esriGeometryType.esriGeometryCircularArc) { ICircularArc pCircularArc = new CircularArcClass(); pCircularArc = pgeometry as ICircularArc; object obj = System.Reflection.Missing.Value; pSegmentCol.AddSegment((ISegment)pCircularArc, ref obj, ref obj); pgeometry = pSegmentCol as IGeometry; } ITopologicalOperator pTopoOp = (ITopologicalOperator)pgeometry; IGeometry pBndGeom = pTopoOp.Boundary; esriGeometryDimension iDimension; IGeometry pAimGeometry = pFeature.ShapeCopy; if (pAimGeometry.Dimension < pgeometry.Dimension) { iDimension = pAimGeometry.Dimension; } else { iDimension = pgeometry.Dimension; } int iCount = 0; while (pFeature != null) { IFeatureBuffer pFeatureBuffer = pfeatureclass.CreateFeatureBuffer(); IFeature pAimFeature = (IFeature)pFeatureBuffer; pAimGeometry = pFeature.ShapeCopy; IRelationalOperator pRelOpeator = (IRelationalOperator)pAimGeometry; for (int i = 0; i < pFeature.Fields.FieldCount; i++) { //IField pFld = pAimFeature.Fields.get_Field(i); //if ((pFld.Editable == true) && pFld.Type != esriFieldType.esriFieldTypeGeometry) //{ // try // { // pAimFeature.set_Value(i, pFeature.get_Value(i)); // } // catch // { } //} string sFieldName = pFeature.Fields.get_Field(i).Name; int iIndex = -1; if (m_DicFields.Keys.Contains(sFieldName)) { iIndex = pFeatureBuffer.Fields.FindField(m_DicFields[sFieldName]); } else { iIndex = pFeatureBuffer.Fields.FindField(sFieldName); } if (iIndex == -1) { continue; } IField pFld = pAimFeature.Fields.get_Field(iIndex); if ((iIndex > -1) && (pFld.Editable == true) && pFld.Type != esriFieldType.esriFieldTypeGeometry) { pAimFeature.set_Value(iIndex, pFeature.get_Value(i)); } } if (pAimGeometry.GeometryType == esriGeometryType.esriGeometryPoint) { pAimFeature.Shape = pFeature.ShapeCopy; } //判断是否相交或者包含关系,如果是则进行空间切割 else { bool bCross = false; bool bContain = false; try { bCross = pRelOpeator.Crosses(pBndGeom);//changed by chulili 20111213 这句话可能报错,不要直接放在IF条件里 } catch { } try { bContain = pRelOpeator.Contains(pBndGeom);//changed by chulili 20111213 这句话可能报错 } catch { } if (bCross || bContain) { pTopoOp = (ITopologicalOperator)pFeature.ShapeCopy; pTopoOp.Simplify(); pAimFeature.Shape = pTopoOp.Intersect(pgeometry, iDimension); } else { pAimFeature.Shape = pFeature.ShapeCopy; } } pFeatureCursor.InsertFeature(pFeatureBuffer); if (iCount == 500) { pFeatureCursor.Flush(); iCount = 0; } iCount = iCount + 1; progressStep.PerformStep(); pFeature = pfeaturecursor.NextFeature(); } if (iCount > 0) { pFeatureCursor.Flush(); } System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor); pFeatureCursor = null; }