Exemple #1
0
 public void OnDblClick()
 {
     try
     {
         IEngineEditor     engineEditor = Editor.UniqueInstance.EngineEditor;
         IEngineEditSketch sketch       = Editor.UniqueInstance.EngineEditor as IEngineEditSketch;
         IGeometry         other        = sketch.Geometry;
         if (this.m_Feature == null)
         {
             MessageBox.Show("当前无要素可进行挖空!", "提示");
             Editor.UniqueInstance.CancleSketch();
         }
         else
         {
             if (other.SpatialReference != this.m_Feature.Shape.SpatialReference)
             {
                 other.Project(this.m_Feature.Shape.SpatialReference);
                 other.SpatialReference = this.m_Feature.Shape.SpatialReference;
             }
             ITopologicalOperator2 @operator = other as ITopologicalOperator2;
             @operator.IsKnownSimple_2 = false;
             @operator.Simplify();
             ITopologicalOperator2 shapeCopy = this.m_Feature.ShapeCopy as ITopologicalOperator2;
             shapeCopy.IsKnownSimple_2 = false;
             shapeCopy.Simplify();
             IGeometry geometry2 = shapeCopy.Difference(other);
             Editor.UniqueInstance.StartEditOperation();
             this.m_Feature.Shape = geometry2;
             this.m_Feature.Store();
             Editor.UniqueInstance.StopEditOperation("erase");
             Editor.UniqueInstance.CancleSketch();
             this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, null);
         }
     }
     catch
     {
         Editor.UniqueInstance.CancleSketch();
     }
 }
Exemple #2
0
        private IList <IGeometry> GetGeometrys(IGeometry pGeo)
        {
            IList <IGeometry> list = new List <IGeometry>();

            try
            {
                if (pGeo.GeometryType == esriGeometryType.esriGeometryPolyline)
                {
                    IGeometryCollection geometrys = pGeo as IGeometryCollection;
                    int geometryCount             = geometrys.GeometryCount;
                    for (int i = 0; i < geometryCount; i++)
                    {
                        IGeometry inGeometry = geometrys.get_Geometry(i);
                        if (!inGeometry.IsEmpty)
                        {
                            IGeometryCollection geometrys2 = new PolylineClass();
                            object missing = System.Type.Missing;
                            geometrys2.AddGeometry(inGeometry, ref missing, ref missing);
                            IGeometry item = geometrys2 as IGeometry;
                            item.SpatialReference = pGeo.SpatialReference;
                            list.Add(item);
                        }
                    }
                    return(list);
                }
                if (pGeo.GeometryType == esriGeometryType.esriGeometryPolygon)
                {
                    IPolygon4 polygon = pGeo as IPolygon4;
                    if (polygon.ExteriorRingCount < 2)
                    {
                        list.Add(pGeo);
                        return(list);
                    }
                    IEnumGeometry exteriorRingBag = polygon.ExteriorRingBag as IEnumGeometry;
                    exteriorRingBag.Reset();
                    for (IRing ring = exteriorRingBag.Next() as IRing; ring != null; ring = exteriorRingBag.Next() as IRing)
                    {
                        IGeometryBag        bag2       = polygon.get_InteriorRingBag(ring);
                        object              before     = System.Type.Missing;
                        IGeometryCollection geometrys3 = null;
                        geometrys3 = new PolygonClass();
                        geometrys3.AddGeometry(ring, ref before, ref before);
                        IPolygon polygon2 = geometrys3 as IPolygon;
                        polygon2.SpatialReference = pGeo.SpatialReference;
                        ITopologicalOperator2 @operator = (ITopologicalOperator2)polygon2;
                        @operator.IsKnownSimple_2 = false;
                        @operator.Simplify();
                        if (!bag2.IsEmpty)
                        {
                            IGeometryCollection geometrys4 = new PolygonClass();
                            IEnumGeometry       geometry4  = bag2 as IEnumGeometry;
                            geometry4.Reset();
                            for (IRing ring2 = geometry4.Next() as IRing; ring2 != null; ring2 = geometry4.Next() as IRing)
                            {
                                geometrys4.AddGeometry(ring2, ref before, ref before);
                            }
                            IPolygon other = geometrys4 as IPolygon;
                            other.SpatialReference = pGeo.SpatialReference;
                            ITopologicalOperator2 operator2 = (ITopologicalOperator2)other;
                            operator2.IsKnownSimple_2 = false;
                            operator2.Simplify();
                            IGeometry geometry5 = @operator.Difference(other);
                            list.Add(geometry5);
                        }
                        else
                        {
                            list.Add(polygon2);
                        }
                    }
                }
                return(list);
            }
            catch
            {
                return(null);
            }
            return(list);
        }
