예제 #1
0
        /// <summary>
        /// 将多个图形合并(Union)成一个图形(使用GeometryBag提高合并效率)
        /// </summary>
        /// <param name="geometryBag"></param>
        /// <param name="geometryType">几何类型</param>
        /// <returns></returns>
        private static IGeometry UnionGeometryEx(this IGeometry geometryBag, esriGeometryType geometryType)
        {
            ITopologicalOperator unionedGeometry;

            switch (geometryType)
            {
            case esriGeometryType.esriGeometryPoint:
                unionedGeometry = new PointClass();
                break;

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

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

            default:
                throw new NotImplementedException($"几何类型({nameof(geometryType)})应是点(point)、线(polyline)、多边形(polygon)之一,未实现{geometryType}类型的图形合并(Union)!");
            }

            unionedGeometry.ConstructUnion(geometryBag as IEnumGeometry);
            return((IGeometry)unionedGeometry);
        }
예제 #2
0
        /// <summary>
        /// 把geometry合并起来,组成一个新的geometry,在缓冲buffer个单位
        /// </summary>
        /// <param name="lstGeo">Geo列表</param>
        /// <param name="buffer">缓冲单位</param>
        /// <returns></returns>
        public static IGeometry GetUnionGeometry(IList <IGeometry> lstGeo, double buffer)
        {
            if (lstGeo.Count == 0)
            {
                return(null);
            }
            IGeometryBag pGeometryBag = new GeometryBagClass();

            pGeometryBag.SpatialReference = lstGeo[0].SpatialReference;
            IGeometryCollection pGeometryCollection = pGeometryBag as IGeometryCollection;
            object obj = Type.Missing;

            foreach (IGeometry geo in lstGeo)
            {
                pGeometryCollection.AddGeometry(geo, ref obj, ref obj);
            }

            ITopologicalOperator UnionPolygon = new PolygonClass();

            UnionPolygon.ConstructUnion(pGeometryCollection as ESRI.ArcGIS.Geometry.IEnumGeometry);
            IGeometry            geoResult    = UnionPolygon as IGeometry;
            ITopologicalOperator operatorTopo = geoResult as ITopologicalOperator;

            return(operatorTopo.Buffer(buffer));
        }
예제 #3
0
 public static IGeometry GetSelectFeatureGeom(IMap pMap)
 {
     try
     {
         object              obj          = System.Reflection.Missing.Value;
         IGeometryBag        pGeometryBag = new GeometryBagClass();
         IGeometryCollection pGeomtryCol  = (IGeometryCollection)pGeometryBag;
         ISelection          pSelection   = pMap.FeatureSelection;
         IEnumFeature        pEnumFea     = pSelection as IEnumFeature;
         IFeature            pFea         = pEnumFea.Next();
         while (pFea != null)
         {
             if (pFea.Shape != null && pFea.Shape.GeometryType == esriGeometryType.esriGeometryPolygon)
             {
                 pGeomtryCol.AddGeometry(pFea.Shape, ref obj, ref obj);
             }
             pFea = pEnumFea.Next();
         }
         ITopologicalOperator pTopo = new PolygonClass();
         pTopo.ConstructUnion(pGeomtryCol as IEnumGeometry);
         IGeometry pGeometry = pTopo as IGeometry;
         return(pGeometry);
     }
     catch { return(null); }
 }
예제 #4
0
        /// <summary>
        /// 获得指定图层的合并范围 为本次加的一个函数
        /// </summary>
        /// <param name="strLyrName"></param>
        /// <param name="strWhere"></param>
        /// <param name="eFeatureType"></param>
        /// <param name="eGeometryType"></param>
        /// <returns></returns>
        public IGeometry GetLyrUnionPlygon(IList <IFeature> vFeaList)
        {
            if (vFeaList.Count < 1)
            {
                return(null);
            }
            //构造
            IGeometryBag        pGeometryBag = new GeometryBagClass();
            IGeometryCollection pGeometryCol = pGeometryBag as IGeometryCollection;

            object obj = System.Type.Missing;

            //获得所有图形
            for (int i = 0; i < vFeaList.Count; i++)
            {
                if (vFeaList[i].Shape != null && !vFeaList[i].Shape.IsEmpty)
                {
                    pGeometryCol.AddGeometry(vFeaList[i].ShapeCopy, ref obj, ref obj);
                }
            }

            //构造合并
            ITopologicalOperator pTopo = new PolygonClass();

            pTopo.ConstructUnion(pGeometryCol as IEnumGeometry);

            IGeometry pGeometry = pTopo as IGeometry;

            return(pGeometry);
        }
