@Override public void setCoordinate(Coordinate other) { x = other.x; y = other.y; z = other.getZ(); m = other.getM(); } @Override
/** * @see org.locationtech.jts.geom.CoordinateSequence#getM(int) */ public double getM(int index) { if (hasM()) { return coordinates[index].getM(); } else { return Double.NaN; } }
@Override public void setCoordinate(Coordinate other) { x = other.x; y = other.y; z = other.getZ(); m = other.getM(); }
@Override public void setCoordinate(Coordinate other) { x = other.x; y = other.y; z = other.getZ(); m = other.getM(); }
@Override protected void checkCoordinate(Coordinate c) { super.checkCoordinate(c); if (hasZ) { BigDecimal zCoord = new BigDecimal(Double.toString(c.getZ())).stripTrailingZeros(); zPrecision = Math.max(zCoord.scale(), zPrecision); } if (hasM) { BigDecimal mCoord = new BigDecimal(Double.toString(c.getM())).stripTrailingZeros(); mPrecision = Math.max(mCoord.scale(), mPrecision); } }
private CoordinateReferenceSystem<?> determineCRS(Coordinate[] coordinates) { boolean hasZ, hasM = false; if (coordinates == null || coordinates.length == 0) { return PROJECTED_2D_METER; } hasM = !Double.isNaN( coordinates[0].getM()); hasZ = !Double.isNaN(coordinates[0].getZ()); if (hasM && hasZ) { return PROJECTED_3DM_METER; } else if (hasM) { return PROJECTED_2DM_METER; } else if (hasZ) { return PROJECTED_3D_METER; } else { return PROJECTED_2D_METER; } }
@Override public PrecisionWriter calculate(Coordinate[] coordinates, int maxPrecision) { this.hasZ = !Double.isNaN(coordinates[0].getZ()); this.hasM = !Double.isNaN(coordinates[0].getM()); super.calculate(coordinates, maxPrecision); return this; }
@Override public void writePoint(Coordinate coordinate, DataOutput output) throws IOException { super.writePoint(coordinate, output); if (hasZ) { Varint.writeSignedVarLong(Math.round(coordinate.getZ() * zPrecisionMultiplier), output); } if (hasM) { Varint.writeSignedVarLong(Math.round(coordinate.getM() * mPrecisionMultiplier), output); } }
/** * Confirm the z field is not supported by getZ and setZ. */ private void checkMUnsupported(Coordinate coord ) { try { coord.setM(0.0); fail(coord.getClass().getSimpleName() + " does not support M"); } catch(IllegalArgumentException expected) { } assertTrue( Double.isNaN(coord.getM())); }
/** * Primary Factory method that converts a JTS geometry into an equivalent geolatte geometry * * @param jtsGeometry the jts geometry to convert * @return an equivalent geolatte geometry * @throws IllegalArgumentException when a null object is passed */ public static org.geolatte.geom.Geometry<?> from(org.locationtech.jts.geom.Geometry jtsGeometry) { if (jtsGeometry == null) { throw new IllegalArgumentException("Null object passed."); } Coordinate testCo = jtsGeometry.getCoordinate(); boolean is3D = !(testCo == null || Double.isNaN(testCo.z)); CoordinateReferenceSystem<?> crs = CrsRegistry.ifAbsentReturnProjected2D(jtsGeometry.getSRID()); if (is3D) { crs = CoordinateReferenceSystems.addVerticalSystem(crs, LinearUnit.METER); } // to translate measure, add Measure as LinearSystem boolean hasM = isMeasuredCoordinate(testCo) && !Double.isNaN(testCo.getM()); if (hasM) { crs = CoordinateReferenceSystems.addLinearSystem(crs, LinearUnit.METER); } return from(jtsGeometry, crs); }
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(); } }
Coordinate[] coordinates = geom.getCoordinates(); PrecisionWriter precision; if (Double.isNaN(coordinates[0].getZ()) || Double.isNaN(coordinates[0].getM())) { metadata |= TWKBUtils.EXTENDED_DIMENSIONS; precision = new ExtendedPrecisionWriter().calculate(coordinates, maxPrecision);
public void testCoordinateXYZM() { Coordinate xyzm = new CoordinateXYZM(); xyzm.setZ(1.0); assertEquals( 1.0, xyzm.getZ()); xyzm.setM(1.0); assertEquals( 1.0, xyzm.getM()); Coordinate coord = new Coordinate(xyzm); // copy assertEquals( xyzm, coord ); assertTrue( xyzm.equalInZ(coord,0.000001) ); assertTrue( Double.isNaN(coord.getM())); coord = new Coordinate(1.0,1.0,1.0); // 2.5d xyzm = new CoordinateXYZM( coord ); // copy assertEquals( xyzm, coord ); assertTrue( xyzm.equalInZ(coord,0.000001) ); }
public void testCoordinateXYM() { Coordinate xym = new CoordinateXYM(); checkZUnsupported(xym); xym.setM(1.0); assertEquals( 1.0, xym.getM()); Coordinate coord = new Coordinate(xym); // copy assertEquals( xym, coord ); assertTrue( !xym.equalInZ(coord,0.000001) ); coord = new Coordinate(1.0,1.0,1.0); // 2.5d xym = new CoordinateXYM( coord ); // copy assertEquals( xym, coord ); assertTrue( !xym.equalInZ(coord,0.000001) ); } public void testCoordinateXYZM() {
boolean isAllCoordsEqual(CoordinateSequence seq, Coordinate coord) { for (int i = 0; i < seq.size(); i++) { if (!coord.equals(seq.getCoordinate(i))) return false; if (coord.x != seq.getOrdinate(i, CoordinateSequence.X)) return false; if (coord.y != seq.getOrdinate(i, CoordinateSequence.Y)) return false; if (seq.hasZ()) { if (coord.getZ() != seq.getZ(i)) return false; } if (seq.hasM()) { if (coord.getM() != seq.getM(i)) return false; } if (seq.getDimension() > 2) { if (coord.getOrdinate(2) != seq.getOrdinate(i, 2)) return false; } if (seq.getDimension() > 3) { if (coord.getOrdinate(3) != seq.getOrdinate(i, 3)) return false; } } return true; }
assertEquals( 4.0, coord.getX()); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getZ()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]);
assertEquals( 4.0, coord.getX()); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]); assertEquals( 4.0, coord.getY()); assertEquals( 4.0, coord.getZ()); assertEquals( 4.0, coord.getM()); array = seq.toCoordinateArray(); assertEquals(coord, array[4]);