private Polygon EditPolygon(Polygon polygon, IGeometryEdit operation) { Polygon newPolygon = (Polygon)operation.Edit(polygon, m_objFactory); if (newPolygon.IsEmpty) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return(newPolygon); } LinearRing shell = (LinearRing)Edit(newPolygon.ExteriorRing, operation); if (shell.IsEmpty) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return(m_objFactory.CreatePolygon(null, null)); } GeometryList holes = new GeometryList(); for (int i = 0; i < newPolygon.NumInteriorRings; i++) { LinearRing hole = (LinearRing)Edit(newPolygon.InteriorRing(i), operation); if (hole.IsEmpty) { continue; } holes.Add(hole); } return(m_objFactory.CreatePolygon(shell, holes.ToLinearRingArray())); }
/// <summary> /// Edit the input <see cref="Geometry"/> with the given edit operation. /// Clients will create subclasses of <see cref="IGeometryEdit"/> or /// <see cref="CoordinateGeometryEdit"/> 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 Geometry which is the result of the editing.</returns> public virtual Geometry Edit(Geometry geometry, IGeometryEdit operation) { if (geometry == null) { throw new ArgumentNullException("geometry"); } if (operation == null) { throw new ArgumentNullException("operation"); } // if client did not supply a GeometryFactory, use the one from the input Geometry if (m_objFactory == null) { m_objFactory = geometry.Factory; } GeometryType geomType = geometry.GeometryType; if (geomType == GeometryType.GeometryCollection) { return(EditGeometryCollection((GeometryCollection)geometry, operation)); } if (geomType == GeometryType.Polygon) { return(EditPolygon((Polygon)geometry, operation)); } if (geomType == GeometryType.Point) { return(operation.Edit(geometry, m_objFactory)); } if (geomType == GeometryType.LineString || geomType == GeometryType.LinearRing) { return(operation.Edit(geometry, m_objFactory)); } Debug.Assert(false, "Should never reach here: Unsupported Geometry classes should be caught in the IGeometryEdit."); return(null); }
private GeometryCollection EditGeometryCollection(GeometryCollection collection, IGeometryEdit operation) { GeometryCollection newCollection = (GeometryCollection)operation.Edit(collection, m_objFactory); GeometryList geometries = new GeometryList(); for (int i = 0; i < newCollection.NumGeometries; i++) { Geometry geometry = Edit(newCollection.GetGeometry(i), operation); if (geometry.IsEmpty) { continue; } geometries.Add(geometry); } GeometryType geomType = newCollection.GeometryType; if (geomType == GeometryType.MultiPoint) { return(m_objFactory.CreateMultiPoint(geometries.ToPointArray())); } if (geomType == GeometryType.MultiLineString) { return(m_objFactory.CreateMultiLineString( geometries.ToLineStringArray())); } if (geomType == GeometryType.MultiPolygon) { return(m_objFactory.CreateMultiPolygon(geometries.ToPolygonArray())); } return(m_objFactory.CreateGeometryCollection(geometries.ToArray())); }