/// <summary> /// Normalizes a <c>LineString</c>. A normalized <c>LineString</c> /// has the first point which is not equal to it's reflected point /// less than the reflected point. /// </summary> public override void Normalize() { for (int i = 0; i < _points.Count / 2; i++) { int j = _points.Count - 1 - i; // skip equal points on both ends if (!_points.GetCoordinate(i).Equals(_points.GetCoordinate(j))) { if (_points.GetCoordinate(i).CompareTo(_points.GetCoordinate(j)) > 0) { var copy = _points.Copy(); CoordinateSequences.Reverse(copy); _points = copy; } return; } } }
/// <summary> /// Creates a <c>LinearRing</c> using the given <c>CoordinateSequence</c>; a null or empty CoordinateSequence /// creates an empty LinearRing. The points must form a closed and simple /// linestring. Consecutive points must not be equal. /// </summary> /// <param name="coordinates">A CoordinateSequence (possibly empty), or null.</param> /// <returns>A <see cref="LinearRing"/> object</returns> /// <exception cref="ArgumentException"> If the ring is not closed, or has too few points</exception> public virtual LinearRing CreateLinearRing(CoordinateSequence coordinates) { return(new LinearRing(coordinates, this)); }
/// <summary> /// Constructs a <c>Polygon</c> with the given exterior boundary. /// </summary> /// <param name="coordinates">the outer boundary of the new <c>Polygon</c>, or /// <c>null</c> or an empty <c>LinearRing</c> if /// the empty geometry is to be created.</param> /// <returns>A <see cref="Polygon"/> object</returns> /// <exception cref="ArgumentException">If the boundary ring is invalid</exception> public virtual Polygon CreatePolygon(CoordinateSequence coordinates) { return(CreatePolygon(CreateLinearRing(coordinates))); }
/// <summary> /// Shifts the positions of the coordinates until the coordinate at <code>firstCoordinateIndex</code> /// is first. /// </summary> /// <param name="seq">The coordinate sequence to rearrange</param> /// <param name="indexOfFirstCoordinate">The index of the coordinate to make first</param> public static void Scroll(CoordinateSequence seq, int indexOfFirstCoordinate) { Scroll(seq, indexOfFirstCoordinate, IsRing(seq)); }
/// <summary> /// Creates a <c>Point</c> using the given <c>CoordinateSequence</c>; a null or empty /// CoordinateSequence will create an empty Point. /// </summary> /// <param name="coordinates">a CoordinateSequence (possibly empty), or null</param> /// <returns>A <see cref="Point"/> object</returns> public virtual Point CreatePoint(CoordinateSequence coordinates) { return(new Point(coordinates, this)); }
private static CoordinateSequence CreateClosedRing(CoordinateSequenceFactory fact, CoordinateSequence seq, int size) { var newseq = fact.Create(size, seq.Dimension); int n = seq.Count; Copy(seq, 0, newseq, 0, n); // fill remaining coordinates with start point for (int i = n; i < size; i++) { Copy(seq, 0, newseq, i, 1); } return(newseq); }
/// <summary> /// Returns the index of the minimum coordinate of the whole /// coordinate sequence, using the usual lexicographic comparison. /// </summary> /// <param name="seq">The coordinate sequence to search</param> /// <param name="from">The lower search index</param> /// <param name="to">The upper search index</param> /// <returns>The index of the minimum coordinate in the sequence, found using <see cref="Coordinate.CompareTo(Coordinate)"/></returns> public static int MinCoordinateIndex(CoordinateSequence seq) { return(MinCoordinateIndex(seq, 0, seq.Count - 1)); }
/// <summary> /// Ensures that a CoordinateSequence forms a valid ring, /// returning a new closed sequence of the correct length if required. /// If the input sequence is already a valid ring, it is returned /// without modification. /// If the input sequence is too short or is not closed, /// it is extended with one or more copies of the start point. /// </summary> /// <param name="fact">The CoordinateSequenceFactory to use to create the new sequence</param> /// <param name="seq">The sequence to test</param> /// <returns>The original sequence, if it was a valid ring, or a new sequence which is valid.</returns> public static CoordinateSequence EnsureValidRing(CoordinateSequenceFactory fact, CoordinateSequence seq) { int n = seq.Count; // empty sequence is valid if (n == 0) { return(seq); } // too short - make a new one if (n <= 3) { return(CreateClosedRing(fact, seq, 4)); } bool isClosed = seq.GetOrdinate(0, 0) == seq.GetOrdinate(n - 1, 0) && seq.GetOrdinate(0, 1) == seq.GetOrdinate(n - 1, 1); if (isClosed) { return(seq); } // make a new closed ring return(CreateClosedRing(fact, seq, n + 1)); }
/// <inheritdoc/> /// <remarks> /// The <see cref="Polygon.ExteriorRing"/> is guaranteed to be orientated counter-clockwise. /// </remarks> public override Polygon CreatePolygon(CoordinateSequence coordinates) { var ring = CreateLinearRing(coordinates, true); return(base.CreatePolygon(ring)); }
public ReversedCoordinateSequence(CoordinateSequence inner) : base(inner.Count, inner.Dimension, inner.Measures) { _inner = inner; }
/// <inheritdoc cref="Geometry.CopyInternal"/>> protected override Geometry CopyInternal() { return(new LinearRing(CoordinateSequence.Copy(), Factory)); }
/// <summary> /// Constructs a <c>LinearRing</c> with the vertices specified /// by the given <see cref="CoordinateSequence"/>. /// </summary> /// <param name="points">A sequence points forming a closed and simple linestring, /// or <c>null</c> to create the empty geometry.</param> /// <param name="factory">The factory that creates this <c>LinearRing</c></param> /// <exception cref="ArgumentException">If the ring is not closed, or has too few points</exception> public LinearRing(CoordinateSequence points, GeometryFactory factory) : base(points, factory) { ValidateConstruction(); }