예제 #5
0
        /// <summary>
        /// 获得当前视图上的选择要素
        /// ZQ 2011 1203 将点要素自动去除 只合并线和面要素
        /// </summary>
        /// <param name="pMap"></param>
        /// <returns></returns>
        private IGeometry ConstructUnion(IMap pMap)
        {
            IGeometry pGeometry = null;

            try
            {
                IGeometryBag        pGeometryBag = new GeometryBagClass();
                IGeometryCollection pGeometryCol = pGeometryBag as IGeometryCollection;
                object       obj          = System.Type.Missing;
                ISelection   pSelection   = pMap.FeatureSelection;
                IEnumFeature pEnumFeature = pSelection as IEnumFeature;
                IFeature     pFeature     = pEnumFeature.Next();
                while (pFeature != null)
                {
                    ///排除点要素
                    if (pFeature.ShapeCopy.GeometryType != esriGeometryType.esriGeometryPoint && pFeature.ShapeCopy.GeometryType != esriGeometryType.esriGeometryMultipoint)
                    {
                        if (!pFeature.ShapeCopy.IsEmpty)
                        {
                            pGeometryCol.AddGeometry(pFeature.ShapeCopy, ref obj, ref obj);
                        }
                    }
                    pFeature = pEnumFeature.Next();
                }
                //构造合并
                ITopologicalOperator pTopo = new PolygonClass();
                pTopo.ConstructUnion(pGeometryCol as IEnumGeometry);
                pGeometry = pTopo as IGeometry;
                return(pGeometry);
            }
            catch
            { return(pGeometry = null); }
        }
        //Function: Judging whether regional breaks have occurred
        public bool isRegionalBreak(IFeatureClass featureClass, int elementId)
        {
            IGeometry    geometryBag = new GeometryBagClass();
            IQueryFilter queryFilter = new QueryFilterClass();

            queryFilter.WhereClause = "id = " + elementId;
            IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);

            IGeometryCollection geometryCollection = geometryBag as IGeometryCollection;
            IFeature            currentFeature     = featureCursor.NextFeature();

            while (currentFeature != null)
            {
                object missing = Type.Missing;
                geometryCollection.AddGeometry(currentFeature.Shape, ref missing, ref missing);
                currentFeature = featureCursor.NextFeature();
            }

            ITopologicalOperator unionedPolygon = new PolygonClass();

            unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);

            IGeometryCollection geoCol = unionedPolygon as IGeometryCollection;

            if (geoCol.GeometryCount > 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
        /// <summary>
        /// union几个面要素
        /// </summary>
        /// <param name="lstGeometry">需要操作的面要素集合</param>
        /// <returns>返回union后的图形</returns>
        public static IGeometry GetUnion(List <IGeometry> lstGeometry)
        {
            IGeometryBag        pGeoBag = new GeometryBagClass();
            IGeometryCollection pGeoCol = pGeoBag as IGeometryCollection;

            if (lstGeometry.Count < 1)
            {
                return(null);
            }
            if (lstGeometry[0].SpatialReference != null)
            {
                pGeoBag.SpatialReference = lstGeometry[0].SpatialReference;
            }

            object obj = System.Type.Missing;

            for (int i = 0; i < lstGeometry.Count; i++)
            {
                IGeometry pTempGeo = lstGeometry[i];
                pGeoCol.AddGeometry(pTempGeo, ref obj, ref obj);
            }
            ISpatialIndex pSI = pGeoBag as ISpatialIndex;

            pSI.AllowIndexing = true;
            pSI.Invalidate();

            ITopologicalOperator pTopo = new PolygonClass();

            pTopo.ConstructUnion(pGeoBag as IEnumGeometry);
            IGeometry pGeo = pTopo as IGeometry;

            return(pGeo);
        }
예제 #8
0
        private List <IElement> CreateElementAois(List <IPolygon> polygons, out IEnvelope encompassingEnvelope)
        {
            var rgbColor = new RgbColorClass {
                Red = 0, Green = 0, Blue = 255, Transparency = 200
            };

            var geometryBag = new GeometryBagClass();

            geometryBag.SpatialReference = ArcMap.Document.FocusMap.SpatialReference;
            IGeometryCollection geometryCollection = geometryBag;
            var elements = new List <IElement>();

            foreach (var polygon in polygons)
            {
                geometryCollection.AddGeometry(polygon);
                IElement element = null;

                // Polygon elements
                ILineSymbol lineSymbol = new SimpleLineSymbolClass();
                lineSymbol.Color = rgbColor;
                lineSymbol.Width = 2.0;

                ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
                simpleFillSymbol.Color   = rgbColor;
                simpleFillSymbol.Style   = esriSimpleFillStyle.esriSFSNull;
                simpleFillSymbol.Outline = lineSymbol;

                IFillShapeElement fillShapeElement = new PolygonElementClass();
                fillShapeElement.Symbol = simpleFillSymbol;
                element = (IElement)fillShapeElement; // Explicit Cast

                element.Geometry = polygon;
                elements.Add(element);
            }

            // Create the polygon that will be the union of the features returned from the search cursor.
            // The spatial reference of this feature does not need to be set ahead of time. The
            // ConstructUnion method defines the constructed polygon's spatial reference to be the same as
            // the input geometry bag.
            ITopologicalOperator unionedPolygon = new PolygonClass();

            unionedPolygon.ConstructUnion(geometryBag);
            var masterPoly = (IPolygon)unionedPolygon;

            encompassingEnvelope = masterPoly.Envelope;
            return(elements);
        }
예제 #9
0
        private static IPolygon UnionPolygons([NotNull] IEnumerable <IGeometry> polygons,
                                              [CanBeNull] ISpatialReference spatialReference)
        {
            const bool   allowProjectingInput = true;
            IGeometryBag bag = GeometryFactory.CreateBag(polygons,
                                                         CloneGeometry.IfChangeNeeded,
                                                         spatialReference,
                                                         allowProjectingInput);

            var result = new PolygonClass
            {
                SpatialReference = spatialReference
            };

            result.ConstructUnion((IEnumGeometry)bag);

            return(result);
        }
예제 #10
0
        private static IGeometry UnionGeometry(List <IGeometry> geoLst, ISpatialReference SpatialReference)
        {
            IGeometry geo = null;

            using (ComReleaser comReleaser = new ComReleaser())
            {
                ESRI.ArcGIS.Geometry.IGeometry geometryBag = new ESRI.ArcGIS.Geometry.GeometryBagClass();
                geometryBag.SpatialReference = SpatialReference;
                ESRI.ArcGIS.Geometry.IGeometryCollection geometryCollection = geometryBag as ESRI.ArcGIS.Geometry.IGeometryCollection;
                object missing = Type.Missing;
                foreach (IGeometry item in geoLst)
                {
                    geometryCollection.AddGeometry(item, ref missing, ref missing);
                }
                ITopologicalOperator unionedPolygon = new PolygonClass();
                unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);
                geo = unionedPolygon as IGeometry;

                comReleaser.ManageLifetime(geometryBag);
                comReleaser.ManageLifetime(geometryCollection);
            }
            return(geo);
        }
