/** * Compact an elevation profile onto a var-len int packed form (Dlugosz coding). * * @param profile The elevation profile to compact * @return The compacted format */ public static byte[] compactElevationProfile(CoordinateSequence elevation) { if (elevation == null) return null; int oix = 0; int oiy = 0; int[] coords = new int[elevation.size() * 2]; for (int i = 0; i < elevation.size(); i++) { /* * Note: We should do the rounding *before* the delta to prevent rounding errors from * accumulating on long line strings. */ Coordinate c = elevation.getCoordinate(i); int ix = (int) Math.round(c.x * FIXED_FLOAT_MULT); int iy = (int) Math.round(c.y * FIXED_FLOAT_MULT); int dix = ix - oix; int diy = iy - oiy; coords[i * 2] = dix; coords[i * 2 + 1] = diy; oix = ix; oiy = iy; } return DlugoszVarLenIntPacker.pack(coords); }
private static double[] getLengthsFromElevation(CoordinateSequence elev) { double trueLength = 0; double flatLength = 0; double lastX = elev.getX(0); double lastY = elev.getY(0); for (int i = 1; i < elev.size(); ++i) { Coordinate c = elev.getCoordinate(i); double x = c.x - lastX; double y = c.y - lastY; trueLength += Math.sqrt(x * x + y * y); flatLength += x; lastX = c.x; lastY = c.y; } return new double[] { trueLength, flatLength }; }
private static int checkRepeatedPoints2d(LineString lineString) { int repeatedPoints = 0; final CoordinateSequence coordSeq = lineString.getCoordinateSequence(); Coordinate nextCoord = null, prevCoord; for(int i = 0; i < coordSeq.size(); ++i) { prevCoord = nextCoord; nextCoord = coordSeq.getCoordinate(i); if(nextCoord.equals(prevCoord)) { ++repeatedPoints; } } return repeatedPoints; } }
@Override public int hashCode() { CoordinateSequence cs = ls.getCoordinateSequence(); int maxIdx = cs.size() - 1; int x = (int) (cs.getX(0) * 1000000) + (int) (cs.getX(maxIdx) * 1000000); int y = (int) (cs.getY(0) * 1000000) + (int) (cs.getY(maxIdx) * 1000000); return x + y * 101149 + maxIdx * 7883; }
return coordSeq.size() == 1 ? geomFactory.createPoint(coordSeq) : geomFactory.createMultiPoint(coordSeq);
nextCoord = nextCoordSeq.getCoordinate(nextCoordSeq.size() - 1); nextCoord.setOrdinate(0, nextCoordSeq.getOrdinate(0, 0)); nextCoord.setOrdinate(1, nextCoordSeq.getOrdinate(0, 1));
public double distanceToEnd() { CoordinateSequence cs = ( (LineString)(edge.getGeometry()) ).getCoordinateSequence(); int s = seg + 1; double x0 = cs.getX(s); double y0 = cs.getY(s); double dist = SphericalDistanceLibrary.fastDistance(y0, x0, y, x); // dist along partial segment int nc = cs.size(); for (; s < nc; s++) { double x1 = cs.getX(s); double y1 = cs.getY(s); dist += SphericalDistanceLibrary.fastDistance(y0, x0, y1, x1); x0 = x1; y0 = y1; } return dist; } }
/** * Reverses the coordinates in a sequence in-place. */ public static void reverse(CoordinateSequence seq) { int last = seq.size() - 1; int mid = last / 2; for (int i = 0; i <= mid; i++) { swap(seq, i, last - i); } }
int numCoords = coordSeq.size(); for (int seg = 0; seg < numCoords - 1; seg++) { c.seg = seg;
private void init(CoordinateSequence points) { if (points == null) { points = getFactory().getCoordinateSequenceFactory().create(new Coordinate[]{}); } if (points.size() == 1) { throw new IllegalArgumentException("Invalid number of points in LineString (found " + points.size() + " - must be 0 or >= 2)"); } this.points = points; } public Coordinate[] getCoordinates() {
private void validateConstruction() { if (!isEmpty() && ! super.isClosed()) { throw new IllegalArgumentException("Points of LinearRing do not form a closed linestring"); } if (getCoordinateSequence().size() >= 1 && getCoordinateSequence().size() < MINIMUM_VALID_SIZE) { throw new IllegalArgumentException("Invalid number of points in LinearRing (found " + getCoordinateSequence().size() + " - must be 0 or >= 4)"); } }
public void apply(CoordinateFilter filter) { for (int i = 0; i < points.size(); i++) { filter.filter(points.getCoordinate(i)); } }
public OctagonalEnvelope expandToInclude(CoordinateSequence seq) { for (int i = 0; i < seq.size(); i++) { double x = seq.getX(i); double y = seq.getY(i); expandToInclude(x, y); } return this; }
private void writePoint(Point pt, OutStream os) throws IOException { if (pt.getCoordinateSequence().size() == 0) throw new IllegalArgumentException("Empty Points cannot be represented in WKB"); writeByteOrder(os); writeGeometryType(WKBConstants.wkbPoint, pt, os); writeCoordinateSequence(pt.getCoordinateSequence(), false, os); }
public static CoordinateSequence extend(CoordinateSequenceFactory fact, CoordinateSequence seq, int size) { CoordinateSequence newseq = fact.create(size, seq.getDimension()); int n = seq.size(); copy(seq, 0, newseq, 0, n); // fill remaining coordinates with end point, if it exists if (n > 0) { for (int i = n; i < size; i++) copy(seq, n-1, newseq, i, 1); } return newseq; }
private void init(CoordinateSequence coordinates) { if (coordinates == null) { coordinates = getFactory().getCoordinateSequenceFactory().create(new Coordinate[]{}); } Assert.isTrue(coordinates.size() <= 1); this.coordinates = coordinates; }