コード例 #1
0
        private IGeometry mergeSmallGeos(IGeometry geo)
        {
            ITopologicalOperator4 tp4    = (ITopologicalOperator4)geo;
            IGeometryCollection   geoCol = new PolygonClass();
            IGeometry             bGeo   = tp4.Boundary;
            ISpatialFilter        spFilt = new SpatialFilter();

            spFilt.Geometry      = bGeo;
            spFilt.SearchOrder   = esriSearchOrder.esriSearchOrderSpatial;
            spFilt.GeometryField = ftrCls.ShapeFieldName;
            spFilt.SpatialRel    = esriSpatialRelEnum.esriSpatialRelContains;
            spFilt.WhereClause   = "Shape_Area <= " + minarea;
            spFilt.SubFields     = ftrCls.ShapeFieldName;
            IFeatureCursor ftrCur  = ftrCls.Search(spFilt, false);
            IFeature       ftr     = ftrCur.NextFeature();
            int            cntTest = 0;

            while (ftr != null)
            {
                IGeometry sGeo = ftr.ShapeCopy;
                geoCol.AddGeometry(sGeo);
                ftr.Delete();
                ftr = ftrCur.NextFeature();
                cntTest++;
            }
            if (cntTest > 0)
            {
                tp4.ConstructUnion((IEnumGeometry)geoCol);
            }
            return((IGeometry)tp4);
        }
コード例 #2
0
        private IArray method_1(IGeometry igeometry_0, IGeometry igeometry_1)
        {
            IArray                array;
            IPolyline             polyline   = null;
            ITopologicalOperator4 igeometry0 = null;

            if (!(igeometry_0 == null ? false : igeometry_1 != null))
            {
                array = null;
            }
            else if (igeometry_0.GeometryType == esriGeometryType.esriGeometryPolygon)
            {
                polyline = (igeometry_1.GeometryType == esriGeometryType.esriGeometryPolyline
                    ? (IPolyline)igeometry_1
                    : (IPolyline)((ITopologicalOperator4)igeometry_1).Boundary);
                igeometry0 = (ITopologicalOperator4)igeometry_0;
                IArray arrayClass = new Array();
                IGeometryCollection geometryCollection = igeometry0.Cut2(polyline);
                for (int i = 0; i < geometryCollection.GeometryCount; i++)
                {
                    arrayClass.Add(geometryCollection.Geometry[i]);
                }
                array = arrayClass;
            }
            else
            {
                array = null;
            }
            return(array);
        }
コード例 #3
0
        private bool updatePolygon(IFeatureClass ftrCls, int oid)
        {
            bool           x     = false;
            IGeometry      geo   = ftrCls.GetFeature(oid).ShapeCopy;
            ISpatialFilter spFlt = new SpatialFilterClass();

            spFlt.WhereClause = ftrCls.OIDFieldName + " <> " + oid.ToString();
            spFlt.SpatialRel  = esriSpatialRelEnum.esriSpatialRelIntersects;
            IQueryFilterDefinition2 qryDef2 = (IQueryFilterDefinition2)spFlt;

            qryDef2.PostfixClause = "Order by Shape_Area DESC";
            spFlt.Geometry        = geo;
            spFlt.GeometryField   = ftrCls.ShapeFieldName;
            spFlt.SearchOrder     = esriSearchOrder.esriSearchOrderSpatial;
            IFeatureCursor ftrCur         = ftrCls.Search(spFlt, false);
            int            shapeAreaIndex = ftrCur.FindField("Shape_Area");
            IFeature       ftr            = ftrCur.NextFeature();

            while (ftr != null)
            {
                IGeometry             geoMax    = ftr.ShapeCopy;
                int                   beforeCnt = ((IGeometryCollection)geoMax).GeometryCount;
                ITopologicalOperator4 tp        = (ITopologicalOperator4)geoMax;
                IGeometry             uGeo      = tp.Union(geo);
                int                   afterCnt  = ((IGeometryCollection)uGeo).GeometryCount;
                if (beforeCnt >= afterCnt)
                {
                    try
                    {
                        ftr.Shape = uGeo;
                        if (shapeAreaEdit)
                        {
                            ftr.set_Value(shapeAreaIndex, ((IArea)uGeo).Area);
                        }
                        ftr.Store();
                        x = true;
                        return(x);
                    }
                    catch (Exception e)
                    {
                        x = false;
                        Console.WriteLine(e.ToString());
                        return(x);
                    }
                }
                ftr = ftrCur.NextFeature();
            }
            return(x);
        }