Exemple #3
0
        public void OnMouseDown(int button, int shift, int x, int y)
        {
            if (button != 2)
            {
                try
                {
                    IPoint         pGeometry    = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
                    IFeatureClass  featureClass = Editor.UniqueInstance.TargetLayer.FeatureClass;
                    ISpatialFilter queryFilter  = new SpatialFilterClass {
                        Geometry      = pGeometry,
                        GeometryField = featureClass.ShapeFieldName,
                        SubFields     = featureClass.OIDFieldName,
                        SpatialRel    = esriSpatialRelEnum.esriSpatialRelWithin
                    };
                    IFeatureCursor o        = Editor.UniqueInstance.TargetLayer.Search(queryFilter, false);
                    IFeature       feature  = o.NextFeature();
                    IFeature       feature2 = o.NextFeature();
                    Marshal.ReleaseComObject(o);
                    o = null;
                    if ((feature != null) && (feature2 != null))
                    {
                        feature  = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature.OID);
                        feature2 = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature2.OID);
                        ITopologicalOperator2 shape     = feature.Shape as ITopologicalOperator2;
                        IGeometry             geometry1 = feature2.Shape;
                        IGeometry             other     = shape.Intersect(feature2.Shape, esriGeometryDimension.esriGeometry2Dimension);
                        if (!other.IsEmpty)
                        {
                            pGeometry = GISFunFactory.UnitFun.ConvertPoject(pGeometry, other.SpatialReference) as IPoint;
                            IGeometryCollection geometrys = other as IGeometryCollection;
                            if (geometrys.GeometryCount > 1)
                            {
                                for (int i = 0; i < geometrys.GeometryCount; i++)
                                {
                                    IGeometry inGeometry = geometrys.get_Geometry(i);
                                    if (!inGeometry.IsEmpty)
                                    {
                                        if (inGeometry.GeometryType == esriGeometryType.esriGeometryRing)
                                        {
                                            object missing = System.Type.Missing;
                                            IGeometryCollection geometrys2 = new PolygonClass();
                                            geometrys2.AddGeometry(inGeometry, ref missing, ref missing);
                                            IPolygon polygon = geometrys2 as IPolygon;
                                            inGeometry = polygon;
                                        }
                                        IRelationalOperator operator2 = inGeometry as IRelationalOperator;
                                        if ((operator2 != null) && operator2.Contains(pGeometry))
                                        {
                                            other = inGeometry;
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                IRelationalOperator operator3 = other as IRelationalOperator;
                                if (!operator3.Contains(pGeometry))
                                {
                                    return;
                                }
                            }
                            feature  = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature.OID);
                            feature2 = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature2.OID);
                            if (other.GeometryType != esriGeometryType.esriGeometryPolygon)
                            {
                                IPolygon polygon2 = new PolygonClass {
                                    SpatialReference = other.SpatialReference
                                };
                                IPointCollection newPoints = other as IPointCollection;
                                (polygon2 as IPointCollection).AddPointCollection(newPoints);
                                other = polygon2;
                            }
                            Editor.UniqueInstance.StartEditOperation();
                            ITopologicalOperator2 operator4 = feature.Shape as ITopologicalOperator2;
                            IGeometry             geometry3 = operator4.Difference(other);
                            if (geometry3.IsEmpty)
                            {
                                feature.Delete();
                            }
                            else
                            {
                                feature.Shape = geometry3;
                                feature.Store();
                            }
                            geometry3 = (feature2.Shape as ITopologicalOperator2).Difference(other);
                            if (geometry3.IsEmpty)
                            {
                                feature2.Delete();
                            }
                            else
                            {
                                feature2.Shape = geometry3;
                                feature2.Store();
                            }

                            Editor.UniqueInstance.StopEditOperation();
                            (Editor.UniqueInstance.TargetLayer as IFeatureSelection).Clear();
                            this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, this.m_hookHelper.ActiveView.Extent);
                            MessageBox.Show("修改完成!", "提示");
                        }
                    }
                }
                catch (Exception exception)
                {
                    Editor.UniqueInstance.AbortEditOperation();
                    this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.OverlapDelete", "OnMouseDown", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
                    MessageBox.Show("修改出错!", "提示");
                }
            }
        }