예제 #1
0
        //<CSCM>
        //********************************************************************************
        //** 函 数 名: IntersectTwoGeometry
        //** 版    权: CopyRight (C)
        //** 创 建 人: 杨旭斌
        //** 功能描述: 二个图形求差
        //** 创建日期:
        //** 修 改 人:
        //** 修改日期:
        //** 修改时间: 20070818
        //** 参数列表: pOriGeometry (IGeometry)
        //         pDesGeometry (IGeometry)
        //** 版    本:1.0
        //*********************************************************************************
        //</CSCM>
        public static IGeometry IntersectTwoGeometry(IGeometry pOriGeometry, IGeometry pDesGeometry)
        {
            IGeometry             functionReturnValue = default(IGeometry);
            ITopologicalOperator2 pTopoOperator       = default(ITopologicalOperator2);
            ITopologicalOperator2 pTopoOperator2      = default(ITopologicalOperator2);
            IGeometry             pGeometry           = default(IGeometry);

            // ERROR: Not supported in C#: OnErrorStatement
            try
            {
                pTopoOperator = (ITopologicalOperator2)pOriGeometry;
                pTopoOperator.IsKnownSimple_2 = false;
                pTopoOperator.Simplify();

                pTopoOperator2 = (ITopologicalOperator2)pDesGeometry;
                pTopoOperator2.IsKnownSimple_2 = false;
                pTopoOperator2.Simplify();
                pGeometry     = pTopoOperator.Intersect((IGeometry)pTopoOperator2, esriGeometryDimension.esriGeometry2Dimension);
                pTopoOperator = (ITopologicalOperator2)pGeometry;
                pTopoOperator.IsKnownSimple_2 = false;
                pTopoOperator.Simplify();
                functionReturnValue = (IGeometry)pTopoOperator;
                return(functionReturnValue);
            }
            catch (Exception)
            {
                functionReturnValue = null;
                return(functionReturnValue);
            }
        }
예제 #2
0
        //<CSCM>
        //********************************************************************************
        //** 函 数 名: CutFeatByGeometry
        //** 版    权: CopyRight (C)
        //** 创 建 人: 杨旭斌
        //** 功能描述: 根据传入的图形,剪切需要被剪切的要素
        //** 创建日期:
        //** 修 改 人:
        //** 修改日期:
        //** 修改时间: 2006-10-13
        //** 参数列表: pOriGeometry (IGeometry)'需要被剪切的要素
        //             pRefGeometry (IGeometry)'参照要素
        //             EnumGeometryDimension (esriGeometryDimension)'返回的图形的维数
        //               线:esriGeometry1Dimension 用于面剪切线;
        //               面:esriGeometry2Dimension 用于面剪切面
        //** 版    本:1.0
        //*********************************************************************************
        //</CSCM>
        public static IGeometry CutFeatByGeometry(ref IGeometry pOriGeometry, ref IGeometry pRefGeometry, ref esriGeometryDimension EnumGeometryDimension)
        {
            IGeometry             functionReturnValue = default(IGeometry);
            ITopologicalOperator2 pTopoOperator       = default(ITopologicalOperator2);
            ITopologicalOperator2 pTopoOperator2      = default(ITopologicalOperator2);
            //原要素和参照要素相交的部分
            IGeometry pGeometry = default(IGeometry);

            // ERROR: Not supported in C#: OnErrorStatement
            try
            {
                pTopoOperator = (ITopologicalOperator2)pRefGeometry;
                pTopoOperator.IsKnownSimple_2 = false;
                pTopoOperator.Simplify();
                pTopoOperator2 = (ITopologicalOperator2)pOriGeometry;
                pTopoOperator2.IsKnownSimple_2 = false;
                pTopoOperator2.Simplify();
                //根据不同的需要返回点,线,面等相交的部分
                pGeometry     = pTopoOperator2.Intersect((IGeometry)pTopoOperator, EnumGeometryDimension);
                pTopoOperator = (ITopologicalOperator2)pGeometry;
                pTopoOperator.IsKnownSimple_2 = false;
                pTopoOperator.Simplify();
                functionReturnValue = (IGeometry)pTopoOperator;
                return(functionReturnValue);
            }
            catch (Exception)
            {
                functionReturnValue = null;
                return(functionReturnValue);
            }
        }
예제 #3
0
 public void OnMouseDown(int button, int shift, int x, int y)
 {
     try
     {
         IPoint         point        = this._hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
         IFeatureClass  featureClass = Editor.UniqueInstance.TargetLayer.FeatureClass;
         ISpatialFilter queryFilter  = new SpatialFilterClass {
             Geometry      = point,
             GeometryField = featureClass.ShapeFieldName,
             SubFields     = featureClass.ShapeFieldName,
             SpatialRel    = esriSpatialRelEnum.esriSpatialRelWithin
         };
         IFeatureCursor o       = Editor.UniqueInstance.TargetLayer.Search(queryFilter, false);
         IFeature       feature = o.NextFeature();
         Marshal.ReleaseComObject(o);
         o = null;
         if ((feature != null) && (feature.OID != this._feature.OID))
         {
             feature = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature.OID);
             ITopologicalOperator2 shape = this._feature.Shape as ITopologicalOperator2;
             shape.IsKnownSimple_2 = false;
             shape.Simplify();
             shape = feature.Shape as ITopologicalOperator2;
             shape.IsKnownSimple_2 = false;
             shape.Simplify();
             shape = shape.Union(this._feature.Shape) as ITopologicalOperator2;
             shape.IsKnownSimple_2 = false;
             shape.Simplify();
             Editor.UniqueInstance.StartEditOperation();
             Editor.UniqueInstance.AddAttribute = false;
             List <IFeature> pFeatureList = new List <IFeature> {
                 this._feature,
                 feature
             };
             IFeature resultFeature = Editor.UniqueInstance.TargetLayer.FeatureClass.CreateFeature();
             resultFeature.Shape = shape as IGeometry;
             if (AttributeManager.AttributeCombineHandleClass.AttributeCombine(pFeatureList, ref resultFeature) == DialogResult.OK)
             {
                 resultFeature.Store();
                 foreach (IFeature feature3 in pFeatureList)
                 {
                     feature3.Delete();
                 }
                 IFeatureSelection targetLayer = Editor.UniqueInstance.TargetLayer as IFeatureSelection;
                 targetLayer.Clear();
                 targetLayer.Add(resultFeature);
                 this._hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, Editor.UniqueInstance.TargetLayer, resultFeature.Extent);
             }
             Editor.UniqueInstance.StopEditOperation("combineex");
         }
     }
     catch (Exception exception)
     {
         Editor.UniqueInstance.AbortEditOperation();
         this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.CombineEx", "OnMouseDown", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
     }
 }
예제 #4
0
        /// <summary>
        /// 简化几何形状
        /// 对传入的几何形状直接进行简化
        /// 主要在编辑时使用
        /// </summary>
        /// <param name="geometry">需要被简化的几何形状</param>
        public static void Simplify(IGeometry geometry)
        {
            if (geometry != null)
            {
                if (geometry is ITopologicalOperator2)
                {
                    ITopologicalOperator2 topoOp = geometry as ITopologicalOperator2;
                    topoOp.IsKnownSimple_2 = false;
                    switch (geometry.GeometryType)
                    {
                    case esriGeometryType.esriGeometryPolygon:
                    {
                        IPolygon poly = (IPolygon)geometry;
                        poly.SimplifyPreserveFromTo();
                        break;
                    }

                    case esriGeometryType.esriGeometryPolyline:
                    {
                        IPolyline polyLineGeom = (IPolyline)geometry;
                        polyLineGeom.SimplifyNetwork();
                        break;
                    }

                    default:
                    {
                        topoOp.Simplify();
                        break;
                    }
                    }
                }
            }
        }
