public class PrecisionModel extends Objectimplements Serializable , Comparable
Coordinates in a
Geometry. In other words, specifies the grid of allowable points for all
Geometrys.
The makePrecise(Coordinate) method allows rounding a coordinate to a "precise" value; that is, one whose precision is known exactly.
Coordinates are assumed to be precise in geometries. That is, the coordinates are assumed to be rounded to the precision model given for the geometry. JTS input routines automatically round coordinates to the precision model before creating Geometries. All internal operations assume that coordinates are rounded to the precision model. Constructive methods (such as boolean operations) always round computed coordinates to the appropriate precision model.
Currently three types of precision model are supported:
Coordinates are represented internally as Java double-precision values. Since Java uses the IEEE-394 floating point standard, this provides 53 bits of precision. (Thus the maximum precisely representable integer is 9,007,199,254,740,992).
JTS methods currently do not handle inputs with different precision models.
| Modifier and Type | Class and Description |
|---|---|
static class |
PrecisionModel
The types of Precision Model which JTS supports.
|
| Modifier and Type | Field and Description |
|---|---|
static PrecisionModel |
FIXED
Fixed Precision indicates that coordinates have a fixed number of decimal places.
|
static PrecisionModel |
FLOATING
Floating precision corresponds to the standard Java double-precision floating-point representation, which is based on the IEEE-754 standard
|
static PrecisionModel |
FLOATING_SINGLE
Floating single precision corresponds to the standard Java single-precision floating-point representation, which is based on the IEEE-754 standard
|
static double |
maximumPreciseValue
The maximum precise value representable in a double.
|
| Constructor and Description |
|---|
PrecisionModel()
Creates a
PrecisionModel with a default precision of FLOATING.
|
PrecisionModel(double scale)
Creates a
PrecisionModel that specifies Fixed precision.
|
PrecisionModel(double scale, double offsetX, double offsetY)
Deprecated.
offsets are no longer supported, since internal representation is rounded floating point
|
PrecisionModel(PrecisionModel
Creates a
PrecisionModel that specifies an explicit precision model type.
|
PrecisionModel(PrecisionModel
Copy constructor to create a new
PrecisionModel from an existing one.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Object
Compares this
PrecisionModel object with the specified object for order.
|
boolean |
equals(Object
|
int |
getMaximumSignificantDigits()
Returns the maximum number of significant digits provided by this precision model.
|
double |
getOffsetX()
Deprecated.
Offsets are no longer used
|
double |
getOffsetY()
Deprecated.
Offsets are no longer used
|
double |
getScale()
Returns the scale factor used to specify a fixed precision model.
|
PrecisionModel |
getType()
Gets the type of this precision model
|
boolean |
isFloating()
Tests whether the precision model supports floating point
|
void |
makePrecise(Coordinate
Rounds a Coordinate to the PrecisionModel grid.
|
double |
makePrecise(double val)
Rounds a numeric value to the PrecisionModel grid.
|
static PrecisionModel |
mostPrecise(PrecisionModel
Determines which of two
PrecisionModels is the most precise (allows the greatest number of significant digits).
|
Coordinate |
toExternal(Coordinate
Deprecated.
no longer needed, since internal representation is same as external representation
|
void |
toExternal(Coordinate
Deprecated.
no longer needed, since internal representation is same as external representation
|
Coordinate |
toInternal(Coordinate
Deprecated.
use makePrecise instead
|
void |
toInternal(Coordinate
Deprecated.
use makePrecise instead
|
String |
toString()
|
public static final PrecisionModel.Type FIXED
public static final PrecisionModel.Type FLOATING
public static final PrecisionModel.Type FLOATING_SINGLE
public static final double maximumPreciseValue
public PrecisionModel()
PrecisionModel with a default precision of FLOATING.
public PrecisionModel(PrecisionModel.Type modelType)
PrecisionModel that specifies an explicit precision model type. If the model type is FIXED the scale factor will default to 1.
modelType - the type of the precision model
public PrecisionModel(double scale,
double offsetX,
double offsetY)
PrecisionModel that specifies Fixed precision. Fixed-precision coordinates are represented as precise internal coordinates, which are rounded to the grid defined by the scale factor.
scale - amount by which to multiply a coordinate after subtracting the offset, to obtain a precise coordinate
offsetX - not used.
offsetY - not used.
public PrecisionModel(double scale)
PrecisionModel that specifies Fixed precision. Fixed-precision coordinates are represented as precise internal coordinates, which are rounded to the grid defined by the scale factor.
scale - amount by which to multiply a coordinate after subtracting the offset, to obtain a precise coordinate
public PrecisionModel(PrecisionModelpm)
PrecisionModel from an existing one.
public static PrecisionModelmostPrecise(PrecisionModel pm1, PrecisionModel pm2)
PrecisionModels is the most precise (allows the greatest number of significant digits).
pm1 - a PrecisionModel
pm2 - a PrecisionModel
public boolean isFloating()
true if the precision model supports floating point
public int getMaximumSignificantDigits()
WKTWriter).
This method would be more correctly called getMinimumDecimalPlaces, since it actually computes the number of decimal places that is required to correctly display the full precision of an ordinate value.
Since it is difficult to compute the required number of decimal places for scale factors which are not powers of 10, the algorithm uses a very rough approximation in this case. This has the side effect that for scale factors which are powers of 10 the value returned is 1 greater than the true value.
public double getScale()
public PrecisionModel.Type getType()
PrecisionModel.Type
public double getOffsetX()
public double getOffsetY()
public void toInternal(Coordinateexternal, Coordinate internal)
internal to the precise representation of
external.
external - the original coordinate
internal - the coordinate whose values will be changed to the precise representation of
external
public CoordinatetoInternal(Coordinate external)
external.
external - the original coordinate
external
public CoordinatetoExternal(Coordinate internal)
internal.
internal - the original coordinate
internal
public void toExternal(Coordinateinternal, Coordinate external)
external to the external representation of
internal.
internal - the original coordinate
external - the coordinate whose values will be changed to the external representation of
internal
public double makePrecise(double val)
This method has no effect on NaN values.
Note: Java's Math#rint uses the "Banker's Rounding" algorithm, which is not suitable for precision operations elsewhere in JTS.
public void makePrecise(Coordinatecoord)
public StringtoString()
public boolean equals(Objectother)
public int compareTo(Objecto)
PrecisionModel object with the specified object for order. A PrecisionModel is greater than another if it provides greater precision. The comparison is based on the value returned by the
getMaximumSignificantDigits() method. This comparison is not strictly accurate when comparing floating precision models to fixed models; however, it is correct when both models are either floating or fixed.
compareTo in interface
Comparable
o - the
PrecisionModel with which this
PrecisionModel is being compared
PrecisionModel is less than, equal to, or greater than the specified
PrecisionModel