예제 #11
0
 public static IGeometry WMerge(this IGeometry Sgeometry,IGeometry geometry)
 {
     IGeometryCollection geometryCollection = new GeometryBagClass();
     geometryCollection.AddGeometry(Sgeometry);
     geometryCollection.AddGeometry(geometry);
     ITopologicalOperator unionedpolygon = new PolygonClass();
     unionedpolygon.ConstructUnion(geometryCollection as IEnumGeometry);
     return unionedpolygon as IGeometry;
 }
예제 #12
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);
        }
예제 #13
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IEnvelope extent;

            if (this.rdoCurrentMapExtend.Checked)
            {
                extent            = (this.Map as IActiveView).Extent;
                this.ClipGeometry = extent;
            }
            else if (this.rdoCustomExtend.Checked)
            {
                double num;
                double num2;
                double num3;
                double num4;
                if (!double.TryParse(this.txtBottom.Text, out num))
                {
                    MessageBox.Show("底部值输入错误!");
                    return;
                }
                if (!double.TryParse(this.txtLeft.Text, out num2))
                {
                    MessageBox.Show("左边值输入错误!");
                    return;
                }
                if (!double.TryParse(this.txtTop.Text, out num3))
                {
                    MessageBox.Show("顶部值输入错误!");
                    return;
                }
                if (!double.TryParse(this.txtRight.Text, out num4))
                {
                    MessageBox.Show("右边值输入错误!");
                    return;
                }
                extent = new EnvelopeClass
                {
                    XMin = num2,
                    XMax = num4,
                    YMax = num3,
                    YMin = num
                };
                this.ClipGeometry = extent;
            }
            else if (this.rdoLayerExtend.Checked)
            {
                IEnumGeometry        geometry;
                ITopologicalOperator @operator;
                if (this.cboLayers.SelectedIndex == -1)
                {
                    MessageBox.Show("请选择图层!");
                    return;
                }
                extent = null;
                ILayer layer = (this.cboLayers.SelectedItem as LayerObject).Layer;
                if (this.cboFeatures.SelectedIndex == 0)
                {
                    geometry = new EnumFeatureGeometryClass();
                    (geometry as IEnumGeometryBind).BindGeometrySource(null, (layer as IGeoFeatureLayer).FeatureClass);
                    @operator = new PolygonClass();
                    @operator.ConstructUnion(geometry);
                    this.ClipGeometry = @operator as IGeometry;
                }
                else if (this.cboFeatures.SelectedIndex == 1)
                {
                    IQueryFilter outputFilter = new SpatialFilterClass();
                    (outputFilter as ISpatialFilter).Geometry   = this.Extend;
                    (outputFilter as ISpatialFilter).SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    geometry = new EnumFeatureGeometryClass();
                    (geometry as IEnumGeometryBind).BindGeometrySource(outputFilter,
                                                                       (layer as IGeoFeatureLayer).FeatureClass);
                    IGeometryFactory3 factory   = new GeometryEnvironmentClass();
                    IGeometry         geometry2 = factory.CreateGeometryFromEnumerator(geometry);
                    int geometryCount           = (geometry2 as IGeometryCollection).GeometryCount;
                    @operator = new PolygonClass();
                    @operator.ConstructUnion(geometry2 as IEnumGeometry);
                    this.ClipGeometry = @operator as IGeometry;
                }
                else
                {
                    geometry = new EnumFeatureGeometryClass();
                    (geometry as IEnumGeometryBind).BindGeometrySource(null, (layer as IFeatureSelection).SelectionSet);
                    @operator = new PolygonClass();
                    @operator.ConstructUnion(geometry);
                    this.ClipGeometry = @operator as IGeometry;
                }
            }
            else
            {
                this.ClipGeometry = this.method_3(this.Map as IGraphicsContainerSelect);
            }
            base.DialogResult = DialogResult.OK;
        }
        private List<IElement> CreateElementAois(List<IPolygon> polygons, out IEnvelope encompassingEnvelope)
        {
            var rgbColor = new RgbColorClass { Red = 0, Green = 0, Blue = 255, Transparency = 200 };

            var geometryBag = new GeometryBagClass();
            geometryBag.SpatialReference = ArcMap.Document.FocusMap.SpatialReference;
            IGeometryCollection geometryCollection = geometryBag;
            var elements = new List<IElement>();
            foreach (var polygon in polygons)
            {
                geometryCollection.AddGeometry(polygon);
                IElement element = null;

                // Polygon elements
                ILineSymbol lineSymbol = new SimpleLineSymbolClass();
                lineSymbol.Color = rgbColor;
                lineSymbol.Width = 2.0;

                ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
                simpleFillSymbol.Color = rgbColor;
                simpleFillSymbol.Style = esriSimpleFillStyle.esriSFSNull;
                simpleFillSymbol.Outline = lineSymbol;

                IFillShapeElement fillShapeElement = new PolygonElementClass();
                fillShapeElement.Symbol = simpleFillSymbol;
                element = (IElement)fillShapeElement; // Explicit Cast

                element.Geometry = polygon;
                elements.Add(element);
            }

            // Create the polygon that will be the union of the features returned from the search cursor.
            // The spatial reference of this feature does not need to be set ahead of time. The
            // ConstructUnion method defines the constructed polygon's spatial reference to be the same as
            // the input geometry bag.
            ITopologicalOperator unionedPolygon = new PolygonClass();
            unionedPolygon.ConstructUnion(geometryBag);
            var masterPoly = (IPolygon)unionedPolygon;

            encompassingEnvelope = masterPoly.Envelope;
            return elements;
        }
