/** project this linestring to an equirectangular projection */ private static LineString equirectangularProject(LineString geometry, double xscale) { Coordinate[] coords = new Coordinate[geometry.getNumPoints()]; for (int i = 0; i < coords.length; i++) { Coordinate c = geometry.getCoordinateN(i); c = (Coordinate) c.clone(); c.x *= xscale; coords[i] = c; } return geometryFactory.createLineString(coords); }
@Override public boolean filter(Individual individual) { Coordinate coord = new Coordinate(individual.lon, individual.lat); Point pt = gf.createPoint(coord); boolean accept = hull.contains(pt); //LOG.debug("label {} accept {}", individual.label, accept); return accept; }
public boolean matchesBackward(CoordinateSequence cs0, CoordinateSequence cs1) { if (cs0.size() != cs1.size()) return false; int maxIdx = cs0.size() - 1; for (int i = 0; i <= maxIdx; i++) if (!cs0.getCoordinate(i).equals(cs1.getCoordinate(maxIdx - i))) return false; return true; }
/** * Creates a circle shape, using the JTS buffer algorithm. The method is used when there is no street found within the given traveltime, e.g. when * the pointer is placed on a field or in the woods.<br> * TODO: Note it is actually not correct to do buffer calculation in Euclidian 2D, since the resulting shape will be elliptical when projected. * * @param dropPoint the location given by the user * @param pathToStreet the path from the dropPoint to the street, used to retrieve the buffer distance * @return a Circle */ private Geometry createCirle(Coordinate dropPoint, LineString pathToStreet) { double length = pathToStreet.getLength(); GeometryFactory gf = new GeometryFactory(); Point dp = gf.createPoint(dropPoint); Geometry buffer = dp.buffer(length); return buffer; }
/** * Returns this as a Coordinate object. * @return */ public Coordinate getCoordinate() { if (this.lat == null || this.lng == null) { return null; } return new Coordinate(this.lng, this.lat); }
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; } }
private Geometry crudeProjectedBuffer(Point pt, double distanceMeters) { final double mPerDegreeLat = 111111.111111; double lat = pt.getY(); double lonScale = Math.cos(Math.PI * lat / 180); double latExpand = distanceMeters / mPerDegreeLat; double lonExpand = latExpand / lonScale; Envelope env = pt.getEnvelopeInternal(); env.expandBy(lonExpand, latExpand); return gf.toGeometry(env); }
public static LinearLocation getEndLocation(Geometry linear) { //the version in LinearLocation is broken int lastComponentIndex = linear.getNumGeometries() - 1; LineString lastLine = (LineString) linear.getGeometryN(lastComponentIndex); int lastSegmentIndex = lastLine.getNumPoints() - 1; return new LinearLocation(lastComponentIndex, lastSegmentIndex, 0.0); } }
@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; }
public Envelope expandEnvelope(Envelope env) { for (int i = 0; i < coords.length; i += dimension) { env.expandToInclude(coords[i], coords[i + 1]); } return env; } }
@Override public boolean accept(Geometry geometry) { boolean accept = true; if((geometry instanceof Polygon || geometry instanceof MultiPolygon) && geometry.getArea() < minArea) { accept = false; } else if((geometry instanceof LineString || geometry instanceof MultiLineString) && geometry.getLength() < minLength) { accept = false; } return accept; } }
private void loadCurrentLine() { if (componentIndex >= numLines) { currentLine = null; return; } currentLine = (LineString) linearGeom.getGeometryN(componentIndex); }
public boolean isValidIndex() { if (componentIndex >= numLines) return false; if (componentIndex == numLines - 1 && vertexIndex >= currentLine.getNumPoints()) return false; return true; }
/** * Gets the first {@link Coordinate} of the current segment. (the coordinate of the current * vertex). * * @return a {@link Coordinate} */ public Coordinate getSegmentStart() { return currentLine.getCoordinateN(vertexIndex); }
@Override public int compare(Polygon o1, Polygon o2) { return o2.getNumPoints() - o1.getNumPoints(); } });
/** * Return true if the values of the two {@link Coordinate} are equal when their * first and second ordinates are cast as ints. Ignores 3rd ordinate. * * @param a first coordinate to compare * @param b second coordinate to compare * @return true if the values of the two {@link Coordinate} are equal when their * first and second ordinates are cast as ints */ private static boolean equalAsInts2d(Coordinate a, Coordinate b) { return ((int)a.getOrdinate(0)) == ((int)b.getOrdinate(0)) && ((int)a.getOrdinate(1)) == ((int)b.getOrdinate(1)); }
/** * @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinate(int) */ public Coordinate getCoordinateInternal(int i) { double x = coords[i * dimension]; double y = coords[i * dimension + 1]; double z = dimension == 2 ? 0.0 : coords[i * dimension + 2]; return new Coordinate(x, y, z); }
public Envelope expandEnvelope(Envelope env) { for (int i = 0; i < coords.length; i += dimension) { env.expandToInclude(coords[i], coords[i + 1]); } return env; }
/** * @see com.vividsolutions.jts.geom.CoordinateSequence#getCoordinate(int) */ public Coordinate getCoordinateInternal(int i) { double x = coords[i * dimension]; double y = coords[i * dimension + 1]; double z = dimension == 2 ? 0.0 : coords[i * dimension + 2]; return new Coordinate(x, y, z); }
@Override public Envelope expandEnvelope(Envelope env) { for (Coordinate c : coordinates) { env.expandToInclude(c); } return env; }