/** * Performs an operation on a coordinate in a CoordinateSequence. * * @param coordinateSequence the object to which the filter is applied * @param i the index of the coordinate to apply the filter to */ @Override public void filter(CoordinateSequence coordinateSequence, int i) { if (!Double.isNaN(coordinateSequence.getOrdinate(i, 2))) { foundZ = true; } }
private static boolean equals2D(CoordinateSequence cs, int i, int j) { return cs.getOrdinate(i, 0) == cs.getOrdinate(j, 0) && cs.getOrdinate(i, 1) == cs.getOrdinate(j, 1); }
public static int computeOrientation(CoordinateSequence cs, int p1, int p2, int q) { // travelling along p1->p2, turn counter clockwise to get to q return 1, // travelling along p1->p2, turn clockwise to get to q return -1, // p1, p2 and q are colinear return 0. double p1x = cs.getOrdinate(p1, 0); double p1y = cs.getOrdinate(p1, 1); double p2x = cs.getOrdinate(p2, 0); double p2y = cs.getOrdinate(p2, 1); double qx = cs.getOrdinate(q, 0); double qy = cs.getOrdinate(q, 1); double dx1 = p2x - p1x; double dy1 = p2y - p1y; double dx2 = qx - p2x; double dy2 = qy - p2y; return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2); }
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; }
@Override public void filter(Geometry geom) { if (geom instanceof LineString && ((LineString) geom).getCoordinateSequence().size() == 2) { CoordinateSequence cs = ((LineString) geom).getCoordinateSequence(); lines.add( new Line2D.Double( cs.getOrdinate(0, 0), cs.getOrdinate(0, 1), cs.getOrdinate(1, 0), cs.getOrdinate(1, 1))); } else if (!(geom instanceof GeometryCollection)) { // collections are not a problem isSimple = false; } }
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); }
public void filter(CoordinateSequence seq, int i) { seq.setOrdinate(i, ordinateIndex, seq.getOrdinate(i, ordinateIndex) + offset); }
/** * Appends a whole coordinate sequence to the array * * @param cs */ public void addAll(CoordinateSequence cs) { int coordinatesCount = cs.size(); ensureLength(curr + coordinatesCount * 2); for (int i = 0; i < coordinatesCount; i++) { data[curr + i * 2] = cs.getOrdinate(i, 0); data[curr + i * 2 + 1] = cs.getOrdinate(i, 1); } curr += coordinatesCount * 2; }
/** * Creates a {@link CircularString} or a {@link CircularRing} depending on whether the points * are forming a closed ring, or not */ public LineString createCurvedGeometry(CoordinateSequence cs) { int lastCoordinate = cs.size() - 1; if (cs.size() > 0 && cs.getOrdinate(0, 0) == cs.getOrdinate(lastCoordinate, 0) && cs.getOrdinate(0, 1) == cs.getOrdinate(lastCoordinate, 1)) { return new CircularRing(cs, this, tolerance); } else { return new CircularString(cs, this, tolerance); } }
protected void write(JsonGenerator gen, CoordinateSequence coordseq) throws IOException { gen.writeStartArray(); int dim = coordseq.getDimension(); for (int i = 0; i < coordseq.size(); i++) { gen.writeStartArray(); gen.writeNumber(coordseq.getOrdinate(i, 0)); gen.writeNumber(coordseq.getOrdinate(i, 1)); if (dim > 2) { double v = coordseq.getOrdinate(i, 2); if (!Double.isNaN(v)) { gen.writeNumber(v); } } gen.writeEndArray(); } gen.writeEndArray(); }
public void init(CoordinateSequence cs) { clear(); for (int i = 0; i < cs.size(); i++) { add(cs.getOrdinate(i, 0), cs.getOrdinate(i, 1)); } }
static DirectPosition[] positions(LineString line) { CoordinateSequence coordinates = line.getCoordinateSequence(); DirectPosition[] dps = new DirectPosition[coordinates.size()]; double x; double y; for (int i = 0; i < dps.length; i++) { x = coordinates.getOrdinate(i, 0); y = coordinates.getOrdinate(i, 1); dps[i] = new DirectPosition2D(x, y); } return dps; }
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)); } }
@Override public void filter(CoordinateSequence seq, int i) { double x = seq.getOrdinate(i, 0); double y = seq.getOrdinate(i, 1); x -= minx; y -= miny; x = Math.round(x / tolerance) * tolerance; y = Math.round(y / tolerance) * tolerance; seq.setOrdinate(i, 0, x); seq.setOrdinate(i, 1, y); } });
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 void assertTolerance(CoordinateSequence cs, double tolerance) { double[] ordinates = new double[cs.size() * 2]; for (int i = 0; i < cs.size(); i++) { ordinates[i * 2] = cs.getOrdinate(i, 0); ordinates[i * 2 + 1] = cs.getOrdinate(i, 1); } assertTolerance(ordinates, tolerance); }
@Test public void testLiteToStandard() throws Exception { LiteCoordinateSequence cs = new LiteCoordinateSequence(1, 2); cs.setArray(new double[] {1000000, 4000000}); CoordinateReferenceSystem sourceCrs = CRS.parseWKT(JTSTest.UTM_ZONE_10N); CoordinateReferenceSystem destCrs = DefaultGeographicCRS.WGS84; DefaultCoordinateSequenceTransformer cst; cst = new DefaultCoordinateSequenceTransformer(/* standard cs factory */ ); MathTransform tx = CRS.findMathTransform(sourceCrs, destCrs, true); CoordinateSequence transformed = cst.transform(cs, tx); CoordinateSequence reference = transform(cs, tx); assertEquals(reference.getOrdinate(0, 0), transformed.getOrdinate(0, 0), 0.0); assertEquals(reference.getOrdinate(0, 1), transformed.getOrdinate(0, 1), 0.0); }
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); }
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); } }