/** * Reads a coordinate value with the specified dimensionality. Makes the X and Y ordinates precise * according to the precision model in use. */ private void readCoordinate() throws IOException { for (int i = 0; i < inputDimension; i++) { if (i <= 1) { ordValues[i] = precisionModel.makePrecise(dis.readDouble()); } else { ordValues[i] = dis.readDouble(); } } }
/** * Compares this {@link 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 {@link #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. * * @param o the <code>PrecisionModel</code> with which this <code>PrecisionModel</code> is being * compared * @return a negative integer, zero, or a positive integer as this <code>PrecisionModel</code> is * less than, equal to, or greater than the specified <code>PrecisionModel</code> */ public int compareTo(Object o) { PrecisionModel other = (PrecisionModel) o; int sigDigits = getMaximumSignificantDigits(); int otherSigDigits = other.getMaximumSignificantDigits(); return (new Integer(sigDigits)).compareTo(new Integer(otherSigDigits)); // if (sigDigits > otherSigDigits) // return 1; // else if // if (modelType == FLOATING && other.modelType == FLOATING) return 0; // if (modelType == FLOATING && other.modelType != FLOATING) return 1; // if (modelType != FLOATING && other.modelType == FLOATING) return -1; // if (modelType == FIXED && other.modelType == FIXED) { // if (scale > other.scale) // return 1; // else if (scale < other.scale) // return -1; // else // return 0; // } // Assert.shouldNeverReachHere("Unknown Precision Model type encountered"); // return 0; }
public Coordinate[] edit(Coordinate[] coordinates, Geometry geom) { if (coordinates.length == 0) return null; Coordinate[] reducedCoords = new Coordinate[coordinates.length]; // copy coordinates and reduce for (int i = 0; i < coordinates.length; i++) { Coordinate coord = new Coordinate(coordinates[i]); targetPM.makePrecise(coord); reducedCoords[i] = coord; } // remove repeated points, to simplify returned geometry as much as possible CoordinateList noRepeatedCoordList = new CoordinateList(reducedCoords, false); Coordinate[] noRepeatedCoords = noRepeatedCoordList.toCoordinateArray(); /** * Check to see if the removal of repeated points collapsed the coordinate List to an invalid * length for the type of the parent geometry. It is not necessary to check for Point collapses, * since the coordinate list can never collapse to less than one point. If the length is * invalid, return the full-length coordinate array first computed, or null if collapses are * being removed. (This may create an invalid geometry - the client must handle this.) */ int minLength = 0; if (geom instanceof LineString) minLength = 2; if (geom instanceof LinearRing) minLength = 4; Coordinate[] collapsedCoords = reducedCoords; if (removeCollapsed) collapsedCoords = null; // return null or orginal length coordinate array if (noRepeatedCoords.length < minLength) { return collapsedCoords; } // ok to return shorter coordinate array return noRepeatedCoords; }
/** * Determines which of two {@link PrecisionModel}s is the most precise (allows the greatest number * of significant digits). * * @param pm1 a PrecisionModel * @param pm2 a PrecisionModel * @return the PrecisionModel which is most precise */ public static PrecisionModel mostPrecise(PrecisionModel pm1, PrecisionModel pm2) { if (pm1.compareTo(pm2) >= 0) return pm1; return pm2; }
public static String toXML(PrecisionModel precisionModel) { if (precisionModel.isFloating()) { return "<precisionModel type=\"FLOATING\"/>"; } return "<precisionModel type=\"FIXED\" scale=\"" + precisionModel.getScale() + "\"/>"; }