Class PackedCoordinateSequence
java.lang.Object
org.locationtech.jts.geom.impl.PackedCoordinateSequence
- All Implemented Interfaces:
Serializable, Cloneable, CoordinateSequence
- Direct Known Subclasses:
PackedCoordinateSequence.Double, PackedCoordinateSequence.Float
public abstract class PackedCoordinateSequence
extends Object
implements CoordinateSequence, Serializable
A
CoordinateSequence implementation based on a packed arrays.
In this implementation, Coordinates 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classPacked coordinate sequence implementation based on doublesstatic classPacked coordinate sequence implementation based on floats -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SoftReference<Coordinate[]> A soft reference to the Coordinate[] representation of this sequence.protected intThe dimensions of the coordinates held in the packed arrayprotected intThe number of measures of the coordinates held in the packed array.Fields inherited from interface CoordinateSequence
M, X, Y, Z -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPackedCoordinateSequence(int dimension, int measures) Creates an instance of this class -
Method Summary
Modifier and TypeMethodDescriptionabstract Objectclone()Deprecated.abstract PackedCoordinateSequencecopy()Returns a deep copy of this collection.getCoordinate(int i) Returns (possibly a copy of) the i'th coordinate in this sequence.voidgetCoordinate(int i, Coordinate coord) Copies the i'th coordinate in the sequence to the suppliedCoordinate.getCoordinateCopy(int i) Returns a copy of the i'th coordinate in this sequence.protected abstract CoordinategetCoordinateInternal(int index) Returns a Coordinate representation of the specified coordinate, by always building a new Coordinate objectintReturns the dimension (number of ordinates in each coordinate) for this sequence.intReturns the number of measures included inCoordinateSequence.getDimension()for each coordinate for this sequence.abstract doublegetOrdinate(int index, int ordinateIndex) Returns the ordinate of a coordinate in this sequence.doublegetX(int index) Returns ordinate X (0) of the specified coordinate.doublegetY(int index) Returns ordinate Y (1) of the specified coordinate.protected Objectabstract voidsetOrdinate(int index, int ordinate, double value) Sets the ordinate of a coordinate in this sequence.voidsetX(int index, double value) Sets the first ordinate of a coordinate in this sequence.voidsetY(int index, double value) Sets the second ordinate of a coordinate in this sequence.Returns (possibly copies of) the Coordinates in this collection.toString()Methods inherited from class Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CoordinateSequence
createCoordinate, expandEnvelope, getM, getZ, hasM, hasZ, size
-
Field Details
-
dimension
protected int dimensionThe dimensions of the coordinates held in the packed array -
measures
protected int measuresThe number of measures of the coordinates held in the packed array. -
coordRef
A soft reference to the Coordinate[] representation of this sequence. Makes repeated coordinate array accesses more efficient.
-
-
Constructor Details
-
PackedCoordinateSequence
protected PackedCoordinateSequence(int dimension, int measures) Creates an instance of this class- Parameters:
dimension- the total number of ordinates that make up aCoordinatein this sequence.measures- the number of measure-ordinates eachCoordinatein this sequence has.
-
-
Method Details
-
getDimension
public int getDimension()Description copied from interface:CoordinateSequenceReturns the dimension (number of ordinates in each coordinate) for this sequence.This total includes any measures, indicated by non-zero
CoordinateSequence.getMeasures().- Specified by:
getDimensionin interfaceCoordinateSequence- Returns:
- the dimension of the sequence.
- See Also:
-
getMeasures
public int getMeasures()Description copied from interface:CoordinateSequenceReturns the number of measures included inCoordinateSequence.getDimension()for each coordinate for this sequence. For a measured coordinate sequence a non-zero value is returned.- For XY sequence measures is zero
- For XYM sequence measure is one
- For XYZ sequence measure is zero
- For XYZM sequence measure is one
- Values greater than one are supported
- Specified by:
getMeasuresin interfaceCoordinateSequence- Returns:
- the number of measures included in dimension
- See Also:
-
getCoordinate
Description copied from interface:CoordinateSequenceReturns (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:
getCoordinatein interfaceCoordinateSequence- Parameters:
i- the index of the coordinate to retrieve- Returns:
- the i'th coordinate in the sequence
- See Also:
-
getCoordinateCopy
Description copied from interface:CoordinateSequenceReturns 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:
getCoordinateCopyin interfaceCoordinateSequence- Parameters:
i- the index of the coordinate to retrieve- Returns:
- a copy of the i'th coordinate in the sequence
- See Also:
-
getCoordinate
Description copied from interface:CoordinateSequenceCopies the i'th coordinate in the sequence to the suppliedCoordinate. Only the first two dimensions are copied.- Specified by:
getCoordinatein interfaceCoordinateSequence- Parameters:
i- the index of the coordinate to copycoord- aCoordinateto receive the value- See Also:
-
toCoordinateArray
Description copied from interface:CoordinateSequenceReturns (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:
toCoordinateArrayin interfaceCoordinateSequence- Returns:
- a array of coordinates containing the point values in this sequence
- See Also:
-
getX
public double getX(int index) Description copied from interface:CoordinateSequenceReturns ordinate X (0) of the specified coordinate.- Specified by:
getXin interfaceCoordinateSequence- Parameters:
index- the coordinate index in the sequence- Returns:
- the value of the X ordinate in the index'th coordinate
- See Also:
-
getY
public double getY(int index) Description copied from interface:CoordinateSequenceReturns ordinate Y (1) of the specified coordinate.- Specified by:
getYin interfaceCoordinateSequence- Parameters:
index- the coordinate index in the sequence- Returns:
- the value of the Y ordinate in the index'th coordinate
- See Also:
-
getOrdinate
public abstract double getOrdinate(int index, int ordinateIndex) Description copied from interface:CoordinateSequenceReturns 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 as described by
CoordinateSequence.getDimension()andCoordinateSequence.getMeasures()).- Specified by:
getOrdinatein interfaceCoordinateSequence- Parameters:
index- the coordinate index in the sequenceordinateIndex- the ordinate index in the coordinate (in range [0, dimension-1])- Returns:
- ordinate value
- See Also:
-
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
-
readResolve
- Throws:
ObjectStreamException
-
getCoordinateInternal
Returns a Coordinate representation of the specified coordinate, by always building a new Coordinate object- Parameters:
index- the coordinate index- Returns:
- the
Coordinateat the given index
-
clone
Deprecated.Description copied from interface:CoordinateSequenceReturns a deep copy of this collection. Called by Geometry#clone.- Specified by:
clonein interfaceCoordinateSequence- Overrides:
clonein classObject- Returns:
- a copy of the coordinate sequence containing copies of all points
- See Also:
-
copy
Description copied from interface:CoordinateSequenceReturns a deep copy of this collection.- Specified by:
copyin 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:
setOrdinatein interfaceCoordinateSequence- Parameters:
index- the coordinate indexordinate- the ordinate index in the coordinate, 0 based, smaller than the number of dimensionsvalue- the new ordinate value
-