예제 #15
0
        private IGeoDataset ConvertAndUnionWatershed(IGeoDataset tWatershedGDS)
        {
            //Convert the raster IGeodataset into a Polygon IFeatureClass, in a memory-workspace
            IWorkspace inMemFeatWksp = CreateInMemoryWorkspace();
            //IWorkspaceFactory pWSF = new ShapefileWorkspaceFactory();
            //IWorkspace pWS = pWSF.OpenFromFile(out_folder,0);
            string current = GetTimeStamp(DateTime.Now);
            string outname = "resultWatershed" + current;
            IFeatureClass tWaterShedPolyFC;
            IGeoDataset tInitialPolygons;
            try
            {
                IConversionOp pConversionOp = new ESRI.ArcGIS.GeoAnalyst.RasterConversionOp() as IConversionOp;
                tInitialPolygons = pConversionOp.RasterDataToPolygonFeatureData(tWatershedGDS, inMemFeatWksp, outname, false);
                tWaterShedPolyFC = tInitialPolygons as IFeatureClass;
            }
            catch
            {
                logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                        "Error in converting watershed to in-memory FC");
                tWaterShedPolyFC = null;
                tInitialPolygons = null;
            }

            // attempt to add a CATCH_AREA field to the feature class
            bool setAreaOk = false;
            try
            {
                //setAreaOk = AddAreaField(tWaterShedPolyFC);
                setAreaOk = AddAField(tWaterShedPolyFC, "Total_Area", esriFieldType.esriFieldTypeDouble);
            }
            catch
            {
                logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                        "Error adding area field to output");
            }

            IFeature tWaterShedFeature;
            // if there is more than one feature in the FC then union them using geometrybag
            if (tWaterShedPolyFC.FeatureCount(null) > 1)
            {
                logger.LogMessage(ServerLogger.msgType.infoStandard, "convert and union wshed", 8000,
                        "Attempting to union multiple polygons...");

                // there is more than one polygon i.e. diagonally connected. merge them into a single feature
                // with multiple rings using a geometrybag
                IGeometryBag tGeometryBag = new GeometryBagClass();
                tGeometryBag.SpatialReference = tInitialPolygons.SpatialReference;
                IFeatureCursor tFCursor = tWaterShedPolyFC.Search(null, false);
                IGeometryCollection tGeomColl = tGeometryBag as IGeometryCollection;
                IFeature tCurrentFeature = tFCursor.NextFeature();
                ITable tTable = tCurrentFeature.Table;
                while (tCurrentFeature != null)
                {
                    object missing = Type.Missing;
                    tGeomColl.AddGeometry(tCurrentFeature.Shape, ref missing, ref missing);
                    tCurrentFeature = tFCursor.NextFeature();
                }
                ITopologicalOperator tUnioned = new PolygonClass();
                tUnioned.ConstructUnion(tGeometryBag as IEnumGeometry);
                logger.LogMessage(ServerLogger.msgType.infoStandard, "convert and union wshed", 8000,
                    "Done with ConstructUnion, doing area");
                try
                {
                    IArea tmpArea = tUnioned as IArea;
                    double tArea = tmpArea.Area;
                    // delete the previously existing rows from the table
                    tTable.DeleteSearchedRows(null);
                    // replace them with a new row representing the unioned feature
                    IRow tRow = tTable.CreateRow();
                    tRow.set_Value(tTable.FindField("SHAPE"), tUnioned);
                    tRow.set_Value(tTable.FindField("ID"), -1);
                    tRow.set_Value(tTable.FindField("GRIDCODE"), -1);
                    if (setAreaOk)
                    {
                        tRow.set_Value(tTable.FindField("Total_Area"), tArea);
                    }
                    tRow.Store();
                }
                catch (Exception ex)
                {
                    logger.LogMessage(ServerLogger.msgType.error, "store unioned polygon", 8000,
                       "Error setting fields of unioned polygon!" + ex.StackTrace + ex.Message);
                }
            }
            else
            {
                // There is only one polygon - i.e. there were not diagonally-disconnected bits
                // NB features are indexed starting at 1. Just for a laff.
                tWaterShedFeature = tWaterShedPolyFC.GetFeature(1);
                if (setAreaOk)
                {
                    try
                    {
                        int tAreaFieldIdx = tWaterShedFeature.Fields.FindField("Total_Area");
                        IArea tArea = tWaterShedFeature.Shape as IArea;
                        double tmpArea = tArea.Area;
                        tWaterShedFeature.set_Value(tAreaFieldIdx, tmpArea);
                        tWaterShedFeature.Store();
                        logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                      "Done adding area to one polygon");
                    }
                    catch
                    {
                        logger.LogMessage(ServerLogger.msgType.debug, "convert and union wshed", 8000,
                        "Error adding area field to single polygon output");
                    }
                }
            }
            return (IGeoDataset)tWaterShedPolyFC;
        }
        // =========================================================================
        // Functions (Public)
        // =========================================================================
        public string GetGmlFromLocation(List <RecordingLocation> recordingLocations, double distance, out Color color, SpatialReference cyclSpatialRef)
        {
            string result = WfsHeader;

            // ReSharper disable UseIndexedProperty

            if (_featureClass != null)
            {
                IGeometry         geometryBag        = new GeometryBagClass();
                var               geometryCollection = geometryBag as IGeometryCollection;
                Config            config             = Config.Instance;
                SpatialReference  spatRel            = config.SpatialReference;
                ISpatialReference gsSpatialReference = (spatRel == null) ? ArcUtils.SpatialReference : spatRel.SpatialRef;
                var               projCoord          = gsSpatialReference as IProjectedCoordinateSystem;

                if (projCoord == null)
                {
                    var geoCoord = gsSpatialReference as IGeographicCoordinateSystem;

                    if (geoCoord != null)
                    {
                        IAngularUnit unit   = geoCoord.CoordinateUnit;
                        double       factor = unit.ConversionFactor;
                        distance = distance * factor;
                    }
                }
                else
                {
                    ILinearUnit unit   = projCoord.CoordinateUnit;
                    double      factor = unit.ConversionFactor;
                    distance = distance / factor;
                }

                foreach (var recordingLocation in recordingLocations)
                {
                    double x = recordingLocation.X;
                    double y = recordingLocation.Y;

                    IEnvelope envelope = new EnvelopeClass
                    {
                        XMin             = x - distance,
                        XMax             = x + distance,
                        YMin             = y - distance,
                        YMax             = y + distance,
                        SpatialReference = gsSpatialReference
                    };

                    envelope.Project(SpatialReference);
                    geometryCollection.AddGeometry(envelope);
                }

                ITopologicalOperator unionedPolygon = new PolygonClass();
                unionedPolygon.ConstructUnion(geometryBag as IEnumGeometry);
                var polygon = unionedPolygon as IPolygon;

                ISpatialFilter spatialFilter = new SpatialFilterClass
                {
                    Geometry      = polygon,
                    GeometryField = _featureClass.ShapeFieldName,
                    SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects
                };

                var featureCursor = _featureClass.Search(spatialFilter, false);
                var featureCount  = _featureClass.FeatureCount(spatialFilter);
                var shapeId       = featureCursor.FindField(_featureClass.ShapeFieldName);
                var gmlConverter  = new GMLConverter();

                for (int i = 0; i < featureCount; i++)
                {
                    IFeature feature = featureCursor.NextFeature();

                    if (!EditFeatures.Contains(feature))
                    {
                        IFields fields      = feature.Fields;
                        var     fieldvalues = new Dictionary <string, string> {
                            { "FEATURECLASSNAME", _featureClass.AliasName }
                        };

                        for (int j = 0; j < fields.FieldCount; j++)
                        {
                            IField field = fields.Field[j];
                            string name  = field.Name;
                            int    id    = featureCursor.FindField(name);

                            string value = (id != shapeId)
                ? feature.get_Value(id).ToString()
                : _featureClass.ShapeType.ToString().Replace("esriGeometry", string.Empty);
                            fieldvalues.Add(name, value);
                        }

                        var shapeVar = feature.get_Value(shapeId);
                        var geometry = shapeVar as IGeometry;

                        if (geometry != null)
                        {
                            geometry.Project((cyclSpatialRef == null) ? gsSpatialReference : cyclSpatialRef.SpatialRef);

                            if (!HasZ)
                            {
                                var pointCollection = geometry as IPointCollection4;

                                if (pointCollection != null)
                                {
                                    for (int j = 0; j < pointCollection.PointCount; j++)
                                    {
                                        IPoint point = pointCollection.Point[j];

                                        if (point != null)
                                        {
                                            point.Z = double.NaN;
                                        }

                                        pointCollection.ReplacePoints(j, 1, 1, point);
                                    }

                                    shapeVar = pointCollection as IGeometry;
                                }
                                else
                                {
                                    var point = geometry as IPoint;

                                    if (point != null)
                                    {
                                        point.Z  = double.NaN;
                                        shapeVar = point;
                                    }
                                }
                            }
                        }

                        gmlConverter.ESRIGeometry = shapeVar;
                        string gml = gmlConverter.GML;
                        gml = gml.Replace("<Polygon>", string.Format("<Polygon srsDimension=\"{0}\" >", HasZ ? 3 : 2));
                        gml = gml.Replace("<LineString>", string.Format("<LineString srsDimension=\"{0}\" >", HasZ ? 3 : 2));
                        gml = gml.Replace("<point>", string.Format("<point srsDimension=\"{0}\" >", HasZ ? 3 : 2));
                        gml = gml.Replace("point", "Point");
                        gml = gml.Replace(",1.#QNAN", string.Empty);
                        gml = gml.Replace("<", "<gml:");
                        gml = gml.Replace("<gml:/", "</gml:");
                        string fieldValueStr = fieldvalues.Aggregate(string.Empty,
                                                                     (current, fieldvalue) => string.Format("{0}<{1}>{2}</{1}>", current, fieldvalue.Key, fieldvalue.Value));
                        result = string.Format("{0}<gml:featureMember><xs:Geometry>{1}{2}</xs:Geometry></gml:featureMember>", result,
                                               fieldValueStr, gml);
                    }
                }
            }

            // ReSharper restore UseIndexedProperty
            color      = ArcUtils.GetColorFromLayer(_layer);
            GmlChanged = (_color != color);
            _color     = color;
            string newGml = string.Concat(result, WfsFinished);

            GmlChanged = ((newGml != _gml) || GmlChanged);
            return(_gml = newGml);
        }
