private int getDisconinuityDirection(CoordinateSequence cs) { double lastOrdinate = cs.getOrdinate(0, ordinateIdx); for (int i = 0; i < cs.size(); i++) { double ordinate = cs.getOrdinate(i, ordinateIdx); if (Math.abs(ordinate - lastOrdinate) > wrapLimit) { if (ordinate > lastOrdinate) return WEST_TO_EAST; else if (ordinate < lastOrdinate) return EAST_TO_WEST; } lastOrdinate = ordinate; } return NOWRAP; }
private void applyZValues( CoordinateSequence cs, int idx, CoordinateSequence csOrig, int origIdx) { if (!cs.hasZ()) return; double lx1 = cs.getOrdinate(idx, 0); double ly1 = cs.getOrdinate(idx, 1); double lz1; double ox1 = csOrig.getX(origIdx); double oy1 = csOrig.getY(origIdx); double oz1 = csOrig.getZ(origIdx); double ox2 = csOrig.getX(origIdx + 1); double oy2 = csOrig.getY(origIdx + 1); double oz2 = csOrig.getZ(origIdx + 1); if (lx1 == ox1 && ly1 == oy1) { lz1 = oz1; } else { double d1 = distance(ox1, oy1, lx1, ly1); double d = distance(ox1, oy1, ox2, oy2); lz1 = oz1 + (oz2 - oz1) * (d1 / d); } cs.setOrdinate(idx, 2, lz1); }
public void filter(CoordinateSequence seq, int i) { seq.setOrdinate(i, 0, seq.getOrdinate(i, 0) + offsetX); seq.setOrdinate(i, 1, seq.getOrdinate(i, 1) + offsetY); }
@Override public void filter(CoordinateSequence seq, int i) { seq.setOrdinate(i, CoordinateSequence.X, seq.getX(i) + xShift ); }
public static int D(CoordinateSequence cs) { if (cs instanceof CoordinateAccess) { return ((CoordinateAccess) cs).getDimension(); } if (cs.size() > 0) { return Double.isNaN(cs.getCoordinate(0).z) ? 2 : 3; } return 3; }
public LiteCoordinateSequence(CoordinateSequence cs, int dimension) { super(dimension, cs.getMeasures()); this.size = cs.size(); this.dimension = dimension; if (cs instanceof LiteCoordinateSequence) { double[] orig = ((LiteCoordinateSequence) cs).getOrdinateArray(dimension); this.coords = new double[orig.length]; System.arraycopy(orig, 0, coords, 0, coords.length); } else { this.coords = new double[size * dimension]; int minDimension = Math.min(dimension, cs.getDimension()); for (int i = 0; i < size; i++) { for (int j = 0; j < minDimension; j++) { coords[i * dimension + j] = cs.getOrdinate(i, j); } } } }
void coordinates(CoordinateSequence coordinates, char cs, char ts, StringBuffer sb) { sb.setLength(0); int n = coordinates.size(); int dim = CoordinateSequences.coordinateDimension(coordinates); for (int i = 0; i < n; i++) { coordFormatter.format(coordinates.getX(i), sb).append(cs); coordFormatter.format(coordinates.getY(i), sb); if (dim > 2) { int totalDimensions = encodeMeasures ? dim : dim - coordinates.getMeasures(); // encoding the remaining ordinates, typically Z and M values for (int j = 2; j < totalDimensions; j++) { sb.append(cs); coordFormatter.format(coordinates.getOrdinate(i, j), sb); } } sb.append(ts); } sb.setLength(sb.length() - 1); }
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); }
if (currentCoord == coords.size()) { if (currentRing < (rings.length - 1)) { currentCoord = 0; if (oldCoord == null) { currentCoord++; oldCoord = coords.getCoordinate(currentCoord); } else { double distx = 0; currentCoord++; if (currentCoord < coords.size()) { distx = Math.abs(coords.getX(currentCoord) - oldCoord.x); disty = Math.abs(coords.getY(currentCoord) - oldCoord.y); && (currentCoord < coords.size())); if (currentCoord < coords.size()) { oldCoord = coords.getCoordinate(currentCoord); } else { oldCoord = null;
int size = cseq.size(); if (size <= 1) return 0; int shiftXPage = 0; int shiftXPageMin = 0/* <= 0 */, shiftXPageMax = 0; /* >= 0 */ double prevX = cseq.getX(0); for(int i = 1; i < size; i++) { double thisX_orig = cseq.getX(i); assert thisX_orig >= -180 && thisX_orig <= 180 : "X not in geo bounds"; double thisX = thisX_orig + shiftX; cseq.setOrdinate(i, CoordinateSequence.X, thisX); prevX = thisX; assert cseq.getCoordinate(0).equals(cseq.getCoordinate(size-1)); assert shiftXPage == 0;//starts and ends at 0
@Override public Polygon getBuffer(double distance) { CoordinateSequence cs = new LiteCoordinateSequence(quadrantSegments * 4 + 1, 2); for (int i = 0; i < (cs.size() - 1); i++) { double azimuth = 360.0 * i / cs.size() - 180; calculator.setDirection(azimuth, distance); Point2D dp = calculator.getDestinationGeographicPoint(); if (latLon) { cs.setOrdinate(i, 0, dp.getY()); cs.setOrdinate(i, 1, dp.getX()); } else { cs.setOrdinate(i, 0, dp.getX()); cs.setOrdinate(i, 1, dp.getY()); } } cs.setOrdinate(cs.size() - 1, 0, cs.getOrdinate(0, 0)); cs.setOrdinate(cs.size() - 1, 1, cs.getOrdinate(0, 1)); return gf.createPolygon(gf.createLinearRing(cs), null); } }
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)); } }
/** Checks that the measures of XYM geometries are not transformed. */ @Test public void testXymGeometriesMeasuresArePreserved() throws Exception { // build a XYM geometry and reproject it Geometry geometry = new WKTReader().read("LINESTRINGM(170 -40 2, 190 40 7)"); MathTransform transform = CRS.findMathTransform(WGS84, MERCATOR, true); Geometry transformed = JTS.transform(geometry, transform); // check that coordinates where transformed but measures preserved assertThat(transformed, instanceOf(LineString.class)); LineString line = (LineString) transformed; assertThat(line.getCoordinateSequence().getDimension(), is(3)); assertThat(line.getCoordinateSequence().getMeasures(), is(1)); // check the first coordinate assertThat(line.getCoordinateSequence().getX(0), closeTo(1.8924313434856504E7, EPS)); assertThat(line.getCoordinateSequence().getY(0), closeTo(-4838471.398061137, EPS)); assertThat(line.getCoordinateSequence().getZ(0), is(Double.NaN)); assertThat(line.getCoordinateSequence().getM(0), is(2.0)); // check the second coordinate assertThat(line.getCoordinateSequence().getX(1), closeTo(2.115070325072198E7, EPS)); assertThat(line.getCoordinateSequence().getY(1), closeTo(4838471.398061137, EPS)); assertThat(line.getCoordinateSequence().getZ(1), is(Double.NaN)); assertThat(line.getCoordinateSequence().getM(1), is(7.0)); }
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(); } }
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); } }
protected double getSegmentAngle(int segmentIdx) { if (Double.isNaN(segmentAngles[segmentIdx])) { double dx = (coords.getX(segmentIdx + 1) - coords.getX(segmentIdx)); double dy = (coords.getY(segmentIdx + 1) - coords.getY(segmentIdx)); segmentAngles[segmentIdx] = Math.atan2(dy, dx); } return segmentAngles[segmentIdx]; }
/** * 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)); } } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { CoordinateSequence coordinates = (CoordinateSequence) node.getChildValue(KML.coordinates.getLocalPart()); // If the last point is not the same as the first point jts will throw an error // where as other KML readers like google earth just auto close the polygon so // here we manually fix it even though it's invalid so KMls that work elsewhere work here Coordinate firstCoord = coordinates.getCoordinate(0); Coordinate lastCoord = coordinates.getCoordinate(coordinates.size() - 1); if (!firstCoord.equals3D(lastCoord)) { List<Coordinate> updateCoords = new ArrayList<>(Arrays.asList(coordinates.toCoordinateArray())); updateCoords.add((Coordinate) firstCoord.clone()); coordinates = csFactory.create(updateCoords.toArray(new Coordinate[0])); } return geometryFactory.createLinearRing(coordinates); }