コード例 #4
0
ファイル: ZDEditTools.cs プロジェクト: secondii/Yutai
        public static IFeature Union(List <IFeature> list_0)
        {
            ITopologicalOperator4 shapeCopy = null;
            IGeometry             geometry  = null;
            List <IFeature>       features  = new List <IFeature>();

            foreach (IFeature list0 in list_0)
            {
                features.Add(ZDEditTools.WriteHistory(list0));
                if (shapeCopy != null)
                {
                    geometry  = shapeCopy.Union(list0.ShapeCopy);
                    shapeCopy = geometry as ITopologicalOperator4;
                }
                else
                {
                    shapeCopy = list0.ShapeCopy as ITopologicalOperator4;
                }
            }
            IFeature feature = ZDEditTools.ZDFeatureClass.CreateFeature();

            feature.Shape = geometry;
            RowOperator.CopyFeatureAttributeToFeature(list_0[0], feature);
            feature.Store();
            (ZDEditTools.ZDFeatureClass as IDataset).Name.Split(new char[] { '.' });
            ZDHistoryTable zDHistoryTable = new ZDHistoryTable();

            ZDEditTools.StartEditDateTime = DateTime.Now;
            int num = 0;

            foreach (IFeature list01 in list_0)
            {
                int num1 = num;
                num = num1 + 1;
                ZDEditTools.WriteHistoryLine(list01, feature, features[num1], 1, ZDEditTools.StartEditDateTime);
                list01.Delete();
            }
            ZDEditTools.Oids.Add(feature.OID);
            return(feature);
        }
コード例 #5
0
        public static IFeature Union(System.Collections.Generic.List <IFeature> list_0)
        {
            ITopologicalOperator4 topologicalOperator = null;
            IGeometry             geometry            = null;

            System.Collections.Generic.List <IFeature> list = new System.Collections.Generic.List <IFeature>();
            foreach (IFeature current in list_0)
            {
                list.Add(ZDEditTools.WriteHistory(current));
                if (topologicalOperator == null)
                {
                    topologicalOperator = (current.ShapeCopy as ITopologicalOperator4);
                }
                else
                {
                    geometry            = topologicalOperator.Union(current.ShapeCopy);
                    topologicalOperator = (geometry as ITopologicalOperator4);
                }
            }
            IFeature feature = ZDEditTools.ZDFeatureClass.CreateFeature();

            feature.Shape = geometry;
            RowOperator.CopyFeatureAttributeToFeature(list_0[0], feature);
            feature.Store();
            (ZDEditTools.ZDFeatureClass as IDataset).Name.Split(new char[]
            {
                '.'
            });
            new ZDHistoryTable();
            ZDEditTools.StartEditDateTime = System.DateTime.Now;
            int num = 0;

            foreach (IFeature current in list_0)
            {
                ZDEditTools.WriteHistoryLine(current, feature, list[num++], 1, ZDEditTools.StartEditDateTime);
                current.Delete();
            }
            ZDEditTools.Oids.Add(feature.OID);
            return(feature);
        }
コード例 #6
0
        /// <summary>
        /// 获取两个Polygon的相交部分geometry
        /// </summary>
        /// <param name="polygon1"></param>
        /// <param name="polygon2"></param>
        /// <returns></returns>
        public static IGeometry GetIntersectGeometry(IPolygon polygon1, IPolygon polygon2)
        {
            try
            {
                bool isTouch = IsTouch(polygon1, polygon2);
                if (isTouch)
                {
                    return(null);
                }

                ITopologicalOperator4 topo = polygon1 as ITopologicalOperator4;

                IGeometry intersectGeom = topo.Intersect(polygon2
                                                         , esriGeometryDimension.esriGeometry2Dimension);

                return(intersectGeom);
            }
            catch (Exception ex)
            {
                LOG.Error(ex);
            }
            return(null);
        }
