protected boolean hasElevations(CoordinateSequence seq) { return (seq instanceof CoordinateArraySequence && !Double.isNaN(((CoordinateArraySequence) seq).getCoordinate(0).z)) || (!(seq instanceof CoordinateArraySequence) && seq.getDimension() > 2); }
public String encode(Object object, String value) throws Exception { StringBuffer sb = new StringBuffer(); CoordinateSequence cs = (CoordinateSequence) object; for (int i = 0; i < cs.size(); i++) { Coordinate c = cs.getCoordinate(i); sb.append(c.x).append(",").append(c.y); if (cs.getDimension() == 3 && !Double.isNaN(c.z)) { sb.append(",").append(c.z); } sb.append(" "); } sb.setLength(sb.length() - 1); return sb.toString(); } }
public void filter(CoordinateSequence seq, int i) { if (seq.getClass() != coordSeqClass) isSame = false; if (seq.getDimension() != dimension) isSame = false; }
@Override public int getCoordinatesDimension() { if (components.size() == 0) { return 2; } int dimension = Integer.MAX_VALUE; for (LineString component : components) { int curr; if (component instanceof CurvedGeometry<?>) { curr = ((CurvedGeometry<?>) component).getCoordinatesDimension(); } else { curr = component.getCoordinateSequence().getDimension(); } dimension = Math.min(curr, dimension); } return dimension; }
/** * Helper method that just inserts the coordinates of the provided array into the provide * coordinates sequence. */ private void insertCoordinates( Coordinate[] coordinates, CoordinateSequence coordinateSequence) { for (int i = 0; i < coordinates.length; i++) { Coordinate coordinate = coordinates[i]; for (int j = 0; j < coordinateSequence.getDimension(); j++) { // j is the index of the ordinate, i.e. X, Y, Z or M coordinateSequence.setOrdinate(i, j, coordinate.getOrdinate(j)); } } }
private CoordinateSequence readCoordinateSequence(int size) throws IOException { CoordinateSequence seq = JTS.createCS(csFactory, size, inputDimension, inputMeasures); int targetDim = seq.getDimension(); if (targetDim > inputDimension) targetDim = inputDimension; for (int i = 0; i < size; i++) { readCoordinate(); for (int j = 0; j < targetDim; j++) { seq.setOrdinate(i, j, ordValues[j]); } } return seq; }
public CircularString(CoordinateSequence points, GeometryFactory factory, double tolerance) { super(FAKE_STRING_2D, factory); this.tolerance = tolerance; if (points.getDimension() != 2) { throw new IllegalArgumentException( "Circular strings are restricted to 2 dimensions " + "at the moment. Contributions to get ND support welcomed!"); } int pointCount = points.size(); controlPoints = new double[pointCount * 2]; for (int i = 0; i < pointCount; i++) { controlPoints[i * 2] = points.getX(i); controlPoints[i * 2 + 1] = points.getY(i); } init(controlPoints, tolerance); }
/** Helper method that converts an array of coordinates to an array of ordinates. */ private List<Double> getOrdinates(CoordinateSequence coordinateSequence) { List<Double> ordinates = new ArrayList<>(); for (Coordinate coordinate : coordinateSequence.toCoordinateArray()) { // let's get all the coordinates ordinates for (int i = 0; i < coordinateSequence.getDimension(); i++) { ordinates.add(coordinate.getOrdinate(i)); } } return ordinates; }
protected void write(Encoder output, CoordinateSequence coordseq) throws IOException { int dim = coordseq.getDimension(); // if(dim>2) { // throw new IllegalArgumentException("only supports 2d geometry now ("+dim+")"); // } for (int i = 0; i < coordseq.size(); i++) { output.write(coordseq.getOrdinate(i, 0), coordseq.getOrdinate(i, 1)); } }
private CoordinateSequence readCoordinateSequence(int size) throws IOException { CoordinateSequence seq = JTS.createCS(factory.getCoordinateSequenceFactory(), size, inputDimension); int targetDim = seq.getDimension(); if (targetDim > inputDimension) targetDim = inputDimension; for (int i = 0; i < size; i++) { readCoordinate(); for (int j = 0; j < targetDim; j++) { seq.setOrdinate(i, j, ordValues[j]); } } return seq; }
boolean hasSameValuesAndStructure(Geometry g1, Geometry g2) { if (!g1.equalsExact(g2, ORD_TOLERANCE)) return false; if (g1.getFactory() != g2.getFactory()) return false; CoordinateSequence seq = CoordinateSequenceFinder.find(g1); if (!CoordinateSequenceSchemaChecker.check(g2, seq.getClass(), seq.getDimension())) return false; return true; }
@Test public void emptyLineStringZ() throws Exception { LineString line = builder.lineStringZ(); assertEquals(3, line.getCoordinateSequence().getDimension()); }
private void writeCoordinate(CoordinateSequence seq, int index, OutStream os) throws IOException { ByteOrderValues.putDouble(seq.getX(index), buf, byteOrder); os.write(buf, 8); ByteOrderValues.putDouble(seq.getY(index), buf, byteOrder); os.write(buf, 8); // only write 3rd dim if caller has requested it for this writer if (outputDimension >= 3) { // if 3rd dim is requested, only access and write it if the CS provides is double ordVal = Coordinate.NULL_ORDINATE; if (seq.getDimension() >= 3) ordVal = seq.getOrdinate(index, 2); ByteOrderValues.putDouble(ordVal, buf, byteOrder); os.write(buf, 8); } }
@Test public void testDecimate3DPoint() throws Exception { Point p = gf.createPoint(csf.create(new double[] {0, 1, 2}, 3)); Decimator d = new Decimator(identity, new Rectangle(0, 0, 5, 5), 0.8); d.decimateTransformGeneralize(p, identity); assertEquals(1, p.getNumPoints()); assertEquals(2, p.getCoordinateSequence().getDimension()); }
@Test public void linearRingZ() throws Exception { LinearRing ring = builder.linearRingZ(); assertTrue(ring.isEmpty()); assertEquals(3, ring.getCoordinateSequence().getDimension()); }
@Test public void emptyLineString() throws Exception { LineString line = builder.lineString(); assertTrue(line.isEmpty()); assertEquals(2, line.getCoordinateSequence().getDimension()); }
@Test public void testDecimate3DLine() throws Exception { LineString ls = gf.createLineString( csf.create(new double[] {0, 0, 1, 1, 2, 1, 3, 3, 4, 4, 5, 5}, 3)); assertEquals(4, ls.getNumPoints()); Decimator d = new Decimator(identity, new Rectangle(0, 0, 5, 5), 0.8); d.decimateTransformGeneralize(ls, identity); assertEquals(4, ls.getNumPoints()); assertEquals(2, ls.getCoordinateSequence().getDimension()); }
@Test public void linearRing() throws Exception { LinearRing ring = builder.linearRing(); assertTrue(ring.isEmpty()); assertEquals(2, ring.getCoordinateSequence().getDimension()); }
@Test public void multiPoint() throws Exception { double[] ords = {1, 2, 3, 4}; MultiPoint mp = builder.multiPoint(ords[0], ords[1], ords[2], ords[3]); assertEquals(2, mp.getNumGeometries()); Point p = (Point) mp.getGeometryN(0); assertEquals(2, p.getCoordinateSequence().getDimension()); }
@Test public void multiPointZ() throws Exception { double[] ords = {1, 2, 3, 4, 5, 6}; MultiPoint mp = builder.multiPointZ(ords[0], ords[1], ords[2], ords[3], ords[4], ords[5]); assertEquals(2, mp.getNumGeometries()); Point p = (Point) mp.getGeometryN(0); assertEquals(3, p.getCoordinateSequence().getDimension()); }