コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private IPolygon EditPolygon(IPolygon polygon, GeometryEditorOperation operation)
        {
            IPolygon newPolygon = (IPolygon)operation.Edit(polygon, factory);

            if (newPolygon.IsEmpty)
            {
                //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
                return(newPolygon);
            }

            ILinearRing shell = (ILinearRing)Edit(newPolygon.ExteriorRing, operation);

            if (shell.IsEmpty)
            {
                //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
                return(factory.CreatePolygon(null, null));
            }

            ArrayList holes = new ArrayList();

            for (int i = 0; i < newPolygon.NumInteriorRings; i++)
            {
                ILinearRing hole = (ILinearRing)Edit(newPolygon.GetInteriorRingN(i), operation);
                if (hole.IsEmpty)
                {
                    continue;
                }
                holes.Add(hole);
            }

            return(factory.CreatePolygon(shell, (ILinearRing[])holes.ToArray(typeof(ILinearRing))));
        }
コード例 #2
0
 /// <summary>
 /// Edit the input <c>Geometry</c> with the given edit operation.
 /// Clients will create subclasses of GeometryEditorOperation or
 /// CoordinateOperation to perform required modifications.
 /// </summary>
 /// <param name="geometry">The Geometry to edit.</param>
 /// <param name="operation">The edit operation to carry out.</param>
 /// <returns>A new <c>Geometry</c> which is the result of the editing.</returns>
 public IGeometry Edit(IGeometry geometry, GeometryEditorOperation operation)
 {
     // if client did not supply a GeometryFactory, use the one from the input Geometry
     if (factory == null)
     {
         factory = geometry.Factory;
     }
     if (geometry is IGeometryCollection)
     {
         return(EditGeometryCollection((IGeometryCollection)geometry, operation));
     }
     if (geometry is IPolygon)
     {
         return(EditPolygon((IPolygon)geometry, operation));
     }
     if (geometry is IPoint)
     {
         return(operation.Edit(geometry, factory));
     }
     if (geometry is ILineString)
     {
         return(operation.Edit(geometry, factory));
     }
     Assert.ShouldNeverReachHere("Unsupported Geometry classes should be caught in the GeometryEditorOperation.");
     return(null);
 }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private IGeometryCollection EditGeometryCollection(GeometryCollection collection,
                                                           GeometryEditorOperation operation)
        {
            GeometryCollection newCollection = (GeometryCollection)operation.Edit(collection, factory);
            ArrayList          geometries    = new ArrayList();

            for (int i = 0; i < newCollection.NumGeometries; i++)
            {
                IGeometry geometry = Edit(newCollection.GetGeometryN(i), operation);
                if (geometry.IsEmpty)
                {
                    continue;
                }
                geometries.Add(geometry);
            }

            if (newCollection is MultiPoint)
            {
                return(factory.CreateMultiPoint((Point[])geometries.ToArray(typeof(Point))));
            }

            if (newCollection is MultiLineString)
            {
                return(factory.CreateMultiLineString((LineString[])geometries.ToArray(typeof(LineString))));
            }

            if (newCollection is MultiPolygon)
            {
                return(factory.CreateMultiPolygon((Polygon[])geometries.ToArray(typeof(Polygon))));
            }

            return(factory.CreateGeometryCollection((Geometry[])geometries.ToArray(typeof(Geometry))));
        }
コード例 #4
0
 /// <summary> 
 /// Edit the input <c>Geometry</c> with the given edit operation.
 /// Clients will create subclasses of GeometryEditorOperation or
 /// CoordinateOperation to perform required modifications.
 /// </summary>
 /// <param name="geometry">The Geometry to edit.</param>
 /// <param name="operation">The edit operation to carry out.</param>
 /// <returns>A new <c>Geometry</c> which is the result of the editing.</returns>
 public IGeometry Edit(IGeometry geometry, GeometryEditorOperation operation)
 {
     // if client did not supply a GeometryFactory, use the one from the input Geometry
     if (factory == null)
         factory = geometry.Factory;
     if (geometry is IGeometryCollection) 
         return EditGeometryCollection((IGeometryCollection) geometry, operation);
     if (geometry is IPolygon)
         return EditPolygon((IPolygon) geometry, operation);
     if (geometry is IPoint) 
         return operation.Edit(geometry, factory);
     if (geometry is ILineString) 
         return operation.Edit(geometry, factory);
     Assert.ShouldNeverReachHere("Unsupported Geometry classes should be caught in the GeometryEditorOperation.");
     return null;
 }
コード例 #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="polygon"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private IPolygon EditPolygon(IPolygon polygon, GeometryEditorOperation operation) 
        {
            IPolygon newPolygon = (IPolygon) operation.Edit(polygon, factory);
            if (newPolygon.IsEmpty) 
                //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
                return newPolygon;

            ILinearRing shell = (ILinearRing) Edit(newPolygon.ExteriorRing, operation);
            if (shell.IsEmpty) 
                //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino]
                return factory.CreatePolygon(null, null);

            ArrayList holes = new ArrayList();
            for (int i = 0; i < newPolygon.NumInteriorRings; i++) 
            {
                ILinearRing hole = (ILinearRing) Edit(newPolygon.GetInteriorRingN(i), operation);
                if (hole.IsEmpty) continue;
                holes.Add(hole);
            }

            return factory.CreatePolygon(shell, (ILinearRing[]) holes.ToArray(typeof(ILinearRing)));
        }
コード例 #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private IGeometryCollection EditGeometryCollection(IGeometryCollection collection, GeometryEditorOperation operation)
        {
            IGeometryCollection newCollection = (IGeometryCollection) operation.Edit(collection, factory);
            ArrayList geometries = new ArrayList();
            for (int i = 0; i < newCollection.NumGeometries; i++) 
            {
                IGeometry geometry = Edit(newCollection.GetGeometryN(i), operation);
                if (geometry.IsEmpty)  continue;
                geometries.Add(geometry);
            }

            if (newCollection is IMultiPoint) 
                return factory.CreateMultiPoint((IPoint[]) geometries.ToArray(typeof(IPoint)));

            if (newCollection is IMultiLineString) 
                return factory.CreateMultiLineString((ILineString[]) geometries.ToArray(typeof(ILineString)));

            if (newCollection is IMultiPolygon)
                return factory.CreateMultiPolygon((IPolygon[]) geometries.ToArray(typeof(IPolygon)));

            return factory.CreateGeometryCollection((IGeometry[]) geometries.ToArray(typeof(IGeometry)));
        }