Class SimpleDirectPosition
java.lang.Object
org.opengis.test.referencing.SimpleDirectPosition
- All Implemented Interfaces:
Position, DirectPosition
A trivial implementation of
DirectPosition for internal usage by
TransformTestCase. Not public because strictly reserved to tests.- Since:
- 2.2
- Version:
- 3.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSimpleDirectPosition(int dimension) Creates a new direct position of the given dimension.SimpleDirectPosition(Point2D point) Creates a new two-dimensional direct position initialized to the given point. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif this direct position is equals to the given object.double[]A copy of the ordinates presented as an array of double values.Returns alwaysnull, since it is allowed by the specification andTransformTestCasedoesn't want to test the handling of CRS.double[]Deprecated.intThe length of coordinate sequence (the number of entries).Returns the direct position.doublegetOrdinate(int dimension) Returns the ordinate at the specified dimension.inthashCode()Returns a hash code value for this direct position.voidsetOrdinate(int dimension, double value) Sets the ordinate value along the specified dimension.toString()Returns a string representation of this direct position.
-
Field Details
-
ordinates
protected final double[] ordinatesThe ordinates.
-
-
Constructor Details
-
SimpleDirectPosition
public SimpleDirectPosition(int dimension) Creates a new direct position of the given dimension.- Parameters:
dimension- The dimension.
-
SimpleDirectPosition
Creates a new two-dimensional direct position initialized to the given point.
-
-
Method Details
-
getCoordinateReferenceSystem
Returns alwaysnull, since it is allowed by the specification andTransformTestCasedoesn't want to test the handling of CRS.- Specified by:
getCoordinateReferenceSystemin interfaceDirectPosition- Returns:
- The coordinate reference system, or
null.
-
getDimension
public int getDimension()The length of coordinate sequence (the number of entries). This is determined by the coordinate reference system.- Specified by:
getDimensionin interfaceDirectPosition- Returns:
- The dimensionality of this position.
-
getCoordinate
public double[] getCoordinate()A copy of the ordinates presented as an array of double values. Please note that this is only a copy (the real values may be stored in another format) so changes to the returned array will not affect the source DirectPosition.
To manipulate ordinates, the following idiom can be used:final int dim = position.getDimension(); for (int i=0; i<dim; i++) { position.getOrdinate(i); // no copy overhead }
There are a couple reasons for requerying a copy:position.setOrdinate(i, value); // edit in place
- We want an array of coordinates with the intend to modify it for computation purpose
(without modifying the original
DirectPosition), or we want to protect the array from futureDirectPositionchanges. - If
DirectPosition.getOrdinates()is guaranteed to not return the backing array, then we can work directly on this array. If we don't have this guarantee, then we must conservatively clone the array in every cases. - Cloning the returned array is useless if the implementation cloned the array or was forced to returns a new array anyway (for example because the coordinates were computed on the fly)
Precedence is given to data integrity over
getOrdinates()performance. Performance concern can be avoided with usage ofDirectPosition.getOrdinate(int).- Specified by:
getCoordinatein interfaceDirectPosition- Returns:
- A copy of the coordinates. Changes in the returned array will not be reflected back
in this
DirectPositionobject.
- We want an array of coordinates with the intend to modify it for computation purpose
(without modifying the original
-
getCoordinates
Deprecated. -
getOrdinate
Returns the ordinate at the specified dimension.- Specified by:
getOrdinatein interfaceDirectPosition- Parameters:
dimension- The dimension in the range 0 to dimension-1.- Returns:
- The coordinate at the specified dimension.
- Throws:
IndexOutOfBoundsException- If the given index is negative or is equals or greater than the envelope dimension.
-
setOrdinate
Sets the ordinate value along the specified dimension.- Specified by:
setOrdinatein interfaceDirectPosition- Parameters:
dimension- the dimension for the ordinate of interest.value- the ordinate value of interest.- Throws:
IndexOutOfBoundsException- If the given index is negative or is equals or greater than the envelope dimension.
-
getDirectPosition
Returns the direct position. This method shall never returnsnull, but may returnsthisif invoked on an object which is already aDirectPositioninstance.- Specified by:
getDirectPositionin interfacePosition- Returns:
- The direct position (may be
this).
-
equals
Returnstrueif this direct position is equals to the given object.- Specified by:
equalsin interfaceDirectPosition- Overrides:
equalsin classObject- Parameters:
object- The object to compare with this direct position for equality.- Returns:
trueif the given object is equals to this direct position.
-
hashCode
public int hashCode()Returns a hash code value for this direct position.- Specified by:
hashCodein interfaceDirectPosition- Overrides:
hashCodein classObject- Returns:
- A hash code value for this direct position.
-
toString
-