예제 #17
0
        private static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart, ref IElementCollection elemCollection)
        {
            IGeometry theReturn = null;
            IGeometryCollection theGeomColl = null;
            object missing = Type.Missing;

            try
            {
                elemCollection.Clear();

                if (theElements != null)
                {
                    theElements.Reset();
                    IElement theElement = theElements.Next();
                    while (theElement != null)
                    {
                        if (theGeomColl == null)
                            theGeomColl = new GeometryBagClass();

                        IGeometry theShape = null;
                        if (theElement is IGroupElement)
                        {
                            theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart,ref elemCollection);
                        }
                        else if (theElement is ICircleElement
                            || theElement is IPolygonElement
                            || theElement is IRectangleElement
                            || theElement is IEllipseElement
                            || theElement is ILineElement
                            || theElement is IMarkerElement)
                            theShape = theElement.Geometry;

                        if (theShape != null)
                            theGeomColl.AddGeometry(theShape, ref missing, ref missing);

                        elemCollection.Add(theElement,-1);

                        theElement = theElements.Next();
                    }
                }

                if (theGeomColl != null && theGeomColl.GeometryCount > 0)
                {
                    ITopologicalOperator theTopoOp = null;

                    switch (a_Dimensionality)
                    {
                        case 0:
                            if (multipart)
                            {
                                theTopoOp = new MultipointClass();
                                theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                            }
                            else
                                theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator;
                            break;
                        case 1:
                            theTopoOp = new PolylineClass();
                            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                            break;
                        case 2:
                            theTopoOp = new PolygonClass();
                            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                            break;
                    }

                    theReturn = theTopoOp as IGeometry;
                }
            }
            catch(Exception ex)
            {
                util.Logger.Write(" Descrip  : Finding elements with a specific dimensionality. " +
                    "\n Message  : " + ex.Message +
                    "\n StackTrc : " + ex.StackTrace,util.Logger.LogLevel.Debug);

            }
            return theReturn;
        }
        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);
            }
        }