コード例 #7
0
ファイル: ZDEditTools.cs プロジェクト: secondii/Yutai
        public static List <IFeature> Split(IFeature ifeature_0, IPolyline ipolyline_0)
        {
            IGeometry             geometry;
            IGeometry             geometry1;
            IFeature              feature;
            IFeature              feature1;
            List <IFeature>       features  = new List <IFeature>();
            ITopologicalOperator4 shapeCopy = ifeature_0.ShapeCopy as ITopologicalOperator4;
            IGeometry             geometry2 = shapeCopy.Intersect(ipolyline_0, esriGeometryDimension.esriGeometry0Dimension);
            List <IFeature>       features1 = new List <IFeature>();

            ZDEditTools.StartEditDateTime = DateTime.Now;
            if (geometry2.IsEmpty)
            {
                shapeCopy.Cut(ipolyline_0, out geometry, out geometry1);
                if ((geometry == null ? false : geometry1 != null))
                {
                    feature  = ZDEditTools.WriteHistory(ifeature_0);
                    feature1 = ZDEditTools.ZDFeatureClass.CreateFeature();
                    features.Add(feature1);
                    feature1.Shape = geometry;
                    RowOperator.CopyFeatureAttributeToFeature(ifeature_0, feature1);
                    feature1.Store();
                    ZDEditTools.Oids.Add(feature1.OID);
                    ZDEditTools.WriteHistoryLine(ifeature_0, feature1, feature, 2, ZDEditTools.StartEditDateTime);
                    feature1 = ZDEditTools.ZDFeatureClass.CreateFeature();
                    features.Add(feature1);
                    feature1.Shape = geometry1;
                    RowOperator.CopyFeatureAttributeToFeature(ifeature_0, feature1);
                    feature1.Store();
                    ZDEditTools.Oids.Add(feature1.OID);
                    ZDEditTools.WriteHistoryLine(ifeature_0, feature1, feature, 2, ZDEditTools.StartEditDateTime);
                    ifeature_0.Delete();
                }
            }
            else if ((!(geometry2 is IMultipoint) ? false : (geometry2 as IPointCollection).PointCount > 1))
            {
                ISpatialFilter spatialFilterClass = new SpatialFilter()
                {
                    Geometry   = ipolyline_0,
                    SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects
                };
                IFeatureCursor featureCursor = (ifeature_0.Class as IFeatureClass).Search(spatialFilterClass, false);
                for (IFeature i = featureCursor.NextFeature(); i != null; i = featureCursor.NextFeature())
                {
                    if (i.OID != ifeature_0.OID)
                    {
                        features1.Add(i);
                    }
                }
                ComReleaser.ReleaseCOMObject(featureCursor);
                int    pointCount = (geometry2 as IPointCollection).PointCount;
                IPoint point      = (geometry2 as IPointCollection).Point[0];
                IPoint point1     = (geometry2 as IPointCollection).Point[pointCount - 1];
                foreach (IFeature feature2 in features1)
                {
                    ZDEditTools.HitTest(feature2, point);
                    ZDEditTools.HitTest(feature2, point1);
                }
                IGeometryCollection geometryCollection = shapeCopy.Cut2(ipolyline_0);
                DateTime            startEditDateTime  = ZDEditTools.StartEditDateTime;
                feature = ZDEditTools.WriteHistory(ifeature_0);
                for (int j = 0; j < geometryCollection.GeometryCount; j++)
                {
                    IGeometry geometry3 = geometryCollection.Geometry[j];
                    feature1 = ZDEditTools.ZDFeatureClass.CreateFeature();
                    features.Add(feature1);
                    feature1.Shape = geometry3;
                    RowOperator.CopyFeatureAttributeToFeature(ifeature_0, feature1);
                    feature1.Store();
                    ZDEditTools.Oids.Add(feature1.OID);
                    ZDEditTools.WriteHistoryLine(ifeature_0, feature1, feature, 2, startEditDateTime);
                }
                ifeature_0.Delete();
            }
            return(features);
        }
