/** * Get or create a geometry value for the given geometry. * * @param s the WKT representation of the geometry * @param srid the srid of the object * @return the value */ public static ValueGeometry get(String s, int srid) { try { GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid); Geometry g = new WKTReader(geometryFactory).read(s); return get(g); } catch (ParseException ex) { throw DbException.convert(ex); } }
public Coordinate getPoint(final double angle) { double x = Math.cos(angle) * this.radius; x = x + this.center.x; x = this.precisionModel.makePrecise(x); double y = Math.sin(angle) * this.radius; y = y + this.center.y; y = this.precisionModel.makePrecise(y); return new Coordinate(x, y); }
public JtsBinaryCodec(JtsSpatialContext ctx, JtsSpatialContextFactory factory) { super(ctx, factory); //note: ctx.geometryFactory hasn't been set yet useFloat = (factory.precisionModel.getType() == PrecisionModel.FLOATING_SINGLE); }
private void bufferFixedPrecision(PrecisionModel fixedPM) { Noder noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.getScale()); BufferBuilder bufBuilder = new BufferBuilder(bufParams); bufBuilder.setWorkingPrecisionModel(fixedPM); bufBuilder.setNoder(noder); // this may throw an exception, if robustness errors are encountered resultGeometry = bufBuilder.buffer(argGeom, distance); } }
private void checkLine45(int width, int nPts, double precision) { Coordinate p1 = new Coordinate(0, width); Coordinate p2 = new Coordinate(width, 0); for (int i = 0; i <= nPts; i++) { double d = width / (double) nPts; Coordinate q = new Coordinate(0.0 + i * d, width - i * d); PrecisionModel pm = new PrecisionModel(precision); pm.makePrecise(q); checkPointOnSeg(p1, p2, q); } }
public void testGetMaximumSignificantDigits() { assertEquals(16, new PrecisionModel(PrecisionModel.FLOATING).getMaximumSignificantDigits()); assertEquals(6, new PrecisionModel(PrecisionModel.FLOATING_SINGLE).getMaximumSignificantDigits()); assertEquals(1, new PrecisionModel(PrecisionModel.FIXED).getMaximumSignificantDigits()); assertEquals(4, new PrecisionModel(1000).getMaximumSignificantDigits()); }
public void setPrecisionModel(PrecisionModel precisionModel) { this.precisionModel = precisionModel; Object modelType = precisionModel.getType(); rbFixed.setSelected(modelType == PrecisionModel.FIXED); rbFloating.setSelected(modelType == PrecisionModel.FLOATING); rbFloatingSingle.setSelected(modelType == PrecisionModel.FLOATING_SINGLE); if (modelType == PrecisionModel.FIXED) { txtScale.setText(Double.toString(precisionModel.getScale())); } updateDisplay(); }
/** * Sets <code>internal</code> to the precise representation of <code>external</code>. * * @param external the original coordinate * @param internal the coordinate whose values will be changed to the * precise representation of <code>external</code> * @deprecated use makePrecise instead */ public void toInternal (Coordinate external, Coordinate internal) { if (isFloating()) { internal.x = external.x; internal.y = external.y; } else { internal.x = makePrecise(external.x); internal.y = makePrecise(external.y); } internal.setZ(external.getZ()); }
private String htmlTitle(PrecisionModel precisionModel) { String html = "Precision Model: scale=" + precisionModel.getScale() + StringUtil.newLine; html = "<div class='precisionModel'>" + html + "</div>"; return html; }
public static String toXML(PrecisionModel precisionModel) { if (precisionModel.isFloating()) { return "<precisionModel type=\"FLOATING\"/>"; } return "<precisionModel type=\"FIXED\" scale=\"" + precisionModel.getScale() + "\"/>"; }
public static NumberFormat format(PrecisionModel pm) { DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setNaN("NaN"); DecimalFormat f = new DecimalFormat(); f.setDecimalFormatSymbols(symbols); if (pm == null) { f.setMaximumFractionDigits(0); return f; } f.setMinimumFractionDigits(0); f.setMaximumFractionDigits(pm.getMaximumSignificantDigits()); return f; }
public void testParameterlessConstructor() { PrecisionModel p = new PrecisionModel(); //Implicit precision model has scale 0 assertEquals(0, p.getScale(), 1E-10); }
private static CoordinateSequence createCircularString(CoordinateSequenceFactory factory, int dimension, Coordinate center, double radius, double startAngle, int numPoints) { final int numSegmentsCircle = 48; final double angleCircle = 2 * Math.PI; final double angleStep = angleCircle / numSegmentsCircle; CoordinateSequence sequence = factory.create(numPoints, dimension); PrecisionModel pm = new PrecisionModel(100); double angle = startAngle; for (int i = 0; i < numPoints; i++) { double dx = Math.cos(angle) * radius; sequence.setOrdinate(i, 0, pm.makePrecise(center.x +dx)); double dy = Math.sin(angle) * radius; sequence.setOrdinate(i, 1, pm.makePrecise(center.y +dy)); // set other ordinate values to predictable values for (int j = 2; j < dimension; j++ ) sequence.setOrdinate(i, j, Math.pow(10, j-1)*i); angle += angleStep; angle %= angleCircle; } return sequence; } }
/** * Estimates the snap tolerance for a Geometry, taking into account its precision model. * * @param g a Geometry * @return the estimated snap tolerance */ public static double computeOverlaySnapTolerance(Geometry g) { double snapTolerance = computeSizeBasedSnapTolerance(g); /** * Overlay is carried out in the precision model * of the two inputs. * If this precision model is of type FIXED, then the snap tolerance * must reflect the precision grid size. * Specifically, the snap tolerance should be at least * the distance from a corner of a precision grid cell * to the centre point of the cell. */ PrecisionModel pm = g.getPrecisionModel(); if (pm.getType() == PrecisionModel.FIXED) { double fixedSnapTol = (1 / pm.getScale()) * 2 / 1.415; if (fixedSnapTol > snapTolerance) snapTolerance = fixedSnapTol; } return snapTolerance; }
public String toString() { String description = "UNKNOWN"; if (modelType == FLOATING) { description = "Floating"; } else if (modelType == FLOATING_SINGLE) { description = "Floating-Single"; } else if (modelType == FIXED) { description = "Fixed (Scale=" + getScale() + ")"; } return description; }
/** * Creates the <code>DecimalFormat</code> used to write <code>double</code>s with a sufficient * number of decimal places. * * @param precisionModel the <code>PrecisionModel</code> used to determine the number of decimal * places to write. * @return a <code>DecimalFormat</code> that write <code>double</code> s without scientific * notation. */ private static DecimalFormat createFormatter(PrecisionModel precisionModel) { // the default number of decimal places is 16, which is sufficient // to accomodate the maximum precision of a double. int decimalPlaces = precisionModel.getMaximumSignificantDigits(); // specify decimal separator explicitly to avoid problems in other locales DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator('.'); String fmtString = "0" + (decimalPlaces > 0 ? "." : "") + stringOfChar('#', decimalPlaces); return new DecimalFormat(fmtString, symbols); }
public static PrecisionModel pm() { if (precModel == null) { precModel = new PrecisionModel(); } return (precModel); }
@Override public double normDist(double d) { return geometryFactory.getPrecisionModel().makePrecise(d); }
/** * Runs a ScaledNoder on input. * Input vertices should be rounded to precision model. * * @param geom * @param scaleFactor * @return the noded geometry */ public static Geometry scaledNoding(Geometry geom, double scaleFactor) { List segs = createSegmentStrings(geom); PrecisionModel fixedPM = new PrecisionModel(scaleFactor); Noder noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.getScale()); noder.computeNodes(segs); Collection nodedSegStrings = noder.getNodedSubstrings(); return SegmentStringUtil.toGeometry(nodedSegStrings, FunctionsUtil.getFactoryOrDefault(geom)); }
/** * Convert the supplied {@code PrecisionModel}. * * @param precisionModel the precision model * * @return the converted precision model */ private com.vividsolutions.jts.geom.PrecisionModel convertPrecisionModel( org.locationtech.jts.geom.PrecisionModel precisionModel) { if (precisionModel.getType() == org.locationtech.jts.geom.PrecisionModel.FIXED) { return new com.vividsolutions.jts.geom.PrecisionModel(precisionModel.getScale()); } else if (precisionModel.getType() == org.locationtech.jts.geom.PrecisionModel.FLOATING) { return new com.vividsolutions.jts.geom.PrecisionModel( com.vividsolutions.jts.geom.PrecisionModel.FLOATING); } else if (precisionModel.getType() == org.locationtech.jts.geom.PrecisionModel.FLOATING_SINGLE) { return new com.vividsolutions.jts.geom.PrecisionModel( com.vividsolutions.jts.geom.PrecisionModel.FLOATING_SINGLE); } else { return new com.vividsolutions.jts.geom.PrecisionModel( new com.vividsolutions.jts.geom.PrecisionModel.Type( precisionModel.getType().toString())); } }