/// <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 virtual IGeometry Edit(IGeometry geometry, IGeometryEditorOperation operation) { // if client did not supply a GeometryFactory, use the one from the input Geometry if (_factory == null) { _factory = geometry.Factory; } if (geometry is GeometryCollection) { return(EditGeometryCollection(geometry, operation)); } if (geometry is Polygon) { return(EditPolygon(geometry, operation)); } if (geometry is Point) { return(operation.Edit(geometry, _factory)); } if (geometry is LineString) { return(operation.Edit(geometry, _factory)); } throw new UnsupportedGeometryException(); }
/// <summary> /// Edit the input <c>Geometry</c> with the given edit operation. /// Clients can 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 (which may be empty).</returns> public IGeometry Edit(IGeometry geometry, IGeometryEditorOperation 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)); } NetTopologySuite.Utilities.Assert.ShouldNeverReachHere("Unsupported Geometry classes should be caught in the GeometryEditorOperation."); return(null); }
private IGeometry EditInternal(IGeometry geometry, IGeometryEditorOperation operation) { 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); Gisoft.NetTopologySuite.Utilities.Assert.ShouldNeverReachHere("Unsupported Geometry classes should be caught in the GeometryEditorOperation."); return null; }
/// <summary> /// /// </summary> /// <param name="collection"></param> /// <param name="operation"></param> /// <returns></returns> private IGeometryCollection EditGeometryCollection(IGeometry collection, IGeometryEditorOperation 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)))); }
/// <summary> /// /// </summary> /// <param name="polygon"></param> /// <param name="operation"></param> /// <returns></returns> private IPolygon EditPolygon(IGeometry polygon, IGeometryEditorOperation operation) { Polygon newPolygon = (Polygon)operation.Edit(polygon, _factory); if (newPolygon.IsEmpty) { //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return(newPolygon); } LinearRing shell = (LinearRing)Edit(newPolygon.Shell, 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.NumHoles; i++) { LinearRing hole = (LinearRing)Edit(newPolygon.GetInteriorRingN(i), operation); if (hole.IsEmpty) { continue; } holes.Add(hole); } return(_factory.CreatePolygon(shell, (LinearRing[])holes.ToArray(typeof(LinearRing)))); }
private IGeometryCollection EditGeometryCollection(IGeometryCollection collection, IGeometryEditorOperation operation) { // first edit the entire collection // MD - not sure why this is done - could just check original collection? var collectionForType = (IGeometryCollection)operation.Edit(collection, _factory); // edit the component geometries IList<IGeometry> geometries = new List<IGeometry>(); for (var i = 0; i < collectionForType.NumGeometries; i++) { var geometry = Edit(collectionForType.GetGeometryN(i), operation); if (geometry == null || geometry.IsEmpty) continue; geometries.Add(geometry); } if (collectionForType is IMultiPoint) return _factory.CreateMultiPoint(geometries.Cast<IPoint>().ToArray()); if (collectionForType is IMultiLineString) return _factory.CreateMultiLineString(geometries.Cast<ILineString>().ToArray()); if (collectionForType is IMultiPolygon) return _factory.CreateMultiPolygon(geometries.Cast<IPolygon>().ToArray()); return _factory.CreateGeometryCollection(geometries.ToArray()); }
private IPolygon EditPolygon(IPolygon polygon, IGeometryEditorOperation operation) { var newPolygon = (IPolygon)operation.Edit(polygon, _factory); // create one if needed if (newPolygon == null) newPolygon = _factory.CreatePolygon(); if (newPolygon.IsEmpty) //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return newPolygon; var shell = (ILinearRing)Edit(newPolygon.ExteriorRing, operation); if (shell == null || shell.IsEmpty) //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return _factory.CreatePolygon(); var holes = new List<ILinearRing>(); for (var i = 0; i < newPolygon.NumInteriorRings; i++) { var hole = (ILinearRing)Edit(newPolygon.GetInteriorRingN(i), operation); if (hole == null || hole.IsEmpty) continue; holes.Add(hole); } return _factory.CreatePolygon(shell, holes.ToArray()); }
/// <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 virtual IGeometry Edit(IGeometry geometry, IGeometryEditorOperation operation) { // if client did not supply a GeometryFactory, use the one from the input Geometry if (_factory == null) _factory = geometry.Factory; if (geometry is GeometryCollection) return EditGeometryCollection(geometry, operation); if (geometry is Polygon) return EditPolygon(geometry, operation); if (geometry is Point) return operation.Edit(geometry, _factory); if (geometry is LineString) return operation.Edit(geometry, _factory); throw new UnsupportedGeometryException(); }
/// <summary> /// /// </summary> /// <param name="collection"></param> /// <param name="operation"></param> /// <returns></returns> private IGeometryCollection EditGeometryCollection(IGeometry collection, IGeometryEditorOperation 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))); }
/// <summary> /// /// </summary> /// <param name="polygon"></param> /// <param name="operation"></param> /// <returns></returns> private IPolygon EditPolygon(IGeometry polygon, IGeometryEditorOperation operation) { Polygon newPolygon = (Polygon)operation.Edit(polygon, _factory); if (newPolygon.IsEmpty) //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return newPolygon; LinearRing shell = (LinearRing)Edit(newPolygon.Shell, 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.NumHoles; i++) { LinearRing hole = (LinearRing)Edit(newPolygon.GetInteriorRingN(i), operation); if (hole.IsEmpty) continue; holes.Add(hole); } return _factory.CreatePolygon(shell, (LinearRing[])holes.ToArray(typeof(LinearRing))); }
/// <summary> /// Edit the input <c>Geometry</c> with the given edit operation. /// Clients can 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 (which may be empty).</returns> public IGeometry Edit(IGeometry geometry, IGeometryEditorOperation 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); NetTopologySuite.Utilities.Assert.ShouldNeverReachHere("Unsupported Geometry classes should be caught in the GeometryEditorOperation."); return null; }
private IGeometryCollection EditGeometryCollection(IGeometryCollection collection, IGeometryEditorOperation operation) { // first edit the entire collection // MD - not sure why this is done - could just check original collection? var collectionForType = (IGeometryCollection)operation.Edit(collection, _factory); // edit the component geometries IList<IGeometry> geometries = new List<IGeometry>(); for (var i = 0; i < collectionForType.NumGeometries; i++) { var geometry = Edit(collectionForType.GetGeometryN(i), operation); if (geometry == null || geometry.IsEmpty) continue; geometries.Add(geometry); } if (collectionForType is IMultiPoint) return _factory.CreateMultiPoint(Enumerable.ToArray(Enumerable.Cast<IPoint>(geometries))); if (collectionForType is IMultiLineString) return _factory.CreateMultiLineString(Enumerable.ToArray(Enumerable.Cast<ILineString>(geometries))); if (collectionForType is IMultiPolygon) return _factory.CreateMultiPolygon(Enumerable.ToArray(Enumerable.Cast<IPolygon>(geometries))); return _factory.CreateGeometryCollection(Enumerable.ToArray(geometries)); }
private IPolygon EditPolygon(IPolygon polygon, IGeometryEditorOperation operation) { var newPolygon = (IPolygon)operation.Edit(polygon, _factory); // create one if needed if (newPolygon == null) newPolygon = _factory.CreatePolygon((ICoordinateSequence)null); if (newPolygon.IsEmpty) //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return newPolygon; var shell = (ILinearRing)Edit(newPolygon.ExteriorRing, operation); if (shell == null || shell.IsEmpty) //RemoveSelectedPlugIn relies on this behaviour. [Jon Aquino] return _factory.CreatePolygon(null, null); var holes = new List<ILinearRing>(); for (var i = 0; i < newPolygon.NumInteriorRings; i++) { var hole = (ILinearRing)Edit(newPolygon.GetInteriorRingN(i), operation); if (hole == null || hole.IsEmpty) continue; holes.Add(hole); } return _factory.CreatePolygon(shell, holes.ToArray()); }
private IGeometry EditInternal(IGeometry geometry, IGeometryEditorOperation operation) { 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); NetTopologySuite.Utilities.Assert.ShouldNeverReachHere("Unsupported Geometry classes should be caught in the GeometryEditorOperation."); return null; }