예제 #19
0
        public static IGeometry get_GraphicShape(IEnumElement theElements, int a_Dimensionality, bool multipart)
        {
            IGeometry theReturn = null;
            IGeometryCollection theGeomColl = null;
            object missing = Type.Missing;

            if (theElements != null)
            {
                theElements.Reset();
                IElement theElement = theElements.Next();
                while (theElement != null)
                {
                    if (theGeomColl == null)
                        theGeomColl = new GeometryBagClass();

                    IGeometry theShape = null;
                    if (theElement is IGroupElement)
                    {
                        theShape = get_GraphicShape(((IGroupElement)theElement).Elements, a_Dimensionality, multipart);
                    }
                    else if (theElement is ICircleElement
                        || theElement is IPolygonElement
                        || theElement is IRectangleElement
                        || theElement is IEllipseElement
                        || theElement is ILineElement
                        || theElement is IMarkerElement)
                        theShape = theElement.Geometry;

                    if (theShape != null)
                        theGeomColl.AddGeometry(theShape, ref missing, ref missing);

                    theElement = theElements.Next();
                }
            }

            if (theGeomColl != null && theGeomColl.GeometryCount > 0)
            {
                ITopologicalOperator theTopoOp = null;

                switch (a_Dimensionality)
                {
                    case 0:
                        if (multipart)
                        {
                            theTopoOp = new MultipointClass();
                            theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        }
                        else
                            theTopoOp = theGeomColl.get_Geometry(0) as ITopologicalOperator;
                        break;
                    case 1:
                        theTopoOp = new PolylineClass();
                        theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        break;
                    case 2:
                        theTopoOp = new PolygonClass();
                        theTopoOp.ConstructUnion((IEnumGeometry)theGeomColl);
                        break;
                }

                theReturn = theTopoOp as IGeometry;
            }
            return theReturn;
        }