コード例 #8
0
        public static System.Collections.Generic.List <IFeature> Split(IFeature ifeature_0, IPolyline ipolyline_0)
        {
            System.Collections.Generic.List <IFeature> list = new System.Collections.Generic.List <IFeature>();
            ITopologicalOperator4 topologicalOperator       = ifeature_0.ShapeCopy as ITopologicalOperator4;
            IGeometry             geometry = topologicalOperator.Intersect(ipolyline_0, esriGeometryDimension.esriGeometry0Dimension);

            System.Collections.Generic.List <IFeature> list2 = new System.Collections.Generic.List <IFeature>();
            ZDEditTools.StartEditDateTime = System.DateTime.Now;
            if (geometry.IsEmpty)
            {
                IGeometry geometry2;
                IGeometry geometry3;
                topologicalOperator.Cut(ipolyline_0, out geometry2, out geometry3);
                if (geometry2 != null && geometry3 != null)
                {
                    IFeature ifeature_ = ZDEditTools.WriteHistory(ifeature_0);
                    IFeature feature   = ZDEditTools.ZDFeatureClass.CreateFeature();
                    list.Add(feature);
                    feature.Shape = geometry2;
                    RowOperator.CopyFeatureAttributeToFeature(ifeature_0, feature);
                    feature.Store();
                    ZDEditTools.Oids.Add(feature.OID);
                    ZDEditTools.WriteHistoryLine(ifeature_0, feature, ifeature_, 2, ZDEditTools.StartEditDateTime);
                    feature = ZDEditTools.ZDFeatureClass.CreateFeature();
                    list.Add(feature);
                    feature.Shape = geometry3;
                    RowOperator.CopyFeatureAttributeToFeature(ifeature_0, feature);
                    feature.Store();
                    ZDEditTools.Oids.Add(feature.OID);
                    ZDEditTools.WriteHistoryLine(ifeature_0, feature, ifeature_, 2, ZDEditTools.StartEditDateTime);
                    ifeature_0.Delete();
                }
            }
            else if (geometry is IMultipoint && (geometry as IPointCollection).PointCount > 1)
            {
                ISpatialFilter spatialFilter = new SpatialFilter();
                spatialFilter.Geometry   = ipolyline_0;
                spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                IFeatureCursor featureCursor = (ifeature_0.Class as IFeatureClass).Search(spatialFilter, false);
                for (IFeature feature2 = featureCursor.NextFeature();
                     feature2 != null;
                     feature2 = featureCursor.NextFeature())
                {
                    if (feature2.OID != ifeature_0.OID)
                    {
                        list2.Add(feature2);
                    }
                }
                ComReleaser.ReleaseCOMObject(featureCursor);
                int    pointCount = (geometry as IPointCollection).PointCount;
                IPoint ipoint_    = (geometry as IPointCollection).get_Point(0);
                IPoint ipoint_2   = (geometry as IPointCollection).get_Point(pointCount - 1);
                foreach (IFeature current in list2)
                {
                    ZDEditTools.HitTest(current, ipoint_);
                    ZDEditTools.HitTest(current, ipoint_2);
                }
                IGeometryCollection geometryCollection = topologicalOperator.Cut2(ipolyline_0);
                System.DateTime     startEditDateTime  = ZDEditTools.StartEditDateTime;
                IFeature            ifeature_          = ZDEditTools.WriteHistory(ifeature_0);
                for (int i = 0; i < geometryCollection.GeometryCount; i++)
                {
                    IGeometry shape   = geometryCollection.get_Geometry(i);
                    IFeature  feature = ZDEditTools.ZDFeatureClass.CreateFeature();
                    list.Add(feature);
                    feature.Shape = shape;
                    RowOperator.CopyFeatureAttributeToFeature(ifeature_0, feature);
                    feature.Store();
                    ZDEditTools.Oids.Add(feature.OID);
                    ZDEditTools.WriteHistoryLine(ifeature_0, feature, ifeature_, 2, startEditDateTime);
                }
                ifeature_0.Delete();
            }
            return(list);
        }