예제 #5
0
        /// 合并列表中所有多边形
        /// </summary>
        /// <param name="orifeature">保留源对象</param>
        /// <param name="geolist">图形列表</param>
        /// <returns></returns>
        public void CreatePolygonFromExistingGeometries(IFeatureLayer lyr, IFeature orifeature, List <IGeometry> geolist)
        {
            int            i            = 0;
            IGeometry      geometry     = null;
            IFeatureClass  Featureclass = lyr.FeatureClass;
            IWorkspaceEdit workspace    = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;

            workspace.StartEditing(false);
            workspace.StartEditOperation();
            //合并图形
            ITopologicalOperator2 topologicalOperator2 = orifeature.ShapeCopy as ITopologicalOperator2;

            for (i = 0; i < geolist.Count; i++)
            {
                IGeometry geo = geolist[i];
                if (geometry != null)
                {
                    topologicalOperator2 = geometry as ITopologicalOperator2;
                }
                ITopologicalOperator opertor = geo as ITopologicalOperator;
                opertor.Simplify();
                topologicalOperator2.IsKnownSimple_2 = false;
                topologicalOperator2.Simplify();
                geometry = topologicalOperator2.Union(geo);
            }
            //更新图形对象
            IGeometry geoCombined = (IGeometry)geometry;

            orifeature.Shape = geoCombined as IGeometry;
            orifeature.Store();

            workspace.StopEditOperation();
            workspace.StopEditing(true);
        }
예제 #6
0
        //获取矿界
        private IPolygon GetPolygon()
        {
            IPolygon      polygon2     = null;
            ILayer        pLayer       = DataEditCommon.GetLayerByName(DataEditCommon.g_pMap, LayerNames.LAYER_ALIAS_MINE_BOUNDARY);
            IFeatureLayer polygonLayer = (IFeatureLayer)pLayer;

            IQueryFilter filter = new QueryFilterClass();

            filter.WhereClause = "layer = '预警矿界'";

            IFeatureLayer         featureLayer        = polygonLayer as IFeatureLayer;
            IFeatureCursor        featureCursor       = featureLayer.Search(filter, false);
            ITopologicalOperator2 topologicalOperator = null;

            //  获得矿界组合成面
            if (featureCursor != null)
            {
                ISegmentCollection polygon = new PolygonClass();

                IFeature feature = featureCursor.NextFeature();

                while (feature != null)
                {
                    polygon.AddSegmentCollection((ISegmentCollection)feature.Shape);
                    feature = featureCursor.NextFeature();
                }

                topologicalOperator = (ITopologicalOperator2)polygon;
                topologicalOperator.IsKnownSimple_2 = true;
                topologicalOperator.Simplify();

                polygon2 = (IPolygon)topologicalOperator;
            }
            return(polygon2);
        }
