org.geotools.geometry.iso
Class PrecisionModel

java.lang.Object
  extended by org.geotools.geometry.iso.PrecisionModel
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<org.opengis.geometry.Precision>, org.opengis.geometry.Precision

public class PrecisionModel
extends java.lang.Object
implements java.io.Serializable, org.opengis.geometry.Precision

Specifies the precision model of the Coordinates in a Geometry. In other words, specifies the grid of allowable points for all Geometrys.

The makePrecise 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.

Version:
1.7.2
See Also:
Serialized Form

Field Summary
static org.opengis.geometry.PrecisionType FIXED
          Fixed Precision indicates that coordinates have a fixed number of decimal places.
static org.opengis.geometry.PrecisionType FLOATING
          Floating precision corresponds to the standard Java double-precision floating-point representation, which is based on the IEEE-754 standard
static org.opengis.geometry.PrecisionType 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 Summary
PrecisionModel()
          Creates a PrecisionModel with a default precision of FLOATING.
PrecisionModel(double scale)
          Creates a PrecisionModel that specifies Fixed precision.
PrecisionModel(PrecisionModel pm)
          Copy constructor to create a new PrecisionModel from an existing one.
PrecisionModel(org.opengis.geometry.PrecisionType modelType)
          Creates a PrecisionModel that specifies an explicit precision model type.
 
Method Summary
 int compareTo(org.opengis.geometry.Precision precision)
           
 int compareTo(PrecisionModel other)
          Compares this PrecisionModel object with the specified object for order.
 boolean equals(java.lang.Object other)
           
 int getMaximumSignificantDigits()
          Returns the maximum number of significant digits provided by this precision model.
 double getScale()
          Returns the multiplying factor used to obtain a precise coordinate.
 org.opengis.geometry.PrecisionType getType()
          Gets the type of this PrecisionModel
 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.
 void round(org.opengis.geometry.DirectPosition position)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FIXED

public static final org.opengis.geometry.PrecisionType FIXED
Fixed Precision indicates that coordinates have a fixed number of decimal places. The number of decimal places is determined by the log10 of the scale factor.


FLOATING

public static final org.opengis.geometry.PrecisionType FLOATING
Floating precision corresponds to the standard Java double-precision floating-point representation, which is based on the IEEE-754 standard


FLOATING_SINGLE

public static final org.opengis.geometry.PrecisionType FLOATING_SINGLE
Floating single precision corresponds to the standard Java single-precision floating-point representation, which is based on the IEEE-754 standard


maximumPreciseValue

public static final double maximumPreciseValue
The maximum precise value representable in a double. Since IEE754 double-precision numbers allow 53 bits of mantissa, the value is equal to 2^53 - 1. This provides almost 16 decimal digits of precision.

See Also:
Constant Field Values
Constructor Detail

PrecisionModel

public PrecisionModel()
Creates a PrecisionModel with a default precision of FLOATING.


PrecisionModel

public PrecisionModel(org.opengis.geometry.PrecisionType modelType)
Creates a PrecisionModel that specifies an explicit precision model type. If the model type is FIXED the scale factor will default to 1.

Parameters:
modelType - the type of the precision model

PrecisionModel

public PrecisionModel(double scale)
Creates a 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.

Parameters:
scale - amount by which to multiply a coordinate after subtracting the offset, to obtain a precise coordinate

PrecisionModel

public PrecisionModel(PrecisionModel pm)
Copy constructor to create a new PrecisionModel from an existing one.

Method Detail

isFloating

public boolean isFloating()
Tests whether the precision model supports floating point

Returns:
true if the precision model supports floating point

getMaximumSignificantDigits

public int getMaximumSignificantDigits()
Returns the maximum number of significant digits provided by this precision model. Intended for use by routines which need to print out precise values.

Specified by:
getMaximumSignificantDigits in interface org.opengis.geometry.Precision
Returns:
the maximum number of decimal places provided by this precision model

getScale

public double getScale()
Returns the multiplying factor used to obtain a precise coordinate. This method is private because PrecisionModel is intended to be an immutable (value) type.

Specified by:
getScale in interface org.opengis.geometry.Precision
Returns:
the amount by which to multiply a coordinate after subtracting the offset

getType

public org.opengis.geometry.PrecisionType getType()
Gets the type of this PrecisionModel

Specified by:
getType in interface org.opengis.geometry.Precision
Returns:
the type of this PrecisionModel

makePrecise

public double makePrecise(double val)
Rounds a numeric value to the PrecisionModel grid. Asymmetric Arithmetic Rounding is used, to provide uniform rounding behaviour no matter where the number is on the number line.

Note: Java's Math#rint uses the "Banker's Rounding" algorithm, which is not suitable for precision operations elsewhere in JTS.


makePrecise

public void makePrecise(Coordinate coord)
Rounds a Coordinate to the PrecisionModel grid.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(PrecisionModel other)
Compares this 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.

Parameters:
other - the PrecisionModel with which this PrecisionModel is being compared
Returns:
a negative integer, zero, or a positive integer as this PrecisionModel is less than, equal to, or greater than the specified PrecisionModel

compareTo

public int compareTo(org.opengis.geometry.Precision precision)
Specified by:
compareTo in interface java.lang.Comparable<org.opengis.geometry.Precision>
Specified by:
compareTo in interface org.opengis.geometry.Precision

round

public void round(org.opengis.geometry.DirectPosition position)
Specified by:
round in interface org.opengis.geometry.Precision


Copyright © 1996-2010 Geotools. All Rights Reserved.