예제 #20
0
        public bool HasTangentCurveMatchFeatures(IFeatureClass FeatureClass, IPolycurve inPolycurve, string WhereClause,
  double AngleToleranceTangentCompareInDegrees, double StraightLinesBreakLessThanInDegrees, double MaximumDeltaInDegrees, double ExcludeTangentsShorterThan, 
      out int outFoundTangentCurvesCount, ref List<string> CurveInfoFromNeighbours)
        {
            outFoundTangentCurvesCount = 0;

              ILine pOriginalChord = new Line();
              pOriginalChord.PutCoords(inPolycurve.FromPoint, inPolycurve.ToPoint);
              IVector3D vecOriginalSelected = new Vector3DClass();
              vecOriginalSelected.PolarSet(pOriginalChord.Angle, 0, 1);

              int idxRadius = FeatureClass.FindField("RADIUS");
              if (idxRadius == -1)
            return false;

              int idxCenterPointID = FeatureClass.FindField("CENTERPOINTID");
              if (idxCenterPointID == -1)
            return false;

              object val = null;

              IGeometryBag pGeomBag = new GeometryBagClass();
              IGeometryCollection pGeomColl = (IGeometryCollection)pGeomBag;

              IGeometry MultiPartPolyLine = new PolylineClass(); //qi
              IGeoDataset pGeoDS = (IGeoDataset)FeatureClass;
              ISpatialReference spatialRef = pGeoDS.SpatialReference;
              MultiPartPolyLine.SpatialReference = spatialRef;

              IGeometryCollection geometryCollection2 = MultiPartPolyLine as IGeometryCollection;

              ILine pTangentLineAtEnd = new Line(); //new
              ILine pTangentLineAtStart = new Line(); //new
              object objMissing = Type.Missing;

              for (int i = 0; i < 2; i++)
              {
            ILine pThisLine = null;
            if (i == 0)
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 0.2, pTangentLineAtEnd);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtEnd.FromPoint, pTangentLineAtEnd.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            else
            {
              inPolycurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 0.2, pTangentLineAtStart);
              pThisLine = new Line();
              pThisLine.PutCoords(pTangentLineAtStart.FromPoint, pTangentLineAtStart.ToPoint);
              pGeomColl.AddGeometry(pThisLine);
            }
            //Create a new path for each line.

            ISegmentCollection newPath = new PathClass();
            newPath.AddSegment((ISegment)pThisLine, ref objMissing, ref objMissing);
            //The spatial reference associated with geometryCollection will be assigned to all incoming paths and segments.
            geometryCollection2.AddGeometry(newPath as IGeometry, ref objMissing, ref objMissing);
              }

              //now buffer the lines
              IGeometryCollection outBufferedGeometryCol = new GeometryBagClass();
              for (int jj = 0; jj < geometryCollection2.GeometryCount; jj++)
              {
            IPath pPath = geometryCollection2.get_Geometry(jj) as IPath;
            IGeometryCollection pPolyL = new PolylineClass();
            pPolyL.AddGeometry((IGeometry)pPath);

            ITopologicalOperator topologicalOperator = (ITopologicalOperator)pPolyL;
            IPolygon pBuffer = topologicalOperator.Buffer(0.1) as IPolygon;
            outBufferedGeometryCol.AddGeometry(pBuffer, ref objMissing, ref objMissing);
              }
              ITopologicalOperator pUnionedBuffers = null;
              pUnionedBuffers = new PolygonClass() as ITopologicalOperator;
              pUnionedBuffers.ConstructUnion((IEnumGeometry)outBufferedGeometryCol);

              ISpatialFilter pSpatFilt = new SpatialFilter();
              pSpatFilt.WhereClause = WhereClause;
              pSpatFilt.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
              pSpatFilt.SearchOrder = esriSearchOrder.esriSearchOrderSpatial;

              pSpatFilt.Geometry = (IGeometry)pUnionedBuffers;

              IFeatureCursor pFeatCursLines = null;
              try
              {
            pFeatCursLines = FeatureClass.Search(pSpatFilt, false);
              }
              catch (Exception ex)
              {
            MessageBox.Show(ex.Message);
            return false;
              }
              IVector3D vecFoundGeom = new Vector3DClass();
              IFeature pFeat = pFeatCursLines.NextFeature();
              bool bHasTangentStraightLineAtJunction = false;
              List<int> lstLargeBreak = new List<int>();

              while (pFeat != null)
              {
            IGeometry pFoundLineGeom = pFeat.ShapeCopy;
            IPolycurve pFoundLineAsPolyCurve = pFoundLineGeom as IPolycurve;
            int iRelativeOrientation = GetRelativeOrientation(pFoundLineAsPolyCurve, inPolycurve);
            //iRelativeOrientation == 1 --> closest points are original TO and found TO
            //iRelativeOrientation == 2 --> closest points are original TO and found FROM
            //iRelativeOrientation == 3 --> closest points are original FROM and found TO
            //iRelativeOrientation == 4 --> closest points are original FROM and found FROM

            //if the feature has no radius attribute, skip.
            double dRadius = 0;
            int iCtrPoint = -1;
            val = pFeat.get_Value(idxRadius);
            if (val == DBNull.Value)
              dRadius = 0;
            else
              dRadius = (double)val;

            val = pFeat.get_Value(idxCenterPointID);

            IPolycurve pPolyCurve = pFoundLineGeom as IPolycurve;

            ILine pFoundChordCandidate = new LineClass();
            pFoundChordCandidate.PutCoords(pPolyCurve.FromPoint, pPolyCurve.ToPoint);
            //first check for liklihood that subject line is supposed to stay straight, by
            //geometry chord bearing angle break test
            vecFoundGeom.PolarSet(pFoundChordCandidate.Angle, 0, 1);
            double dDotProd = vecFoundGeom.DotProduct(vecOriginalSelected);
            double dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            double dLargeAngleBreakInDegrees = 3;
            if (dAngleCheck > dLargeAngleBreakInDegrees && dAngleCheck < (180 - dLargeAngleBreakInDegrees)) //large angle break non-tangent, greater than 3 degrees
            {
              if (!lstLargeBreak.Contains(iRelativeOrientation))
            lstLargeBreak.Add(iRelativeOrientation);
            }

            if ((dAngleCheck <= StraightLinesBreakLessThanInDegrees || (180 - dAngleCheck) < StraightLinesBreakLessThanInDegrees)
            && val == DBNull.Value && dRadius == 0 && !(pPolyCurve.Length< ExcludeTangentsShorterThan))
            {
              if (lstLargeBreak.Contains(iRelativeOrientation))
            bHasTangentStraightLineAtJunction = true;
            }

            if (val == DBNull.Value || dRadius == 0 || pPolyCurve.Length< ExcludeTangentsShorterThan)
            {//if the feature has a null centrpointID then skip.
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            if (Math.Abs(inPolycurve.Length / dRadius * 180 / Math.PI) > MaximumDeltaInDegrees)
            {
              //if the resulting curve would have a central angle more than MaximumDeltaInDegrees degrees then skip
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            iCtrPoint = (int)val;

            //if geometry of curve neighbour curves have been cracked then there can be more than one segment
            //however since all segments would be circular arcs, just need to test the first segment
            ISegmentCollection pFoundLineGeomSegs = pFoundLineGeom as ISegmentCollection;
            ISegment pSeg = pFoundLineGeomSegs.get_Segment(0);
            if (!(pSeg is ICircularArc))
            {
              Marshal.ReleaseComObject(pFeat);
              pFeat = pFeatCursLines.NextFeature();
              continue;
            }

            dRadius = (double)pFeat.get_Value(idxRadius);

            IVector3D vect1 = new Vector3DClass();
            IVector3D vect2 = new Vector3DClass();
            ILine tang = new Line();
            double dUnitSignChange = 1;
            if (iRelativeOrientation == 1) //closest points are original TO and found TO
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 2)//closest points are original TO and found FROM
            {
              vect1.PolarSet(pTangentLineAtEnd.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 3)//closest points are original FROM and found TO
            {
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtTo, 1.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }
            else if (iRelativeOrientation == 4)//closest points are original FROM and found FROM
            {
              dUnitSignChange = -1;
              vect1.PolarSet(pTangentLineAtStart.Angle, 0, 1);
              pFoundLineAsPolyCurve.QueryTangent(esriSegmentExtension.esriExtendAtFrom, 0.0, true, 1, tang);
              vect2.PolarSet(tang.Angle, 0, 1);
            }

            dDotProd = vect1.DotProduct(vect2);
            dAngleCheck = Math.Acos(dDotProd) * 180 / Math.PI; //in degrees
            dAngleCheck = Math.Abs(dAngleCheck);
            if (dAngleCheck < AngleToleranceTangentCompareInDegrees || (180 - dAngleCheck) < AngleToleranceTangentCompareInDegrees)
            {

              double dDerivedRadius = dRadius * dUnitSignChange;

              string sHarvestedCurveInfo = pFeat.OID.ToString() + "," + dDerivedRadius.ToString("#.000") + "," +
            iCtrPoint.ToString() + "," + "t";
              CurveInfoFromNeighbours.Add(sHarvestedCurveInfo);

              outFoundTangentCurvesCount++;
            }

            Marshal.ReleaseComObject(pFeat);
            pFeat = pFeatCursLines.NextFeature();
              }
              Marshal.FinalReleaseComObject(pFeatCursLines);

              if (bHasTangentStraightLineAtJunction)
            return false; //open to logic change to be less conservative

              bool bHasParallelCurveFeaturesNearby = (outFoundTangentCurvesCount > 0);

              return bHasParallelCurveFeaturesNearby;
        }
        //合并要素
        private void UnionFeatures(IEnumFeature selectedFeatures, IFeature pMergeFeature)
        {
            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();
            IDataset            dataset      = null;

            while (feature != null)
            {
                geometry = feature.ShapeCopy;
                geometries.AddGeometry(geometry, ref missing, ref missing);
                feature = selectedFeatures.Next();
            }
            ITopologicalOperator2 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;
            }
            IEnumGeometry enuGeo = geometries as IEnumGeometry;

            unionedGeometry.ConstructUnion(enuGeo);
            ITopologicalOperator2 topo = unionedGeometry as ITopologicalOperator2;

            topo.IsKnownSimple_2 = false; topo.Simplify();
            IFeatureClass targetFeatureClass = currentLayer.FeatureClass;

            dataset = featureClass as IDataset;
            selectedFeatures.Reset();
            //如果没有IWorkspaceEdit则无法进行撤销重做操作
            IWorkspaceEdit workspaceEdit = dataset.Workspace as IWorkspaceEdit;

            try
            {
                //workspaceEdit.StartEditOperation();
                IFeature    unionedFeature = targetFeatureClass.CreateFeature();
                IFields     pFields        = unionedFeature.Fields;
                IFieldsEdit pFieldsEdit    = pFields as IFieldsEdit;
                IField      pField         = null;
                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    pField = pFields.Field[i];
                    if (targetFeatureClass.AreaField != null && targetFeatureClass.LengthField != null)
                    {
                        if (pField.Name != targetFeatureClass.OIDFieldName && pField.Name != targetFeatureClass.ShapeFieldName &&
                            pField.Name != targetFeatureClass.AreaField.Name && pField.Name != targetFeatureClass.LengthField.Name)
                        {
                            unionedFeature.set_Value(i, pMergeFeature.Value[i]);
                        }
                    }
                    else
                    {
                        if (pField.Name != targetFeatureClass.OIDFieldName && pField.Name != targetFeatureClass.ShapeFieldName)
                        {
                            unionedFeature.set_Value(i, pMergeFeature.Value[i]);
                        }
                    }
                }

                unionedFeature.Shape = unionedGeometry as IGeometry;
                unionedFeature.Store();
                while ((feature = selectedFeatures.Next()) != null)
                {
                    feature.Delete();
                }
                workspaceEdit.StopEditOperation();
            }
            catch (Exception ex)
            {
                //SysLogHelper.WriteOperationLog("要素合并错误", ex.Source, "数据编辑");
                MessageBox.Show(ex.Message);
            }
        }