예제 #7
0
 private void InitOtherLayer(IGeometry pGeo)
 {
     if (this._linkLayers != null)
     {
         ISpatialFilter filter = new SpatialFilterClass {
             Geometry = pGeo
         };
         foreach (IFeatureLayer layer in this._linkLayers)
         {
             if (layer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
             {
                 filter.SubFields     = layer.FeatureClass.ShapeFieldName;
                 filter.GeometryField = layer.FeatureClass.ShapeFieldName;
                 filter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelTouches;
                 IFeatureCursor o        = layer.FeatureClass.Search(filter, false);
                 IFeature       pFeature = o.NextFeature();
                 IFeature       feature2 = o.NextFeature();
                 IFeature       feature3 = o.NextFeature();
                 Marshal.ReleaseComObject(o);
                 o = null;
                 if (((pFeature != null) && (feature2 != null)) && (feature3 == null))
                 {
                     ITopologicalOperator2 shapeCopy = pFeature.ShapeCopy as ITopologicalOperator2;
                     shapeCopy.IsKnownSimple_2 = false;
                     shapeCopy.Simplify();
                     shapeCopy = feature2.ShapeCopy as ITopologicalOperator2;
                     shapeCopy.IsKnownSimple_2 = false;
                     shapeCopy.Simplify();
                     if (!shapeCopy.Intersect(pFeature.ShapeCopy, esriGeometryDimension.esriGeometry1Dimension).IsEmpty)
                     {
                         IRelationalOperator operator2 = shapeCopy.Union(pFeature.ShapeCopy) as IRelationalOperator;
                         if (operator2.Contains(this._editBound))
                         {
                             this._las.Add(new LinkArgs(pFeature));
                             this._las.Add(new LinkArgs(feature2));
                             Marshal.ReleaseComObject(o);
                             o = null;
                         }
                     }
                 }
             }
         }
     }
 }
예제 #8
0
        //<CSCM>
        //********************************************************************************
        //** 函 数 名: GetCursorByFieldAndValue
        //** 版    权: CopyRight (C)
        //** 创 建 人: 杨旭斌
        //** 功能描述: 给出查询信息后,返回一个满足范围的光标
        //
        //** 创建日期:
        //** 修 改 人:
        //** 修改日期:
        //** 修改时间: 20070817
        //** 参数列表: sValue (String)
        //         sFieldName (String)
        //         pFeatCls (IFeatureClass)
        //** 版    本:1.0
        //*********************************************************************************
        //</CSCM>
        public static IFeatureCursor GetFeatCursor(IFeatureClass pFeatCls, string sSQLExpress, esriSpatialRelEnum EnumSpatialRel,
                                                   ref IGeometry pDomainGeometry, bool bGetFeatCount, ref long lFeatCount)
        {
            //sSQLExpress = "";
            //EnumSpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            //pDomainGeometry = null;
            //bGetFeatCount = false;
            //lFeatCount = 0;

            IFeatureCursor        functionReturnValue = default(IFeatureCursor);
            ISpatialFilter        pSpatialfilter      = default(ISpatialFilter);
            ITopologicalOperator2 pTopoOperator       = default(ITopologicalOperator2);
            IFeatureCursor        pFeatCursor         = default(IFeatureCursor);

            // ERROR: Not supported in C#: OnErrorStatement

            try
            {
                if (pFeatCls == null)
                {
                    functionReturnValue = null;
                    return(functionReturnValue);
                }
                pSpatialfilter             = new SpatialFilter();
                pSpatialfilter.WhereClause = sSQLExpress;
                //范围一起查询,提高查询效率
                if (pDomainGeometry != null)
                {
                    pTopoOperator = (ITopologicalOperator2)pDomainGeometry;
                    pTopoOperator.IsKnownSimple_2 = false;
                    pTopoOperator.Simplify();
                    pSpatialfilter.Geometry   = (IGeometry)pTopoOperator;
                    pSpatialfilter.SpatialRel = EnumSpatialRel;
                }
                //获得一个新的选择集
                pFeatCursor = pFeatCls.Search(pSpatialfilter, false);
                //如果需要获得要满足条件的个数,则获得
                if (bGetFeatCount)
                {
                    lFeatCount = pFeatCls.FeatureCount(pSpatialfilter);
                }
                functionReturnValue = pFeatCursor;
                return(functionReturnValue);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147216117)
                {
                    MessageBoxEx.Show("失去了与SDE服务器的连接,提取失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
                functionReturnValue = null;
                return(functionReturnValue);
            }
        }
예제 #9
0
        private void TrimPolyline(IFeature trimFeature, IFeature targetFeature, IPoint secondPoint)
        {
            IGeometry      preservedGeom   = null;
            IGeometry      leftGeom        = null;
            IGeometry      rightGeom       = null;
            double         distanceOnCurve = 0;
            double         nearestDistance = 0;
            bool           isRightSide     = false;
            IPoint         outPoint        = new PointClass();
            IFeatureClass  featureClass    = trimFeature.Class as IFeatureClass;
            IDataset       dataset         = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit   = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }


            try
            { IGeometry             targetGeometry = targetFeature.ShapeCopy;
              IGeometry             trimGeometry   = trimFeature.ShapeCopy;
              ITopologicalOperator2 topo           = trimGeometry as ITopologicalOperator2;
              topo.IsKnownSimple_2 = false;
              topo.Simplify();
              ITopologicalOperator2 topo2 = targetGeometry as ITopologicalOperator2;
              topo2.IsKnownSimple_2 = false;
              topo2.Simplify();
              topo.Cut(targetGeometry as IPolyline, out leftGeom, out rightGeom);
              ICurve curve = targetGeometry as ICurve;
              curve.QueryPointAndDistance(esriSegmentExtension.esriNoExtension, secondPoint, false, outPoint, ref distanceOnCurve, ref nearestDistance, ref isRightSide);
              if (isRightSide)
              {
                  preservedGeom = leftGeom;
              }
              else
              {
                  preservedGeom = rightGeom;
              }
              workspaceEdit.StartEditOperation();
              trimFeature.Shape = preservedGeom;
              trimFeature.Store();
              workspaceEdit.StopEditOperation();
              FlashGeometry(trimGeometry as IGeometry, 3, 10); }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                MessageBox.Show("线要素延伸失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #10
0
        //<CSCM>
        //********************************************************************************
        //** 函 数 名: getFeatSelection
        //** 版    权: CopyRight (C)
        //** 创 建 人: 杨旭斌
        //** 功能描述: 由非标准的sSQL表达式获得选择集,如果SQL为空的话,默认选择要素类内的所有要素
        //** 创建日期:
        //** 修 改 人:
        //** 修改日期:
        //** 修改时间: 20070813
        //** 参数列表: pFeatSelection (IFeatureSelection)传入的选择集,
        //             sSQLExpress (String)
        //             pDomainGeometry  如果有范围的时和范围一起进行查寻,提高效率
        //             EnumSelectMethod 选择方式:添加,新建等
        //** 版    本:1.0
        //*********************************************************************************
        //</CSCM>
        public static IFeatureSelection GetFeatSelection(ref IFeatureLayer pFeatLayer, string sSQLExpress, esriSelectionResultEnum EnumSelectMethod, esriSpatialRelEnum EnumSpatialRel, ref IGeometry pDomainGeometry)
        {
            //sSQLExpress = "";
            //EnumSelectMethod = esriSelectionResultEnum.esriSelectionResultNew;
            //EnumSpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
            //pDomainGeometry = null;

            IFeatureSelection     functionReturnValue = default(IFeatureSelection);
            ISpatialFilter        pSpatialfilter      = default(ISpatialFilter);
            ITopologicalOperator2 pTopoOperator       = default(ITopologicalOperator2);
            IFeatureSelection     pFeatSelection      = default(IFeatureSelection);

            // ERROR: Not supported in C#: OnErrorStatement

            try
            {
                if (pFeatLayer == null)
                {
                    functionReturnValue = null;
                    return(functionReturnValue);
                }

                pFeatSelection             = (IFeatureSelection)pFeatLayer;
                pSpatialfilter             = new SpatialFilter();
                pSpatialfilter.WhereClause = sSQLExpress;
                //范围一起查询,提高查询效率
                if (pDomainGeometry != null)
                {
                    pTopoOperator = (ITopologicalOperator2)pDomainGeometry;
                    pTopoOperator.IsKnownSimple_2 = false;
                    pTopoOperator.Simplify();
                    pSpatialfilter.Geometry   = (IGeometry)pTopoOperator;
                    pSpatialfilter.SpatialRel = EnumSpatialRel;
                }
                //获得一个新的选择集
                pFeatSelection.SelectFeatures(pSpatialfilter, EnumSelectMethod, false);
                functionReturnValue = pFeatSelection;
                return(functionReturnValue);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                if (ex.ErrorCode == -2147216117)
                {
                    MessageBoxEx.Show("失去了与SDE服务器的连接,提取失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }
                functionReturnValue = null;
                return(functionReturnValue);
            }
        }
예제 #11
0
        /// <summary>
        /// 简化几何形状
        /// 不直接对传入的几何形状进行简化,而是克隆传入参数再进行简化出结果
        /// 主要在编辑时使用
        /// </summary>
        /// <param name="geometry">需要被简化的几何形状</param>
        /// <returns>简化后的几何形状</returns>
        public static IGeometry QuerySimplify(IGeometry geometry)
        {
            if (geometry == null)
            {
                return(null);
            }
            else
            {
                IGeometry geom = (geometry as IClone).Clone() as IGeometry;
                if (geom is ITopologicalOperator2)
                {
                    ITopologicalOperator2 topoOp = geom as ITopologicalOperator2;
                    topoOp.IsKnownSimple_2 = false;

                    switch (geom.GeometryType)
                    {
                    case esriGeometryType.esriGeometryPolygon:
                    {
                        IPolygon poly = (IPolygon)geom;
                        poly.SimplifyPreserveFromTo();
                        return(poly);
                    }

                    case esriGeometryType.esriGeometryPolyline:
                    {
                        IPolyline polyLineGeom = (IPolyline)geom;
                        polyLineGeom.SimplifyNetwork();
                        return(polyLineGeom);
                    }

                    default:
                    {
                        topoOp.Simplify();
                        return((IGeometry)topoOp);
                    }
                    }
                }
                else
                {
                    return(geometry);
                }
            }
        }
예제 #12
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (Button != 1)
            {
                return;
            }
            IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2;

            ESRI.ArcGIS.Geometry.IGeometry pGeometry = null;
            pGeometry = pMapCtl.TrackLine();//控件画线
            if (pGeometry == null)
            {
                return;
            }
            //简化拓扑
            ITopologicalOperator2 topoOperator = pGeometry as ITopologicalOperator2;

            topoOperator.IsKnownSimple_2 = false;
            topoOperator.Simplify();
            splitFeature(pGeometry);
        }
예제 #13
0
        /// <summary>
        /// 对地类图斑进行拓扑纠正
        /// </summary>
        public void SimplifyDLTB()
        {
            IFeatureCursor dltbCursor = pDLTBFeatureLayer.FeatureClass.Search(null, true);
            IFeature       feature    = dltbCursor.NextFeature();

            while (feature != null)
            {
                ITopologicalOperator2 pTopo = (ITopologicalOperator2)feature.ShapeCopy;
                //if (pTopo.IsSimple)
                //{
                //    feature = dltbCursor.NextFeature();
                //    continue;
                //}
                pTopo.IsKnownSimple_2 = false;
                pTopo.Simplify();
                feature.Shape = pTopo as IGeometry;
                feature.Store();
                feature = dltbCursor.NextFeature();
            }
            Marshal.ReleaseComObject(dltbCursor);
        }
예제 #14
0
파일: Erase.cs 프로젝트: 605258778/GISData
 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();
     }
 }
예제 #15
0
        /// <summary>
        /// 获得当前视图上的选择要素
        /// </summary>
        /// <param name="pMap"></param>
        /// <returns></returns>
        private IGeometry ConstructUnion(IMap pMap)
        {
            ISelection pSelection = pMap.FeatureSelection;

            //
            IEnumFeature pEnumFeature = pSelection as IEnumFeature;
            IFeature     pFeature     = pEnumFeature.Next();

            //考虑到有点 线 面的情况 所以只选第一个要素
            if (pFeature == null)
            {
                return(null);
            }

            IGeometry             pGeometry = pFeature.ShapeCopy;
            ITopologicalOperator2 pTopo2    = pGeometry as ITopologicalOperator2;

            pTopo2.IsKnownSimple_2 = false;
            pTopo2.Simplify();

            return(pTopo2 as IGeometry);
        }
예제 #16
0
        /// <summary>
        /// Simplifies the geometry.
        /// </summary>
        /// <param name="inputGeometry">The input geometry.</param>
        /// <returns></returns>
        public static IGeometry SimplifyGeometry(IGeometry inputGeometry)
        {
            // Validate the arguments
            if (inputGeometry == null)
            {
                throw new ArgumentNullException("inputGeometry", "Failed to simplify geometry. Input geometry has not been set.");
            }

            ITopologicalOperator2 topologicalOperator = inputGeometry as ITopologicalOperator2;

            if (topologicalOperator == null)
            {
                throw new ArgumentException("Failed to simplify geometry. Input geometry must be a polyline, polygon, multipoint or multipatch.");
            }

            // Simplify the geometry
            topologicalOperator.IsKnownSimple_2 = false;
            topologicalOperator.Simplify();

            // Return simple geometry
            return(inputGeometry);
        }
예제 #17
0
 public void OnMouseUp(int button, int shift, int x, int y)
 {
     if (button != 2)
     {
         IPoint    pPoint         = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
         IEnvelope searchEnvelope = FeatureFuncs.GetSearchEnvelope(this.m_hookHelper.ActiveView, pPoint);
         IFeature  feature        = FeatureFuncs.SearchFeatures(Editor.UniqueInstance.TargetLayer, searchEnvelope, esriSpatialRelEnum.esriSpatialRelIntersects).NextFeature();
         if (feature != null)
         {
             ITopologicalOperator2 shape = feature.Shape as ITopologicalOperator2;
             Editor.UniqueInstance.StartEditOperation();
             shape.IsKnownSimple_2 = false;
             shape.Simplify();
             Editor.UniqueInstance.StopEditOperation("simplify");
             IActiveView       activeView  = this.m_hookHelper.ActiveView;
             IFeatureSelection targetLayer = Editor.UniqueInstance.TargetLayer as IFeatureSelection;
             targetLayer.Clear();
             targetLayer.Add(feature);
             activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, null);
         }
     }
 }
예제 #18
0
        public virtual IGeometry IntersectsMuliDim(IGeometry byGeo, IGeometry pGeo)
        {
            IGeometry retGeo       = null;
            IGeometry TopGeometry1 = byGeo;
            IGeometry TopGeometry2 = pGeo;

            if (TopGeometry1 == null || TopGeometry2 == null || TopGeometry1.IsEmpty == true || TopGeometry2.IsEmpty == true)
            {
                retGeo = null;
                MessageBox.Show("空间叠加有一对象为空", "空间分析错误");
                return(retGeo);
            }
            if (!(TopGeometry1 is ITopologicalOperator2) && !(TopGeometry2 is ITopologicalOperator2))
            {
                retGeo = null;
                MessageBox.Show("空间叠加有一对象不是高级对象(Polygon,Polyline,MuliPoint)", "空间分析错误");
                return(retGeo);
            }

            try
            {
                Topoperator2 = (ITopologicalOperator2)TopGeometry2;
                Topoperator2.Simplify();
                Topoperator2 = (ITopologicalOperator2)TopGeometry1;
                Topoperator2.Simplify();

                retGeo = Topoperator2.IntersectMultidimension(TopGeometry2);
            }
            catch (Exception ee)
            {
                retGeo = null;
                System.Diagnostics.Debug.WriteLine(ee.ToString());
                //ZH.Error.Write.Line("ZHFeature.IntersectsMuliDim():<Topoperator2.IntersectMultidimension>出错:<" + this.Tag.ToString() + ">", ee.Message);
            }
            return(retGeo);
        }
예제 #19
0
        void IEditTask.OnFinishSketch()
        {
            if (m_editSketch == null)
            {
                return;
            }

            bool HasCutPolygons = false;

            //Change the cursor to be hourglass shape.
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

            try
            {
                //Get the geometry that performs the cut from the edit sketch.
                IGeometry cutGeometry = m_editSketch.Geometry;

                //The sketch geometry is simplified to deal with a multi-part sketch as well
                //as the case where the sketch loops back over itself.
                ITopologicalOperator2 topoOperator = cutGeometry as ITopologicalOperator2;
                topoOperator.IsKnownSimple_2 = false;
                topoOperator.Simplify();

                //Get ready to invalidate the features.
                IInvalidArea refreshArea = new InvalidAreaClass();
                refreshArea.Add(cutGeometry.Envelope);

                //Create the spatial filter to search for features in the target feature class.
                //The spatial relationship we care about is whether the interior of the line
                //intesects the interior of the polygon.
                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry   = m_editSketch.Geometry;
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                //Find the polygon features that cross the sketch.
                IFeatureClass  featureClass  = m_editLayer.CurrentLayer.FeatureClass;
                IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);

                //Only do work if there are features that intersect the edit sketch.
                IFeature origFeature = featureCursor.NextFeature();
                if (origFeature != null)
                {
                    //Check the first feature to see if it is ZAware and if it needs to make the
                    //cut geometry ZAware.
                    IZAware zAware = origFeature.Shape as IZAware;
                    if (zAware.ZAware)
                    {
                        zAware        = cutGeometry as IZAware;
                        zAware.ZAware = true;
                    }

                    //The result selection set will be the new features created. This means
                    //we need to add the currently selected features to the refresh area so
                    //they are correctly invalidated.
                    if (m_editor.SelectionCount > 0)
                    {
                        IEnumFeature selectedFeatures = m_editor.EditSelection;
                        selectedFeatures.Reset();
                        IFeature selectedFeature = selectedFeatures.Next();
                        while (selectedFeature != null)
                        {
                            refreshArea.Add(selectedFeature);
                            selectedFeature = selectedFeatures.Next();
                        }
                    }

                    //Initialize the selection set for the new features.
                    IFeatureSelection featureSelect = m_editLayer.CurrentLayer as IFeatureSelection;
                    featureSelect.Clear();
                    //Cache the new features created.
                    ISelectionSet selectionSet = featureSelect.SelectionSet;

                    //Start an edit operation so we can have undo/redo.
                    m_editor.StartOperation();

                    //Cycle through the features, cutting with the sketch.
                    while (origFeature != null)
                    {
                        try
                        {
                            //Add the feature to the invalidate object.
                            refreshArea.Add(origFeature);

                            //Split the feature. Use the IFeatureEdit::Split method which ensures
                            //the attributes are correctly dealt with.
                            IFeatureEdit featureEdit = origFeature as IFeatureEdit;
                            //Set to hold the new features that are created by the Split.
                            ISet newFeaturesSet = featureEdit.Split(cutGeometry);

                            //New features have been created, loop through the set and flash
                            //each feature and get it's OID for the final selection set.
                            if (newFeaturesSet != null)
                            {
                                newFeaturesSet.Reset();

                                //A list to hold the selected features' OIDs.
                                List <int> iOIDList = new List <int>();

                                for (int featureCount = 0; featureCount < newFeaturesSet.Count; featureCount++)
                                {
                                    HasCutPolygons = true;
                                    //Flash the new features.
                                    IFeature newFeature = newFeaturesSet.Next() as IFeature;
                                    FlashGeometry(newFeature.Shape, m_editor.Display);

                                    //Add the feature to the new selection set
                                    iOIDList.Add(newFeature.OID);
                                }
                                int[] iOIDArray = iOIDList.ToArray();

                                selectionSet.AddList(newFeaturesSet.Count, ref iOIDArray[0]);
                            }
                        }
                        catch (COMException)
                        {
                        }
                        finally
                        {
                            //Continue to work on the next feature if it fails to split the current one.
                            origFeature = featureCursor.NextFeature();
                        }
                    }
                    //If any polygons were cut, invalidate the display and stop the edit operation.
                    if (HasCutPolygons)
                    {
                        //Clear the map's selection.
                        m_mxDoc.FocusMap.ClearSelection();

                        //Select the new features.
                        featureSelect.SelectionSet = selectionSet;

                        //Refresh the display.
                        refreshArea.Display = m_editor.Display;
                        refreshArea.Invalidate((short)esriScreenCache.esriAllScreenCaches);

                        //Complete the edit operation.
                        m_editor.StopOperation("Cut Polygons Without Selection");

                        //As we changed the selection set, the map has no idea we did this.
                        //Fire the event to inform others the selection has changed.
                        featureSelect.SelectionChanged();
                    }
                    else
                    {
                        m_editor.AbortOperation();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Unable to perform the cut task.\n" + e.ToString());
                //In the event of an error, abort the operation.
                m_editor.AbortOperation();
            }
            finally
            {
                //Change the cursor shape to default.
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
        }
        public void OnFinishSketch()
        {
            if (m_editSketch == null)
            {
                return;
            }

            bool hasCutPolygons = false;

            //Change the cursor to be hourglass shape.
            System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

            try
            {
                //Get the geometry that performs the cut from the edit sketch.
                IGeometry cutGeometry = m_editSketch.Geometry;

                //The sketch geometry is simplified to deal with a multi-part sketch as well
                //as the case where the sketch loops back over itself.
                ITopologicalOperator2 topoOperator = cutGeometry as ITopologicalOperator2;
                topoOperator.IsKnownSimple_2 = false;
                topoOperator.Simplify();

                //Create the spatial filter to search for features in the target feature class.
                //The spatial relationship we care about is whether the interior of the line
                //intersects the interior of the polygon.
                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry   = m_editSketch.Geometry;
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

                //Find the polygon features that cross the sketch.
                IFeatureClass  featureClass  = m_editLayer.TargetLayer.FeatureClass;
                IFeatureCursor featureCursor = featureClass.Search(spatialFilter, false);

                //Only do work if there are features that intersect the edit sketch.
                IFeature origFeature = featureCursor.NextFeature();
                if (origFeature != null)
                {
                    //Check the first feature to see if it is ZAware and if it needs to make the
                    //cut geometry ZAware.
                    IZAware zAware = origFeature.Shape as IZAware;
                    if (zAware.ZAware)
                    {
                        zAware        = cutGeometry as IZAware;
                        zAware.ZAware = true;
                    }

                    ArrayList comErrors = new ArrayList();

                    //Start an edit operation so we can have undo/redo.
                    m_engineEditor.StartOperation();

                    //Cycle through the features, cutting with the sketch.
                    while (origFeature != null)
                    {
                        try
                        {
                            //Split the feature. Use the IFeatureEdit::Split method which ensures
                            //the attributes are correctly dealt with.
                            IFeatureEdit featureEdit = origFeature as IFeatureEdit;
                            //Set to hold the new features that are created by the Split.
                            ISet newFeaturesSet = featureEdit.Split(cutGeometry);

                            //New features have been created.
                            if (newFeaturesSet != null)
                            {
                                newFeaturesSet.Reset();
                                hasCutPolygons = true;
                            }
                        }
                        catch (COMException comExc)
                        {
                            comErrors.Add(String.Format("OID: {0}, Error: {1} , {2}", origFeature.OID.ToString(), comExc.ErrorCode, comExc.Message));
                        }
                        finally
                        {
                            //Continue to work on the next feature if it fails to split the current one.
                            origFeature = featureCursor.NextFeature();
                        }
                    }
                    //If any polygons were cut, refresh the display and stop the edit operation.
                    if (hasCutPolygons)
                    {
                        //Clear the map's selection.
                        m_engineEditor.Map.ClearSelection();

                        //Refresh the display including modified layer and any previously selected component.
                        IActiveView activeView = m_engineEditor.Map as IActiveView;
                        activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography | esriViewDrawPhase.esriViewGeoSelection, null, activeView.Extent);

                        //Complete the edit operation.
                        m_engineEditor.StopOperation("Cut Polygons Without Selection");
                    }
                    else
                    {
                        m_engineEditor.AbortOperation();
                    }

                    //report any errors that have arisen while splitting features
                    if (comErrors.Count > 0)
                    {
                        StringBuilder stringBuilder = new StringBuilder("The following features could not be split: \n", 200);
                        foreach (string comError in comErrors)
                        {
                            stringBuilder.AppendLine(comError);
                        }

                        MessageBox.Show(stringBuilder.ToString(), "Cut Errors");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Unable to perform the cut task.\n" + e.Message);
                m_engineEditor.AbortOperation();
            }
            finally
            {
                //Change the cursor shape to default.
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
        }
예제 #21
0
파일: Erase2.cs 프로젝트: 605258778/GISData
        public override void OnMouseUp(int Button, int Shift, int X, int Y)
        {
            IPoint point = this.m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);

            try
            {
                IFeatureLayer  targetLayer  = Editor.UniqueInstance.TargetLayer;
                IFeatureClass  featureClass = targetLayer.FeatureClass;
                ISpatialFilter queryFilter  = null;
                queryFilter = new SpatialFilterClass {
                    Geometry      = point,
                    GeometryField = featureClass.ShapeFieldName,
                    SpatialRel    = esriSpatialRelEnum.esriSpatialRelWithin
                };
                IFeature         feature = null;
                IFeatureCursor   cursor  = targetLayer.Search(queryFilter, false);
                IFeature         item    = cursor.NextFeature();
                int              num     = 0;
                IList <IFeature> pList   = new List <IFeature>();
                while (item != null)
                {
                    if ((this.m_Feature1 != null) && (item.OID == this.m_Feature1.OID))
                    {
                        item = cursor.NextFeature();
                    }
                    else
                    {
                        feature = item;
                        num++;
                        pList.Add(item);
                        item = cursor.NextFeature();
                    }
                }
                if (num < 1)
                {
                    MessageBox.Show("当前无要素可进行裁切!", "提示");
                }
                else
                {
                    if (num > 1)
                    {
                        OverlapSublot sublot = new OverlapSublot(this.m_hookHelper.Hook, pList)
                        {
                            Text = "裁切",
                            Tip  = "超过一个要素被选中,请选择需要的小班ID"
                        };
                        if (sublot.ShowDialog() == DialogResult.OK)
                        {
                            int selectedIndex = sublot.SelectedIndex;
                            feature = pList[selectedIndex];
                        }
                        else
                        {
                            MessageBox.Show("超过一个要素被选中,无法进行裁切!", "提示");
                            return;
                        }
                    }
                    IFeatureSelection selection = Editor.UniqueInstance.TargetLayer as IFeatureSelection;
                    if (this.m_Feature1 == null)
                    {
                        this.m_Feature1 = feature;
                        selection.Add(this.m_Feature1);
                        this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                        this._cursor = ToolCursor.Erase22;
                    }
                    else
                    {
                        this.m_Feature2 = feature;
                        selection.Add(this.m_Feature2);
                        this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null);
                        IGeometry             shapeCopy = this.m_Feature1.ShapeCopy;
                        IGeometry             other     = this.m_Feature2.ShapeCopy;
                        ITopologicalOperator2 @operator = shapeCopy as ITopologicalOperator2;
                        @operator.IsKnownSimple_2 = false;
                        @operator.Simplify();
                        IGeometry geometry3 = @operator.Intersect(other, esriGeometryDimension.esriGeometry2Dimension);
                        if (geometry3.IsEmpty)
                        {
                            MessageBox.Show("选中两个要素无相交部分,无法进行裁切!", "提示");
                            this.m_Feature1 = null;
                            this.m_Feature2 = null;
                            this._cursor    = ToolCursor.Erase2;
                        }
                        else
                        {
                            ITopologicalOperator2 operator2 = geometry3 as ITopologicalOperator2;
                            operator2.IsKnownSimple_2 = false;
                            operator2.Simplify();
                            IGeometry geometry4 = (other as ITopologicalOperator2).Difference(geometry3);
                            if (geometry4.IsEmpty)
                            {
                                MessageBox.Show("选中两个要素完全重合,无法进行裁切!", "提示");
                                this.m_Feature1 = null;
                                this.m_Feature2 = null;
                                this._cursor    = ToolCursor.Erase2;
                            }
                            else
                            {
                                Editor.UniqueInstance.CheckOverlap = false;
                                Editor.UniqueInstance.StartEditOperation();
                                this.m_Feature2.Shape = geometry4;
                                this.m_Feature2.Store();
                                Editor.UniqueInstance.StopEditOperation();
                                Editor.UniqueInstance.CheckOverlap = true;
                                this.m_Feature1 = null;
                                this.m_Feature2 = null;
                                this._cursor    = ToolCursor.Erase2;
                                (Editor.UniqueInstance.TargetLayer as IFeatureSelection).Clear();
                                this.m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, null);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Editor.UniqueInstance.AbortEditOperation();
                this.m_Feature1 = null;
                this.m_Feature2 = null;
                this._cursor    = ToolCursor.Erase2;
                this.mErrOpt.ErrorOperate(this.mSubSysName, "ShapeEdit.Erase2", "OnMouseUp", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
            }
        }
예제 #22
0
        //<CSCM>
        //********************************************************************************
        //** 函 数 名: UnionTwoGeometry
        //** 版    权: CopyRight (C)
        //** 创 建 人: 杨旭斌
        //** 功能描述: 合并二个图形成一个图形
        //** 创建日期:
        //** 修 改 人:
        //** 修改日期:
        //** 修改时间: 20070818
        //** 参数列表: pOriGeometry (IGeometry)需要合并的二个图形
        //             pDesOrigeometry (IGeometry)
        //             bHasErr合并过程中是否产生了错误
        //             sErrDes 错误描述
        //** 版    本:1.0
        //*********************************************************************************
        //</CSCM>
        public static IGeometry UnionTwoGeometry(IGeometry pOriGeometry, IGeometry pDesGeometry, ref bool bHasErr, ref string sErrDes)
        {
            //bHasErr = false;
            //sErrDes = "";

            IGeometry             functionReturnValue = default(IGeometry);
            ITopologicalOperator2 pTopoOperator       = default(ITopologicalOperator2);
            IGeometry             pGeometry           = default(IGeometry);

            //如果图形为空,则置为nothing
            bHasErr = false;
            sErrDes = "";
            if (pOriGeometry != null && pDesGeometry != null)
            {
                if (pOriGeometry.SpatialReference == null & pDesGeometry.SpatialReference != null)
                {
                    if (pOriGeometry.SpatialReference.FactoryCode != pDesGeometry.SpatialReference.FactoryCode)
                    {
                        bHasErr = true;
                        sErrDes = "二个图形的投影坐标系不相同,不能进行求交。";
                        return(null);
                    }
                }
            }
            if (pOriGeometry != null)
            {
                if (pOriGeometry.IsEmpty == true)
                {
                    pOriGeometry = null;
                }
            }
            if (pDesGeometry != null)
            {
                if (pDesGeometry.IsEmpty == true)
                {
                    pDesGeometry = null;
                }
            }
            try
            {
                if (pOriGeometry != null && pDesGeometry != null)
                {
                    pTopoOperator = (ITopologicalOperator2)pOriGeometry;
                    pGeometry     = pTopoOperator.Union(pDesGeometry);
                    pTopoOperator = (ITopologicalOperator2)pGeometry;
                    pTopoOperator.IsKnownSimple_2 = false;
                    pTopoOperator.Simplify();
                    functionReturnValue = (IGeometry)pTopoOperator;
                    return(functionReturnValue);
                }
                else if (pOriGeometry != null)
                {
                    return(pOriGeometry);
                }
                else if (pDesGeometry != null)
                {
                    return(pDesGeometry);
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                functionReturnValue = null;
            }
            return(functionReturnValue);
        }
예제 #23
0
        public void InitLinkage(IPoint mousePoint, double buffer)
        {
            this._isVertexEditing = false;
            this._editOrigShape   = null;
            this._editBound       = null;
            this._las.Clear();
            IFeatureClass  featureClass = Editor.UniqueInstance.TargetLayer.FeatureClass;
            ISpatialFilter queryFilter  = new SpatialFilterClass {
                Geometry      = (mousePoint as ITopologicalOperator).Buffer(buffer),
                GeometryField = featureClass.ShapeFieldName,
                SubFields     = featureClass.ShapeFieldName,
                SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects
            };
            IFeatureCursor o        = Editor.UniqueInstance.TargetLayer.Search(queryFilter, false);
            IFeature       pFeature = o.NextFeature();

            if (pFeature == null)
            {
                Marshal.ReleaseComObject(o);
                o = null;
                this.ClearUp();
            }
            else
            {
                IFeature feature = o.NextFeature();
                if (feature == null)
                {
                    Marshal.ReleaseComObject(o);
                    o = null;
                    this.ClearUp();
                }
                else if (o.NextFeature() != null)
                {
                    Marshal.ReleaseComObject(o);
                    o = null;
                    this.ClearUp();
                }
                else
                {
                    pFeature = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(pFeature.OID);
                    feature  = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(feature.OID);
                    IGeometry             pGeometry = null;
                    IGeometry             shapeCopy = pFeature.ShapeCopy;
                    IGeometry             other     = feature.ShapeCopy;
                    ITopologicalOperator2 @operator = shapeCopy as ITopologicalOperator2;
                    @operator.IsKnownSimple_2 = false;
                    @operator.Simplify();
                    ITopologicalOperator2 operator2 = other as ITopologicalOperator2;
                    operator2.IsKnownSimple_2 = false;
                    operator2.Simplify();
                    pGeometry = @operator.Intersect(other, esriGeometryDimension.esriGeometry1Dimension);
                    if (pGeometry.IsEmpty)
                    {
                        this.ClearUp();
                    }
                    else
                    {
                        if ((pGeometry as IGeometryCollection).GeometryCount > 1)
                        {
                            IHitTest test            = pGeometry as IHitTest;
                            IPoint   hitPoint        = null;
                            double   hitDistance     = 0.0;
                            int      hitPartIndex    = -1;
                            int      hitSegmentIndex = -1;
                            bool     bRightSide      = false;
                            if (!test.HitTest(mousePoint, buffer, esriGeometryHitPartType.esriGeometryPartBoundary, hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref bRightSide))
                            {
                                return;
                            }
                            pGeometry = (pGeometry as IGeometryCollection).get_Geometry(hitPartIndex);
                        }
                        pGeometry = GISFunFactory.UnitFun.ConvertPoject(pGeometry, this._viewMap.FocusMap.SpatialReference);
                        IPolyline polyline = null;
                        if (pGeometry.GeometryType != esriGeometryType.esriGeometryPolyline)
                        {
                            IPath path = pGeometry as IPath;
                            if ((path != null) && path.IsClosed)
                            {
                                this.ClearUp();
                                return;
                            }
                            IPointCollection newPoints = pGeometry as IPointCollection;
                            polyline = new PolylineClass {
                                SpatialReference = pGeometry.SpatialReference
                            };
                            (polyline as IPointCollection).AddPointCollection(newPoints);
                        }
                        IGeometry geometry4 = @operator.Union(other);
                        this._editBound = GISFunFactory.UnitFun.ConvertPoject(geometry4, this._viewMap.FocusMap.SpatialReference);
                        this._las.Add(new LinkArgs(pFeature));
                        this._las.Add(new LinkArgs(feature));
                        this.InitOtherLayer(pGeometry);
                        if (polyline != null)
                        {
                            this._editOrigShape = (polyline as IClone).Clone() as IGeometry;
                            Editor.UniqueInstance.LinageShape       = polyline;
                            Editor.UniqueInstance.ReservedLinkShape = polyline;
                        }
                        else
                        {
                            this._editOrigShape = (pGeometry as IClone).Clone() as IGeometry;
                            Editor.UniqueInstance.LinageShape       = pGeometry;
                            Editor.UniqueInstance.ReservedLinkShape = pGeometry;
                        }
                        this._isVertexEditing = true;
                    }
                }
            }
        }
예제 #24
0
        /// <summary>
        /// 绘制曲线部分
        /// </summary>
        /// <params name="lyr">推断断层</params>
        /// <params name="newplines">延长点构造的线</params>
        /// <params name="originlines">原始点构造的线</params>
        private void AddCurveToMap(IFeatureLayer lyr, List <IPolyline> newplines, List <IPolyline> originlines)
        {
            IFeatureClass  Featureclass = lyr.FeatureClass;
            IWorkspaceEdit workspace    = (IWorkspaceEdit)(Featureclass as IDataset).Workspace;

            workspace.StartEditing(true);
            workspace.StartEditOperation();
            object missing = Type.Missing;
            //揭露断层上的曲线对象
            IGeometry geom = new PolylineClass();

            geom.SpatialReference = Global.spatialref;
            IGeometryCollection outgeomcols = geom as IGeometryCollection;
            IFeature            fea         = Featureclass.CreateFeature();
            ISegmentCollection  newpath     = new PathClass();
            int kindpos = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_TYPE);
            int bidpos  = Featureclass.Fields.FindField(GIS.GIS_Const.FIELD_BID);

            for (int i = 0; i < newplines.Count; i++)
            {
                ILine lin = new LineClass();
                lin.SpatialReference = Global.spatialref;
                //直线段
                IPath path = new PathClass();
                if (i == 0)
                {
                    lin.FromPoint = newplines[i].FromPoint;
                    lin.ToPoint   = originlines[i].ToPoint;
                }
                else if (i == originlines.Count - 1)
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint   = newplines[i].ToPoint;
                }
                else
                {
                    lin.FromPoint = originlines[i].FromPoint;
                    lin.ToPoint   = originlines[i].ToPoint;
                }
                newpath.AddSegment(lin as ISegment, ref missing, ref missing);
                //曲线段
                if (i < newplines.Count - 1)
                {
                    IBezierCurveGEN bezier      = new BezierCurveClass();
                    IPoint[]        pntcontrols = new IPoint[4];
                    pntcontrols[0] = originlines[i].ToPoint;
                    pntcontrols[1] = newplines[i].ToPoint;
                    pntcontrols[2] = newplines[i + 1].FromPoint;
                    pntcontrols[3] = originlines[i + 1].FromPoint;
                    bezier.PutCoords(ref pntcontrols);

                    newpath.AddSegment(bezier as ISegment, ref missing, ref missing);
                }
            }
            outgeomcols.AddGeometry(newpath as IGeometry, ref missing, ref missing);
            int          index       = fea.Fields.FindField(GIS_Const.FIELD_SHAPE);
            IGeometryDef geometryDef = fea.Fields.get_Field(index).GeometryDef as IGeometryDef;

            if (geometryDef.HasZ)
            {
                IZAware pZAware = (IZAware)outgeomcols;
                pZAware.ZAware = true;
            }
            fea.Shape = outgeomcols as IPolyline;
            fea.set_Value(kindpos, 1);
            fea.set_Value(bidpos, BID);
            fea.Store();
            //外围曲线绘制
            ITopologicalOperator2 top = outgeomcols as ITopologicalOperator2;

            if (!top.IsSimple)
            {
                top.Simplify();
            }
            IConstructCurve curve = new PolylineClass();

            curve.ConstructOffset(outgeomcols as IPolyline, -3, ref missing, ref missing);
            IPolyline plinnew = curve as IPolyline;

            plinnew.SpatialReference = Global.spatialref;
            plinnew.FromPoint        = newplines[0].FromPoint;
            plinnew.ToPoint          = newplines[newplines.Count - 1].ToPoint;

            IFeature outcurve = Featureclass.CreateFeature();

            outcurve.set_Value(kindpos, 2);
            outcurve.set_Value(bidpos, BID);
            outcurve.Shape = plinnew;
            outcurve.Store();
            //结束编辑
            workspace.StopEditOperation();
            workspace.StopEditing(true);
            //定位跳转
            Global.commonclss.JumpToGeometry(plinnew);
        }
        private void UnionFeatures(IEnumFeature selectedFeatures)
        {
            IFeature  feature  = null;
            IGeometry geometry = null;
            object    missing  = Type.Missing;

            selectedFeatures.Reset();
            feature = selectedFeatures.Next();
            if (feature == null)
            {
                return;
            }
            IFeatureClass       featureClass = feature.Class as IFeatureClass;
            IGeometryCollection geometries   = new GeometryBagClass();

            while (feature != null)
            {
                geometry = feature.ShapeCopy;
                geometries.AddGeometry(geometry, ref missing, ref missing);
                feature = selectedFeatures.Next();
            }
            ITopologicalOperator unionedGeometry = null;

            switch (featureClass.ShapeType)
            {
            case esriGeometryType.esriGeometryMultipoint:
                unionedGeometry = new MultipointClass(); break;

            case esriGeometryType.esriGeometryPolyline:
                unionedGeometry = new PolylineClass(); break;

            case esriGeometryType.esriGeometryPolygon:
                unionedGeometry = new PolygonClass(); break;

            default: break;
            }

            unionedGeometry.ConstructUnion(geometries as IEnumGeometry);
            ITopologicalOperator2 topo = unionedGeometry as ITopologicalOperator2;

            topo.IsKnownSimple_2 = false; topo.Simplify();
            IFeatureClass  targetFeatureClass = currentLayer.FeatureClass;
            IDataset       dataset            = featureClass as IDataset;
            IWorkspaceEdit workspaceEdit      = dataset.Workspace as IWorkspaceEdit;

            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }
            try
            {
                workspaceEdit.StartEditOperation();
                IFeature unionedFeature = targetFeatureClass.CreateFeature();
                unionedFeature.Shape = unionedGeometry as IGeometry;
                unionedFeature.Store();
                workspaceEdit.StopEditOperation();
            }
            catch (Exception ex)
            {
                workspaceEdit.AbortEditOperation();
                MessageBox.Show("要素合并失败!!" + ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #26
0
        /// <summary>
        /// 利用缓冲区图层,遍历每一个要素,找出与其相交且要素代码相同的所有要素,进行合并
        /// </summary>
        private void UnionBuffer(string unionType, string unionValue)
        {
            //IFeatureWorkspace pFWks = GISUtil.GISUtil.CreateFeatureWorkspace(bufferSavefile);
            //IFeatureClass pFc = pFWks.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(bufferSavefile));
            if (string.IsNullOrWhiteSpace(unionType) || string.IsNullOrWhiteSpace(unionValue))
            {
                return;
            }

            IQueryFilter filter = new QueryFilterClass();

            if (currentFieldType == esriFieldType.esriFieldTypeString)
            {
                filter.WhereClause = unionType + " = " + "'" + unionValue + "'";
            }
            else if (currentFieldType == esriFieldType.esriFieldTypeDate)
            {
                //filter.WhereClause = unionType + " = " + "'" + unionValue + "'";
            }
            else
            {
                filter.WhereClause = unionType + " = " + unionValue;
            }
            ISpatialFilter spatialFilter = new SpatialFilterClass();
            IFeatureCursor pFCursor      = pFc.Search(filter, true);
            IFeature       pFeature      = pFCursor.NextFeature();

            while (pFeature != null)
            {
                ArrayList           fIDList        = new ArrayList();
                IGeometryCollection pGeoCollection = GetIntersectSameTypeFeatures(pFc, pFeature, spatialFilter, filter, unionType, unionValue, ref fIDList);
                if (pGeoCollection.GeometryCount == 1)
                {
                    pFeature = pFCursor.NextFeature();
                    continue;
                }
                try
                {
                    ITopologicalOperator unionGeometry = new PolygonClass();
                    unionGeometry.ConstructUnion((IEnumGeometry)pGeoCollection);
                    ITopologicalOperator2 pTopo2 = (ITopologicalOperator2)unionGeometry; //pFeature.Shape;
                    pTopo2.IsKnownSimple_2 = false;
                    pTopo2.Simplify();
                    pFeature.Shape = unionGeometry as IGeometry;
                    pFeature.Store();
                    //删除参与Union的非自身要素
                    int pFID = (int)pFeature.get_Value(pFeature.Fields.FindField("FID"));
                    for (int i = 0; i < fIDList.Count; i++)
                    {
                        if ((int)fIDList[i] == pFID)
                        {
                            continue;
                        }
                        IFeature delFeature = pFc.GetFeature((int)fIDList[i]);
                        if (delFeature != null)
                        {
                            delFeature.Delete();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.LogHelper.WriteLog(typeof(BufferForm), ex.Message + ex.StackTrace);
                }
                pFeature = pFCursor.NextFeature();
            }
            Marshal.ReleaseComObject(pFCursor);
        }
예제 #27
0
파일: Split.cs 프로젝트: 605258778/GISData
 public void OnDblClick()
 {
     if (this._isLineStarted)
     {
         this._snapPoint = null;
         try
         {
             this._isLineStarted = false;
             this._linePoints.RemoveAll();
             IPolyline         other       = this._feedback.Stop();
             IFeatureSelection targetLayer = Editor.UniqueInstance.TargetLayer as IFeatureSelection;
             IEnumIDs          iDs         = targetLayer.SelectionSet.IDs;
             iDs.Reset();
             IFeature srcFeature = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(iDs.Next());
             if (other.SpatialReference != srcFeature.Shape.SpatialReference)
             {
                 other.Project(srcFeature.Shape.SpatialReference);
                 other.SpatialReference = srcFeature.Shape.SpatialReference;
             }
             ITopologicalOperator2 shape = srcFeature.Shape as ITopologicalOperator2;
             if (shape != null)
             {
                 shape.IsKnownSimple_2 = false;
                 shape.Simplify();
                 ITopologicalOperator2 operator2 = other as ITopologicalOperator2;
                 operator2.IsKnownSimple_2 = false;
                 operator2.Simplify();
                 IGeometry geometry = null;
                 if (srcFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                 {
                     geometry = shape.Intersect(other, esriGeometryDimension.esriGeometry0Dimension);
                 }
                 else
                 {
                     geometry = shape.Intersect(other, esriGeometryDimension.esriGeometry1Dimension);
                 }
                 if (!geometry.IsEmpty)
                 {
                     IGeometry geometry2;
                     IGeometry geometry3;
                     shape.Cut(other, out geometry3, out geometry2);
                     if ((geometry3 != null) && (geometry2 != null))
                     {
                         (geometry3 as ITopologicalOperator).Simplify();
                         (geometry2 as ITopologicalOperator).Simplify();
                         IFeatureClass featureClass = Editor.UniqueInstance.TargetLayer.FeatureClass;
                         IFeature      feature      = featureClass.CreateFeature();
                         IFeature      feature3     = featureClass.CreateFeature();
                         feature.Shape  = geometry3;
                         feature3.Shape = geometry2;
                         IAttributeSplit attributeSplitHandleClass = AttributeManager.AttributeSplitHandleClass;
                         if (attributeSplitHandleClass != null)
                         {
                             try
                             {
                                 Editor.UniqueInstance.StartEditOperation();
                                 Editor.UniqueInstance.AddAttribute = false;
                                 List <IFeature> pFeatureList = null;
                                 pFeatureList = new List <IFeature> {
                                     feature,
                                     feature3
                                 };
                                 attributeSplitHandleClass.AttributeSplit(srcFeature, ref pFeatureList);
                                 feature  = pFeatureList[0];
                                 feature3 = pFeatureList[1];
                                 feature.Store();
                                 feature3.Store();
                                 srcFeature.Delete();
                                 Editor.UniqueInstance.StopEditOperation("split");
                                 targetLayer.Clear();
                                 targetLayer.Add(feature);
                                 this._hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, null);
                             }
                             catch (Exception exception)
                             {
                                 Editor.UniqueInstance.AbortEditOperation();
                                 this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.Split", "OnDblClick", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
                             }
                         }
                     }
                 }
             }
         }
         catch (Exception exception2)
         {
             this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.Split", "OnDblClick", exception2.GetHashCode().ToString(), exception2.Source, exception2.Message, "", "", "");
         }
     }
 }
예제 #28
0
        public override void OnClick()
        {
            try
            {
                ITopologicalOperator2 @operator;
                List <IFeature>       list;
                IFeature          feature2;
                IFeatureSelection targetLayer = Editor.UniqueInstance.TargetLayer as IFeatureSelection;
                IEnumIDs          iDs         = targetLayer.SelectionSet.IDs;
                iDs.Reset();
                int iD = iDs.Next();
                if (iD != -1)
                {
                    IFeature feature = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(iD);
                    @operator = feature.Shape as ITopologicalOperator2;
                    @operator.IsKnownSimple_2 = false;
                    @operator.Simplify();
                    iD   = iDs.Next();
                    list = null;
                    if (iD != -1)
                    {
                        list = new List <IFeature> {
                            feature
                        };
                        goto Label_00F4;
                    }
                }
                return;

Label_0088:
                feature2 = Editor.UniqueInstance.TargetLayer.FeatureClass.GetFeature(iD);
                ITopologicalOperator2 shape = feature2.Shape as ITopologicalOperator2;
                shape.IsKnownSimple_2 = false;
                shape.Simplify();
                @operator = @operator.Union(feature2.Shape) as ITopologicalOperator2;
                @operator.IsKnownSimple_2 = false;
                @operator.Simplify();
                iD = iDs.Next();
                list.Add(feature2);
Label_00F4:
                if (iD != -1)
                {
                    goto Label_0088;
                }
                Editor.UniqueInstance.StartEditOperation();
                Editor.UniqueInstance.AddAttribute = false;
                IFeature resultFeature = Editor.UniqueInstance.TargetLayer.FeatureClass.CreateFeature();
                resultFeature.Shape = @operator as IGeometry;
                if (AttributeManager.AttributeCombineHandleClass.AttributeCombine(list, ref resultFeature) == DialogResult.OK)
                {
                    resultFeature.Store();
                    foreach (IFeature feature4 in list)
                    {
                        feature4.Delete();
                    }
                    targetLayer.Clear();
                    targetLayer.Add(resultFeature);
                }
                Editor.UniqueInstance.StopEditOperation("combine");
                this._hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection | esriViewDrawPhase.esriViewGeography, null, null);
            }
            catch (Exception exception)
            {
                Editor.UniqueInstance.AbortEditOperation();
                this._mErrOpt.ErrorOperate(this._mSubSysName, "ShapeEdit.Combine", "OnClick", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
            }
        }
예제 #29
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);
        }
예제 #30
0
        //功能描述:根据坐标串生成一个polygon
        //参数列表: sCoordinate (String)
        //          pSpatialReference (ISpatialReference)
        public static IPolygon GetPolygonByCoordinate(string sCoordinate, ISpatialReference pSpatialReference)
        {
            string           sRealCoordinate = null;
            int              i        = 0;
            string           sValue   = null;
            IPolygon         pPolygon = default(IPolygon);
            IPointCollection pPntCol  = default(IPointCollection);
            IPoint           pPnt     = default(IPoint);
            string           x        = null;
            string           y        = null;

            string[] sArray      = null;
            string[] sCoordArray = null;
            ITopologicalOperator2 pTopoOperator = default(ITopologicalOperator2);

            if (pSpatialReference == null)
            {
                return(null);
            }
            pPolygon = null;
            try
            {
                if (!string.IsNullOrEmpty(Strings.Trim(sCoordinate)))
                {
                    if (Strings.InStr(sCoordinate, "(", CompareMethod.Text) > 0 & Strings.InStr(sCoordinate, ")", CompareMethod.Text) > 0 & Strings.InStr(sCoordinate, ",", CompareMethod.Text) > 0)
                    {
                        //去掉坐标窜中的空格
                        sRealCoordinate = "";
                        for (i = 1; i <= Strings.Len(sCoordinate); i++)
                        {
                            sValue = Strings.Mid(sCoordinate, i, 1);
                            if (!string.IsNullOrEmpty(Strings.Trim(sValue)))
                            {
                                if (string.IsNullOrEmpty(Strings.Trim(sRealCoordinate)))
                                {
                                    sRealCoordinate = sValue;
                                }
                                else
                                {
                                    sRealCoordinate = sRealCoordinate + sValue;
                                }
                            }
                        }
                        pPntCol = new Polygon();
                        //说明有多个坐标对
                        if (Strings.InStr(sRealCoordinate, "),", CompareMethod.Text) > 0)
                        {
                            //sArray = Strings.Split(sRealCoordinate, "),");
                            sArray = sRealCoordinate.Split(new char[] { ')' });
                            if (Information.UBound(sArray, 1) > 1)
                            {
                                for (i = 0; i <= Information.UBound(sArray, 1); i++)
                                {
                                    sValue = sArray[i];
                                    //分解后的坐标解析式:(x,y,   最后一项(x,y)
                                    if (Strings.InStr(sValue, "(", CompareMethod.Text) > 0 && Strings.InStr(sValue, ",", CompareMethod.Text) > 0)
                                    {
                                        //sCoordArray = Strings.Split(sValue, ",");
                                        sCoordArray = sValue.Split(new char[] { ',' });
                                        if (Information.UBound(sCoordArray, 1) == 1)
                                        {
                                            pPnt = new Point();
                                            pPnt.Project(pSpatialReference);
                                            x = sCoordArray[0];
                                            x = Convert.ToString(Convert.ToDouble(Strings.Right(x, Strings.Len(x) - 1)));
                                            y = sCoordArray[1];
                                            if (i == Information.UBound(sArray, 1))
                                            {
                                                y = Strings.Left(y, Strings.Len(y) - 1);
                                            }
                                            pPnt.PutCoords(Convert.ToDouble(x), Convert.ToDouble(y));
                                            object missing = Type.Missing;
                                            pPntCol.AddPoint(pPnt, ref missing, ref missing);
                                            //只要有一个点的坐标形式出错,就退出
                                        }
                                        else
                                        {
                                            return(null);
                                        }
                                    }
                                    else
                                    {
                                        return(null);
                                    }
                                }
                                pTopoOperator = (ITopologicalOperator2)pPntCol;
                                pTopoOperator.Simplify();
                                pPolygon = (IPolygon)pTopoOperator;
                                pPolygon.Project(pSpatialReference);
                                return(pPolygon);
                            }
                        }
                    }
                }
                return(pPolygon);
            }
            catch
            {
                return(null);
            }
        }