Java Code Examples for com.vividsolutions.jts.geom.CoordinateSequence#getOrdinate()
The following examples show how to use
com.vividsolutions.jts.geom.CoordinateSequence#getOrdinate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WKBWriter.java From jts with GNU Lesser General Public License v2.1 | 6 votes |
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 write it if the CoordinateSequence provides it double ordVal = Coordinate.NULL_ORDINATE; if (seq.getDimension() >= 3) ordVal = seq.getOrdinate(index, 2); ByteOrderValues.putDouble(ordVal, buf, byteOrder); os.write(buf, 8); } }
Example 2
Source File: GeoJsonWriter.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
private String getJsonString(CoordinateSequence coordinateSequence) { StringBuffer result = new StringBuffer(); if (coordinateSequence.size() > 1) { result.append("["); } for (int i = 0; i < coordinateSequence.size(); i++) { if (i > 0) { result.append(","); } result.append("["); result.append(formatOrdinate(coordinateSequence.getOrdinate(i, CoordinateSequence.X))); result.append(","); result.append(formatOrdinate(coordinateSequence.getOrdinate(i, CoordinateSequence.Y))); if (coordinateSequence.getDimension() > 2 ) { double z = coordinateSequence.getOrdinate(i, CoordinateSequence.Z); if (! Double.isNaN(z)) { result.append(","); result.append(formatOrdinate(z)); } } result.append("]"); } if (coordinateSequence.size() > 1) { result.append("]"); } return result.toString(); }
Example 3
Source File: PlanarPolygon3D.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Computes a point which is the average of all coordinates * in a sequence. * If the sequence lies in a single plane, * the computed point also lies in the plane. * * @param seq a coordinate sequence * @return a Coordinate with averaged ordinates */ private Coordinate averagePoint(CoordinateSequence seq) { Coordinate a = new Coordinate(0,0,0); int n = seq.size(); for (int i = 0; i < n; i++) { a.x += seq.getOrdinate(i, CoordinateSequence.X); a.y += seq.getOrdinate(i, CoordinateSequence.Y); a.z += seq.getOrdinate(i, CoordinateSequence.Z); } a.x /= n; a.y /= n; a.z /= n; return a; }
Example 4
Source File: CoordinateSequenceTestBase.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
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 (coord.z != seq.getOrdinate(i, CoordinateSequence.Z)) return false; } return true; }
Example 5
Source File: CoordinateSequenceTestBase.java From jts with GNU Lesser General Public License v2.1 | 5 votes |
/** * Tests for equality using all supported accessors, * to provides test coverage for them. * * @param seq * @param coords * @return */ boolean isEqual(CoordinateSequence seq, Coordinate[] coords) { if (seq.size() != coords.length) return false; Coordinate p = new Coordinate(); for (int i = 0; i < seq.size(); i++) { if (! coords[i].equals(seq.getCoordinate(i))) return false; // Ordinate named getters if (coords[i].x != seq.getX(i)) return false; if (coords[i].y != seq.getY(i)) return false; // Ordinate indexed getters if (coords[i].x != seq.getOrdinate(i, CoordinateSequence.X)) return false; if (coords[i].y != seq.getOrdinate(i, CoordinateSequence.Y)) return false; if (coords[i].z != seq.getOrdinate(i, CoordinateSequence.Z)) return false; // Coordinate getter seq.getCoordinate(i, p); if (coords[i].x != p.x) return false; if (coords[i].y != p.y) return false; if (coords[i].z != p.z) return false; } return true; }