@Override public void newPoint(final double x, final double y) { this.currCoordSeq.setOrdinate(this.currPointNo, 0, x); this.currCoordSeq.setOrdinate(this.currPointNo, 1, y); currPointNo++; if (currPointNo == this.currPartNumPoints) { this.subparts[this.subPartNo] = gf.createLinearRing(this.currCoordSeq); } } }
/** * Builds a linear ring representing the clipping area * * @param gf * @param csf * @return */ LinearRing buildBoundsString(final GeometryFactory gf, final CoordinateSequenceFactory csf) { CoordinateSequence cs = JTS.createCS(csf, 5, 2); cs.setOrdinate(0, 0, xmin); cs.setOrdinate(0, 1, ymin); cs.setOrdinate(1, 0, xmin); cs.setOrdinate(1, 1, ymax); cs.setOrdinate(2, 0, xmax); cs.setOrdinate(2, 1, ymax); cs.setOrdinate(3, 0, xmax); cs.setOrdinate(3, 1, ymin); cs.setOrdinate(4, 0, xmin); cs.setOrdinate(4, 1, ymin); return gf.createLinearRing(cs); }
List<Polygon> getFaces(GeometryFactory gf, double extrude) { // sort the segments from bottom to top Collections.sort(segments); // extrude each segment List<Polygon> result = new ArrayList<Polygon>(); for (Segment segment : segments) { CoordinateSequence cs = JTS.createCS(gf.getCoordinateSequenceFactory(), 5, 2); cs.setOrdinate(0, 0, segment.x0); cs.setOrdinate(0, 1, segment.y0); cs.setOrdinate(3, 0, segment.x0); cs.setOrdinate(3, 1, segment.y0 + extrude); cs.setOrdinate(2, 0, segment.x1); cs.setOrdinate(2, 1, segment.y1 + extrude); cs.setOrdinate(1, 0, segment.x1); cs.setOrdinate(1, 1, segment.y1); cs.setOrdinate(4, 0, segment.x0); cs.setOrdinate(4, 1, segment.y0); result.add(gf.createPolygon(gf.createLinearRing(cs), null)); } return result; } }
/** Converts the ordinate into a coordinate sequence */ public CoordinateSequence toCoordinateSequence(CoordinateSequenceFactory csfac) { CoordinateSequence cs = JTS.createCS(csfac, size(), 3); for (int i = 0; i <= curr; i++) { cs.setOrdinate(i, 0, ordinates[i * 2]); cs.setOrdinate(i, 1, ordinates[i * 2 + 1]); } return cs; }
@Override public void reset(double x, double y) { assert ! isEmpty(); CoordinateSequence cSeq = pointGeom.getCoordinateSequence(); cSeq.setOrdinate(0, CoordinateSequence.X, x); cSeq.setOrdinate(0, CoordinateSequence.Y, y); }
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 void filter(CoordinateSequence seq, int i) { seq.setOrdinate(i, ordinateIndex, seq.getOrdinate(i, ordinateIndex) + offset); }
public Object read(ByteBuffer buffer, ShapeType type, boolean flatGeometry) { if (type == ShapeType.NULL) { return createNull(); } int dimension = shapeType == ShapeType.POINTZ && !flatGeometry ? 3 : 2; CoordinateSequence cs = JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), 1, dimension); cs.setOrdinate(0, 0, buffer.getDouble()); cs.setOrdinate(0, 1, buffer.getDouble()); if (shapeType == ShapeType.POINTM) { buffer.getDouble(); } if (dimension > 2) { cs.setOrdinate(0, 2, buffer.getDouble()); } return geometryFactory.createPoint(cs); }
/** * @param buffer * @param numPoints */ private CoordinateSequence readCoordinates( final ByteBuffer buffer, final int numPoints, final int dimensions) { CoordinateSequence cs = JTS.createCS(geometryFactory.getCoordinateSequenceFactory(), numPoints, dimensions); DoubleBuffer dbuffer = buffer.asDoubleBuffer(); double[] ordinates = new double[numPoints * 2]; dbuffer.get(ordinates); for (int t = 0; t < numPoints; t++) { cs.setOrdinate(t, 0, ordinates[t * 2]); cs.setOrdinate(t, 1, ordinates[t * 2 + 1]); } if (dimensions > 2) { // z dbuffer.position(dbuffer.position() + 2); dbuffer.get(ordinates, 0, numPoints); for (int t = 0; t < numPoints; t++) { cs.setOrdinate(t, 2, ordinates[t]); } } return cs; }
/** * 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)); } } }
/** * Turns the array of ordinates into a coordinate sequence * * @param gf * @return */ public CoordinateSequence toCoordinateSequence(GeometryFactory gf) { double[] data = getData(); CoordinateSequence cs = JTS.createCS(gf.getCoordinateSequenceFactory(), data.length / 2, 2); for (int i = 0; i < cs.size(); i++) { cs.setOrdinate(i, 0, data[i * 2]); cs.setOrdinate(i, 1, data[i * 2 + 1]); } return cs; }
@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); } }
@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); } });
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; }
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; }
@Override public void filter(CoordinateSequence seq, int i) { double x = seq.getX(i); double y = seq.getY(i); //Note: we don't simply call ctx.normX & normY because // those methods use the precisionModel, but WKTReader already // used the precisionModel. It's be nice to turn that off somehow but alas. if (ctx.isGeo() && ctx.isNormWrapLongitude()) { double xNorm = DistanceUtils.normLonDEG(x); if (Double.compare(x, xNorm) != 0) {//handles NaN changed = true; seq.setOrdinate(i, CoordinateSequence.X, xNorm); } // double yNorm = DistanceUtils.normLatDEG(y); // if (y != yNorm) { // changed = true; // seq.setOrdinate(i,CoordinateSequence.Y,yNorm); // } } ctx.verifyX(x); ctx.verifyY(y); }
private static void transformGeometry(Geometry geometry) { if (geometry == null) { return; } if (geometry instanceof GeometryCollection) { GeometryCollection collection = (GeometryCollection) geometry; for (int i = 0; i < collection.getNumGeometries(); i++) { transformGeometry(collection.getGeometryN(i)); } } else if (geometry instanceof Polygon) { Polygon polygon = (Polygon) geometry; transformGeometry(polygon.getExteriorRing()); for (int i = 0; i < polygon.getNumInteriorRing(); i++) { transformGeometry(polygon.getInteriorRingN(i)); } } else if (geometry instanceof LineString) { CoordinateSequence cs = ((LineString) geometry).getCoordinateSequence(); for (int i = 0; i < cs.size(); i++) { cs.setOrdinate(i, 0, (int) (cs.getOrdinate(i, 0) + 0.5d)); cs.setOrdinate(i, 1, (int) (cs.getOrdinate(i, 1) + 0.5d)); } } geometry.geometryChanged(); }
/** * Does what it says, reverses the order of the Coordinates in the ring. * * <p>This is different then lr.reverses() in that a copy is produced using a new coordinate * sequence. * * @param lr The ring to reverse. * @return A new ring with the reversed Coordinates. */ public static final LinearRing reverseRing(LinearRing lr) { GeometryFactory gf = lr.getFactory(); CoordinateSequenceFactory csf = gf.getCoordinateSequenceFactory(); CoordinateSequence csOrig = lr.getCoordinateSequence(); int numPoints = csOrig.size(); int dimensions = csOrig.getDimension(); CoordinateSequence csNew = JTS.createCS(csf, numPoints, dimensions, csOrig.getMeasures()); for (int i = 0; i < numPoints; i++) { for (int j = 0; j < dimensions; j++) { csNew.setOrdinate(numPoints - 1 - i, j, csOrig.getOrdinate(i, j)); } } return gf.createLinearRing(csNew); }
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); }