public classPrecisionModelextendsObjectimplementsSerializable,Comparable
Coordinates in aGeometry. In other words, specifies the grid of allowable points for aGeometry. A precision model may befloating (FLOATING orFLOATING_SINGLE), in which case normal floating-point value semantics apply. For aFIXED precision model themakePrecise(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. 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.
Three types of precision model are supported:
It is also supported to specify a precisegrid size by providing it as a negative scale factor. This allows setting a precise grid size rather than using a fractional scale, which provides more accurate and robust rounding. For example, to specify rounding to the nearest 1000 use a scale factor of -1000.
Coordinates are represented internally as Java double-precision values. Java uses the IEEE-394 floating point standard, which provides 53 bits of precision. (Thus the maximum precisely representableinteger is 9,007,199,254,740,992 - or almost 16 decimal digits of precision).
| Modifier and Type | Class and Description |
|---|---|
static class | PrecisionModel.TypeThe types of Precision Model which JTS supports. |
| Modifier and Type | Field and Description |
|---|---|
staticPrecisionModel.Type | FIXEDFixed Precision indicates that coordinates have a fixed number of decimal places. |
staticPrecisionModel.Type | FLOATINGFloating precision corresponds to the standard Java double-precision floating-point representation, which is based on the IEEE-754 standard |
staticPrecisionModel.Type | FLOATING_SINGLEFloating single precision corresponds to the standard Java single-precision floating-point representation, which is based on the IEEE-754 standard |
static double | maximumPreciseValueThe 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.Type modelType)Creates a PrecisionModel that specifies an explicit precision model type. |
PrecisionModel(PrecisionModel pm)Copy constructor to create a new PrecisionModel from an existing one. |
| Modifier and Type | Method and Description |
|---|---|
int | compareTo(Object o)Compares this PrecisionModel object with the specified object for order. |
boolean | equals(Object other) |
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.Type | getType()Gets the type of this precision model |
double | gridSize()Computes the grid size for a fixed precision model. |
int | hashCode() |
boolean | isFloating()Tests whether the precision model supports floating point |
void | makePrecise(Coordinate coord)Rounds a Coordinate to the PrecisionModel grid. |
double | makePrecise(double val)Rounds a numeric value to the PrecisionModel grid. |
staticPrecisionModel | mostPrecise(PrecisionModel pm1,PrecisionModel pm2)Determines which of two PrecisionModels is the most precise (allows the greatest number of significant digits). |
Coordinate | toExternal(Coordinate internal)Deprecated. no longer needed, since internal representation is same as external representation |
void | toExternal(Coordinate internal,Coordinate external)Deprecated. no longer needed, since internal representation is same as external representation |
Coordinate | toInternal(Coordinate external)Deprecated. use makePrecise instead |
void | toInternal(Coordinate external,Coordinate internal)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 modelpublic 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 coordinateoffsetX - 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. The provided scale may be negative, to specify an exact grid size. The scale is then computed as the reciprocal.scale - amount by which to multiply a coordinate after subtracting the offset, to obtain a precise coordinate. Must be non-zero.public PrecisionModel(PrecisionModel pm)
PrecisionModel from an existing one.public static PrecisionModel mostPrecise(PrecisionModel pm1,PrecisionModel pm2)
PrecisionModels is the most precise (allows the greatest number of significant digits).pm1 - a PrecisionModelpm2 - a PrecisionModelpublic boolean isFloating()
true if the precision model supports floating pointpublic int getMaximumSignificantDigits()
WKTWriter).This method would be more correctly calledgetMinimumDecimalPlaces, 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 double gridSize()
public PrecisionModel.Type getType()
PrecisionModel.Typepublic double getOffsetX()
public double getOffsetY()
public void toInternal(Coordinate external,Coordinate internal)
internal to the precise representation ofexternal.external - the original coordinateinternal - the coordinate whose values will be changed to the precise representation ofexternalpublic Coordinate toInternal(Coordinate external)
external.external - the original coordinateexternalpublic Coordinate toExternal(Coordinate internal)
internal.internal - the original coordinateinternalpublic void toExternal(Coordinate internal,Coordinate external)
external to the external representation ofinternal.internal - the original coordinateexternal - the coordinate whose values will be changed to the external representation ofinternalpublic double makePrecise(double val)
This method has no effect on NaN values.
Note: Java'sMath#rint uses the "Banker's Rounding" algorithm, which is not suitable for precision operations elsewhere in JTS.
public void makePrecise(Coordinate coord)
public int compareTo(Object o)
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 thegetMaximumSignificantDigits() 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 Comparableo - thePrecisionModel with which thisPrecisionModel is being comparedPrecisionModel is less than, equal to, or greater than the specifiedPrecisionModelCopyright © 2024. All rights reserved.