Package org.locationtech.jts.geom.impl
Class PackedCoordinateSequence
- java.lang.Object
-
- org.locationtech.jts.geom.impl.PackedCoordinateSequence
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,CoordinateSequence
- Direct Known Subclasses:
PackedCoordinateSequence.Double
,PackedCoordinateSequence.Float
public abstract class PackedCoordinateSequence extends java.lang.Object implements CoordinateSequence, java.io.Serializable
ACoordinateSequence
implementation based on a packed arrays. In this implementation,Coordinate
s returned by #toArray and #get are copies of the internal values. To change the actual values, use the provided setters.For efficiency, created Coordinate arrays are cached using a soft reference. The cache is cleared each time the coordinate sequence contents are modified through a setter method.
- Version:
- 1.7
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PackedCoordinateSequence.Double
Packed coordinate sequence implementation based on doublesstatic class
PackedCoordinateSequence.Float
Packed coordinate sequence implementation based on floats
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ref.SoftReference
coordRef
A soft reference to the Coordinate[] representation of this sequence.protected int
dimension
The dimensions of the coordinates hold in the packed arrayprivate static long
serialVersionUID
-
Fields inherited from interface org.locationtech.jts.geom.CoordinateSequence
M, X, Y, Z
-
-
Constructor Summary
Constructors Constructor Description PackedCoordinateSequence()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract java.lang.Object
clone()
Deprecated.abstract PackedCoordinateSequence
copy()
Returns a deep copy of this collection.private Coordinate[]
getCachedCoords()
Coordinate
getCoordinate(int i)
Returns (possibly a copy of) the i'th coordinate in this sequence.void
getCoordinate(int i, Coordinate coord)
Copies the i'th coordinate in the sequence to the suppliedCoordinate
.Coordinate
getCoordinateCopy(int i)
Returns a copy of the i'th coordinate in this sequence.protected abstract Coordinate
getCoordinateInternal(int index)
Returns a Coordinate representation of the specified coordinate, by always building a new Coordinate objectint
getDimension()
Returns the dimension (number of ordinates in each coordinate) for this sequence.abstract double
getOrdinate(int index, int ordinateIndex)
Returns the ordinate of a coordinate in this sequence.double
getX(int index)
Returns ordinate X (0) of the specified coordinate.double
getY(int index)
Returns ordinate Y (1) of the specified coordinate.protected java.lang.Object
readResolve()
abstract void
setOrdinate(int index, int ordinate, double value)
Sets the ordinate of a coordinate in this sequence.void
setX(int index, double value)
Sets the first ordinate of a coordinate in this sequence.void
setY(int index, double value)
Sets the second ordinate of a coordinate in this sequence.Coordinate[]
toCoordinateArray()
Returns (possibly copies of) the Coordinates in this collection.java.lang.String
toString()
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.locationtech.jts.geom.CoordinateSequence
expandEnvelope, size
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
dimension
protected int dimension
The dimensions of the coordinates hold in the packed array
-
coordRef
protected transient java.lang.ref.SoftReference coordRef
A soft reference to the Coordinate[] representation of this sequence. Makes repeated coordinate array accesses more efficient.
-
-
Method Detail
-
getDimension
public int getDimension()
Description copied from interface:CoordinateSequence
Returns the dimension (number of ordinates in each coordinate) for this sequence.- Specified by:
getDimension
in interfaceCoordinateSequence
- Returns:
- the dimension of the sequence.
- See Also:
CoordinateSequence.getDimension()
-
getCoordinate
public Coordinate getCoordinate(int i)
Description copied from interface:CoordinateSequence
Returns (possibly a copy of) the i'th coordinate in this sequence. Whether or not the Coordinate returned is the actual underlying Coordinate or merely a copy depends on the implementation.Note that in the future the semantics of this method may change to guarantee that the Coordinate returned is always a copy. Callers should not to assume that they can modify a CoordinateSequence by modifying the object returned by this method.
- Specified by:
getCoordinate
in interfaceCoordinateSequence
- Parameters:
i
- the index of the coordinate to retrieve- Returns:
- the i'th coordinate in the sequence
- See Also:
CoordinateSequence.getCoordinate(int)
-
getCoordinateCopy
public Coordinate getCoordinateCopy(int i)
Description copied from interface:CoordinateSequence
Returns a copy of the i'th coordinate in this sequence. This method optimizes the situation where the caller is going to make a copy anyway - if the implementation has already created a new Coordinate object, no further copy is needed.- Specified by:
getCoordinateCopy
in interfaceCoordinateSequence
- Parameters:
i
- the index of the coordinate to retrieve- Returns:
- a copy of the i'th coordinate in the sequence
- See Also:
CoordinateSequence.getCoordinate(int)
-
getCoordinate
public void getCoordinate(int i, Coordinate coord)
Description copied from interface:CoordinateSequence
Copies the i'th coordinate in the sequence to the suppliedCoordinate
. Only the first two dimensions are copied.- Specified by:
getCoordinate
in interfaceCoordinateSequence
- Parameters:
i
- the index of the coordinate to copycoord
- aCoordinate
to receive the value- See Also:
CoordinateSequence.getCoordinate(int)
-
toCoordinateArray
public Coordinate[] toCoordinateArray()
Description copied from interface:CoordinateSequence
Returns (possibly copies of) the Coordinates in this collection. Whether or not the Coordinates returned are the actual underlying Coordinates or merely copies depends on the implementation. Note that if this implementation does not store its data as an array of Coordinates, this method will incur a performance penalty because the array needs to be built from scratch.- Specified by:
toCoordinateArray
in interfaceCoordinateSequence
- Returns:
- a array of coordinates containing the point values in this sequence
- See Also:
CoordinateSequence.toCoordinateArray()
-
getCachedCoords
private Coordinate[] getCachedCoords()
- Returns:
-
getX
public double getX(int index)
Description copied from interface:CoordinateSequence
Returns ordinate X (0) of the specified coordinate.- Specified by:
getX
in interfaceCoordinateSequence
- Returns:
- the value of the X ordinate in the index'th coordinate
- See Also:
CoordinateSequence.getX(int)
-
getY
public double getY(int index)
Description copied from interface:CoordinateSequence
Returns ordinate Y (1) of the specified coordinate.- Specified by:
getY
in interfaceCoordinateSequence
- Returns:
- the value of the Y ordinate in the index'th coordinate
- See Also:
CoordinateSequence.getY(int)
-
getOrdinate
public abstract double getOrdinate(int index, int ordinateIndex)
Description copied from interface:CoordinateSequence
Returns the ordinate of a coordinate in this sequence. Ordinate indices 0 and 1 are assumed to be X and Y. Ordinates indices greater than 1 have user-defined semantics (for instance, they may contain other dimensions or measure values).- Specified by:
getOrdinate
in interfaceCoordinateSequence
- Parameters:
index
- the coordinate index in the sequenceordinateIndex
- the ordinate index in the coordinate (in range [0, dimension-1])- See Also:
CoordinateSequence.getOrdinate(int, int)
-
setX
public void setX(int index, double value)
Sets the first ordinate of a coordinate in this sequence.- Parameters:
index
- the coordinate indexvalue
- the new ordinate value
-
setY
public void setY(int index, double value)
Sets the second ordinate of a coordinate in this sequence.- Parameters:
index
- the coordinate indexvalue
- the new ordinate value
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
readResolve
protected java.lang.Object readResolve() throws java.io.ObjectStreamException
- Throws:
java.io.ObjectStreamException
-
getCoordinateInternal
protected abstract Coordinate getCoordinateInternal(int index)
Returns a Coordinate representation of the specified coordinate, by always building a new Coordinate object- Parameters:
index
-- Returns:
-
clone
public abstract java.lang.Object clone()
Deprecated.Description copied from interface:CoordinateSequence
Returns a deep copy of this collection. Called by Geometry#clone.- Specified by:
clone
in interfaceCoordinateSequence
- Overrides:
clone
in classjava.lang.Object
- Returns:
- a copy of the coordinate sequence containing copies of all points
- See Also:
Object.clone()
-
copy
public abstract PackedCoordinateSequence copy()
Description copied from interface:CoordinateSequence
Returns a deep copy of this collection.- Specified by:
copy
in interfaceCoordinateSequence
- Returns:
- a copy of the coordinate sequence containing copies of all points
-
setOrdinate
public abstract void setOrdinate(int index, int ordinate, double value)
Sets the ordinate of a coordinate in this sequence.
Warning: for performance reasons the ordinate index is not checked - if it is over dimensions you may not get an exception but a meaningless value.- Specified by:
setOrdinate
in interfaceCoordinateSequence
- Parameters:
index
- the coordinate indexordinate
- the ordinate index in the coordinate, 0 based, smaller than the number of dimensionsvalue
- the new ordinate value
-
-