示例#1
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);
        }
示例#2
0
        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);
        }
示例#3
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);
        }