コード例 #9
0
        private static IGeometry UnionItemsFor(IFeatureClass featureClass, SpatialFilter privateFilter, ITopologicalOperator4 countyPart)
        {
            var       cursor = featureClass.Search(privateFilter, true);
            IFeature  privateLand;
            IGeometry privateGeometry = null;

            while ((privateLand = cursor.NextFeature()) != null)
            {
                var intersect = countyPart.Intersect(privateLand.ShapeCopy, esriGeometryDimension.esriGeometry2Dimension);

                if (privateGeometry == null)
                {
                    privateGeometry = intersect;
                }
                else
                {
                    privateGeometry = ((ITopologicalOperator4)privateGeometry).Union(intersect);
                }
            }
            return(privateGeometry);
        }
コード例 #10
0
 // line over polygon = 1D
 // polygon over polygon = 2D
 public CalculateCountyPrivateCommand(ITopologicalOperator4 whole, ServerLogger logger)
 {
     _whole  = whole;
     _logger = logger;
 }
コード例 #11
0
 // line over polygon = 1D
 // polygon over polygon = 2D
 public CalculateIntersectionCommand(ITopologicalOperator4 whole, ServerLogger logger)
 {
     _whole  = whole;
     _logger = logger;
 }
コード例 #12
0
        private List <IGeometry> splitGeometry(IGeometry geo, bool mergePolys)
        {
            IGeometry geoM = null;

            if (mergePolys)
            {
                geoM = mergeSmallGeos(geo);
            }
            else
            {
                geoM = geo;
            }
            List <IGeometry>    geoLst  = new List <IGeometry>();
            IPolygon4           poly4   = (IPolygon4)geoM;
            IGeometryCollection geoColl = (IGeometryCollection)poly4.ConnectedComponentBag;

            for (int i = 0; i < geoColl.GeometryCount; i++)
            {
                IGeometry geo2 = geoColl.get_Geometry(i);
                IEnvelope env = geo2.Envelope;
                double    xmax = env.XMax;
                double    xmin = env.XMin;
                double    ymax = env.YMax;
                double    ymin = env.YMin;
                double    xRange = xmax - xmin;
                double    yRange = ymax - ymin;
                double    nMinX, nMinY, nMaxX, nMaxY;
                if (xRange > yRange)
                {
                    nMinY = ymin - 1;
                    nMaxY = ymax + 1;
                    nMinX = xmin + (xRange / 2);
                    nMaxX = nMinX;
                }
                else
                {
                    nMinX = xmin - 1;
                    nMaxX = xmax + 1;
                    nMinY = ymin + (yRange / 2);
                    nMaxY = nMinY;
                }
                WKSPoint[]        wksPoint         = new WKSPoint[2];
                IPointCollection4 pointCollection4 = new PolylineClass();
                wksPoint[0].X = nMinX;
                wksPoint[0].Y = nMinY;
                wksPoint[1].X = nMaxX;
                wksPoint[1].Y = nMaxY;
                IGeometryBridge2 geometryBridge2 = new GeometryEnvironmentClass();
                geometryBridge2.AddWKSPoints(pointCollection4, ref wksPoint);
                IPolyline polyline = pointCollection4 as ESRI.ArcGIS.Geometry.IPolyline;
                polyline.SpatialReference = geo2.SpatialReference;
                ITopologicalOperator4 tp   = (ITopologicalOperator4)geo2;
                IGeometry             geoL = null;
                IGeometry             geoR = null;
                try
                {
                    tp.Cut(polyline, out geoL, out geoR);
                    if (((IArea)geoL).Area > maxarea)
                    {
                        geoLst.AddRange(splitGeometry(geoL, false));
                    }
                    else
                    {
                        geoLst.Add(geoL);
                    }
                    if (((IArea)geoR).Area > maxarea)
                    {
                        geoLst.AddRange(splitGeometry(geoR, false));
                    }
                    else
                    {
                        geoLst.Add(geoR);
                    }
                }
                catch (Exception e)
                {
                    geoLst.Add(geo2);
                    Console.WriteLine(e.ToString());
                }
            }
            return(geoLst);
        }