コード例 #1
0
        public IntersectionPart Execute(IFeature other)
        {
            const string methodName = "CalculateIntersectionCommand";

            IGeometry intersection;
            var       part = new IntersectionPart();

            switch (other.ShapeCopy.GeometryType)
            {
            case esriGeometryType.esriGeometryPolygon:
                intersection = _whole.Intersect(other.ShapeCopy, esriGeometryDimension.esriGeometry2Dimension);

                var area = (IArea)intersection;
                part.Size         = Math.Abs(area.Area);
                part.Intersection = intersection;
#if !DEBUG
                _logger.LogMessage(ServerLogger.msgType.infoStandard, methodName, MessageCode, string.Format("Area: {0}", area.Area));
#endif
                break;

            case esriGeometryType.esriGeometryPolyline:
                intersection = _whole.Intersect(other.ShapeCopy, esriGeometryDimension.esriGeometry1Dimension);

                var length = (IPolyline5)intersection;
                part.Size         = Math.Abs(length.Length);
                part.Intersection = intersection;
#if !DEBUG
                _logger.LogMessage(ServerLogger.msgType.infoStandard, methodName, MessageCode, string.Format("Length: {0}", length.Length));
#endif
                break;
            }

            return(part);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }