/** * Non-robust intersection of a segment with a horizontal line. * Inputs are not expected to have high precision, so * this computation should be adequate. * * @param p0 * @param p1 * @param scanY2 * @return */ private static double intersection(Coordinate p0, Coordinate p1, double Y) { double x0 = p0.getX(); double x1 = p1.getX(); if (x0 == x1) return x0; double m = (p1.getY() - p0.getY()) / (x1 - x0); double x = ((Y - p0.getY()) / m) + x0; return x; }
protected void checkCoordinate(Coordinate c) { BigDecimal xCoord = new BigDecimal(Double.toString(c.getX())).stripTrailingZeros(); precision = Math.max(xCoord.scale(), precision); BigDecimal yCoord = new BigDecimal(Double.toString(c.getY())).stripTrailingZeros(); precision = Math.max(yCoord.scale(), precision); }
private void scanSegment(Coordinate p0, Coordinate p1) { // skip non-crossing segments if (! crosses(p0, p1, scanY)) return; // skip horizontal lines if (p0.getY() == p1.getY()) return; // handle vertices on scan-line // downward segment does not include start point if (p0.y == scanY && p1.y < scanY) return; // upward segment does not include endpoint if (p1.y == scanY && p0.y < scanY) return; // add a crossing double xInt = intersection(p0, p1, scanY); crossings.add(xInt); }
protected ArrayNode encodeCoordinate(Coordinate coordinate) { ArrayNode array = jsonFactory.arrayNode().add(coordinate.getX()).add(coordinate.getY()); if (!Double.isNaN(coordinate.getZ())) { array.add(coordinate.getZ()); } return array; }
public void writePoint(Coordinate coordinate, DataOutput output) throws IOException { Varint.writeSignedVarLong(Math.round(coordinate.getX() * precisionMultiplier), output); Varint.writeSignedVarLong(Math.round(coordinate.getY() * precisionMultiplier), output); }
/** * @param coord1 * @param coord2 subtracted from coord1 * @return a coordinate the supplies the difference of values for each axis between coord1 and * coord2 */ private static Coordinate diff(final Coordinate coord1, final Coordinate coord2) { return new Coordinate( coord1.getX() - coord2.getX(), coord1.getY() - coord2.getY(), coord1.getZ() - coord2.getZ()); }
public void writePointArray(Coordinate[] coordinates, DataOutput output) throws IOException { long lastX = 0; long lastY = 0; Varint.writeUnsignedVarInt(coordinates.length, output); for (Coordinate c : coordinates) { long x = Math.round(c.getX() * precisionMultiplier); long y = Math.round(c.getY() * precisionMultiplier); Varint.writeSignedVarLong(x - lastX, output); Varint.writeSignedVarLong(y - lastY, output); lastX = x; lastY = y; } } }
@Override public void writePointArray(Coordinate[] coordinates, DataOutput output) throws IOException { long lastX = 0; long lastY = 0; long lastZ = 0; long lastM = 0; Varint.writeUnsignedVarInt(coordinates.length, output); for (Coordinate c : coordinates) { long x = Math.round(c.getX() * precisionMultiplier); long y = Math.round(c.getY() * precisionMultiplier); Varint.writeSignedVarLong(x - lastX, output); Varint.writeSignedVarLong(y - lastY, output); lastX = x; lastY = y; if (hasZ) { long z = Math.round(c.getZ() * zPrecisionMultiplier); Varint.writeSignedVarLong(z - lastZ, output); lastZ = z; } if (hasM) { long m = Math.round(c.getZ() * mPrecisionMultiplier); Varint.writeSignedVarLong(m - lastM, output); lastM = m; } } } }
private <P extends Position> void copy(Coordinate co, double[] ordinates, CoordinateReferenceSystem<P> crs) { ordinates[0] = co.getX(); ordinates[1] = co.getY(); boolean hasVerticalAxis = hasVerticalAxis(crs); if (hasVerticalAxis) { ordinates[2] = co.getZ(); } if (hasMeasureAxis(crs)) { int idxM = hasVerticalAxis ? 3 : 2; ordinates[idxM] = co.getM(); } }
/** * Make sure the coordinate falls in the range of provided coordinate reference systems's * coordinate system. 'x' coordinate is wrapped around date line. 'y' and 'z' coordinate are * clipped. At some point, this function will be adjusted to project 'y' appropriately. * * @param crs * @param coord * @return */ public static Coordinate adjustCoordinateToFitInRange( final CoordinateReferenceSystem crs, final Coordinate coord) { return new Coordinate( adjustCoordinateDimensionToRange(coord.getX(), crs, 0), clipRange(coord.getY(), crs, 1), clipRange(coord.getZ(), crs, 2)); }
private void checkDecodeEncode(int level, int index) { Coordinate p = decode(index); int encode = encode((int) p.getX(), (int) p.getY() ); assertEquals( index, encode); } }
private void checkDecode(int order, int index, int x, int y) { Coordinate p = decode(order, index); //System.out.println(p); assertEquals( (int) p.getX(), x); assertEquals( (int) p.getY(), y); }
private void checkDecode(int index, int x, int y) { Coordinate p = decode(index); //System.out.println(p); assertEquals( (int) p.getX(), x); assertEquals( (int) p.getY(), y); }
private void checkDecodeEncode(int level, int index) { Coordinate p = decode(level, index); int encode = encode(level, (int) p.getX(), (int) p.getY() ); assertEquals( index, encode); }
AbstractSamplingFeature sf = (AbstractSamplingFeature) f; String xString = sf.isSetGeometry() ? Double.toString(sf.getGeometry().getCoordinate().getY()) : ""; xString = ensureValueLength(xString, 10); sb.append(xString);
@Override public Geometry getGeometry() { int level = level(numPts); int nPts = size(level); double scale = 1; double baseX = 0; double baseY = 0; if (extent != null) { LineSegment baseLine = getSquareBaseLine(); baseX = baseLine.minX(); baseY = baseLine.minY(); double width = baseLine.getLength(); int maxOrdinate = maxOrdinate(level); scale = width / maxOrdinate; } Coordinate[] pts = new Coordinate[nPts]; for (int i = 0; i < nPts; i++) { Coordinate pt = decode(level, i); double x = transform(pt.getX(), scale, baseX ); double y = transform(pt.getY(), scale, baseY ); pts[i] = new Coordinate(x, y); } return geomFactory.createLineString(pts); }
@Override public Geometry getGeometry() { int level = level(numPts); int nPts = size(level); double scale = 1; double baseX = 0; double baseY = 0; if (extent != null) { LineSegment baseLine = getSquareBaseLine(); baseX = baseLine.minX(); baseY = baseLine.minY(); double width = baseLine.getLength(); int maxOrdinate = maxOrdinate(level); scale = width / maxOrdinate; } Coordinate[] pts = new Coordinate[nPts]; for (int i = 0; i < nPts; i++) { Coordinate pt = decode(i); double x = transform(pt.getX(), scale, baseX); double y = transform(pt.getY(), scale, baseY); pts[i] = new Coordinate(x, y); } return geomFactory.createLineString(pts); }