@Override public Envelope expandPixels(double marginXPixels, double marginYPixels) { Envelope retval = new Envelope(bbox); retval.expandBy( marginXPixels / tileRequest.width * (bbox.getMaxX() - bbox.getMinX()), marginYPixels / tileRequest.height * (bbox.getMaxY() - bbox.getMinY())); return retval; } };
BikeRentalStationService bikeRentalService = graph.getService( BikeRentalStationService.class, true); Envelope envelope = new Envelope(); long osmId = area.parent.getId(); I18NString creativeName = wayPropertySet.getCreativeNameForWay(area.parent); for (Ring ring : area.outermostRings) { for (OSMNode node : ring.nodes) { envelope.expandToInclude(new Coordinate(node.lon, node.lat)); bikePark.x = (envelope.getMinX() + envelope.getMaxX()) / 2; bikePark.y = (envelope.getMinY() + envelope.getMaxY()) / 2; bikeRentalService.addBikePark(bikePark); BikeParkVertex bikeParkVertex = new BikeParkVertex(graph, bikePark);
public static PointSet regularGrid (Envelope envelope, double gridSizeMeters) { // non-ideal but for now make a grid in projected space // to see why this is wrong, look at a map of Iowa and note that it leans to the left // This is because they started surveying the township and range system (which is a grid) // from the east, and wound up further west in the north than the south, which led them // to resurvey the baseline every 24 miles, which explains why one is often driving // down a rural road in the midwestern US and comes to a point where the road makes two 90- // degree curves in quick succession to reach the new survey baseline. double gridSizeLat = SphericalDistanceLibrary.metersToDegrees(gridSizeMeters); double gridSizeLon = SphericalDistanceLibrary.metersToLonDegrees(gridSizeMeters, (envelope.getMaxY() + envelope.getMinY()) / 2); // how large will it be? int npts = (int) (envelope.getHeight() / gridSizeLat + 1) * (int) (envelope.getWidth() / gridSizeLon + 1); PointSet ret = new PointSet(npts); int idx = 0; for (double lon = envelope.getMinX(); lon < envelope.getMaxX(); lon += gridSizeLon) { for (double lat = envelope.getMinY(); lat < envelope.getMaxY(); lat += gridSizeLat) { PointFeature pf = new PointFeature("" + idx); pf.setLat(lat); pf.setLon(lon); ret.addFeature(pf, idx++); } } return ret; }
private URL getNominatimGeocoderUrl(String address, Envelope bbox) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(nominatimUrl); uriBuilder.queryParam("q", address); uriBuilder.queryParam("format", "json"); if (bbox != null) { uriBuilder.queryParam("viewbox", bbox.getMinX() + "," + bbox.getMinY() + "," + bbox.getMaxX() + "," + bbox.getMaxY()); uriBuilder.queryParam("bounded", 1); } else if (viewBox != null) { uriBuilder.queryParam("viewbox", viewBox); uriBuilder.queryParam("bounded", 1); } if (resultLimit != null) { uriBuilder.queryParam("limit", resultLimit); } if (emailAddress != null) { uriBuilder.queryParam("email", emailAddress); } URI uri = uriBuilder.build(); return new URL(uri.toString()); }
/** * Instantiates a new voronoi partitioning. * * @param samples the sample list * @param partitions the partitions * @throws Exception the exception */ public VoronoiPartitioning(List<Envelope> samples, int partitions) throws Exception { GeometryFactory fact = new GeometryFactory(); ArrayList<Point> subSampleList = new ArrayList<Point>(); MultiPoint mp; //Take a subsample accoring to the partitions for (int i = 0; i < samples.size(); i = i + samples.size() / partitions) { Envelope envelope = samples.get(i); Coordinate coordinate = new Coordinate((envelope.getMinX() + envelope.getMaxX()) / 2.0, (envelope.getMinY() + envelope.getMaxY()) / 2.0); subSampleList.add(fact.createPoint(coordinate)); } mp = fact.createMultiPoint(subSampleList.toArray(new Point[subSampleList.size()])); VoronoiDiagramBuilder voronoiBuilder = new VoronoiDiagramBuilder(); voronoiBuilder.setSites(mp); Geometry voronoiDiagram = voronoiBuilder.getDiagram(fact); for (int i = 0; i < voronoiDiagram.getNumGeometries(); i++) { Polygon poly = (Polygon) voronoiDiagram.getGeometryN(i); grids.add(poly.getEnvelopeInternal()); } //grids.add(new EnvelopeWithGrid(boundary,grids.size())); }
public ShapeValue(Envelope e) { GeometryFactory gFactory = new GeometryFactory(); Coordinate[] pts = { new Coordinate(e.getMinX(), e.getMinY()), new Coordinate(e.getMaxX(), e.getMinY()), new Coordinate(e.getMaxX(), e.getMaxY()), new Coordinate(e.getMinX(), e.getMaxY()), new Coordinate(e.getMinX(), e.getMinY()) }; value = gFactory.createPolygon(gFactory.createLinearRing(pts), null); }
public Polygon call(T spatialObject) { Double x1, x2, y1, y2; LinearRing linear; Coordinate[] coordinates = new Coordinate[5]; GeometryFactory fact = new GeometryFactory(); final Envelope envelope = spatialObject.getEnvelopeInternal(); x1 = envelope.getMinX(); x2 = envelope.getMaxX(); y1 = envelope.getMinY(); y2 = envelope.getMaxY(); coordinates[0] = new Coordinate(x1, y1); coordinates[1] = new Coordinate(x1, y2); coordinates[2] = new Coordinate(x2, y2); coordinates[3] = new Coordinate(x2, y1); coordinates[4] = coordinates[0]; linear = fact.createLinearRing(coordinates); Polygon polygonObject = new Polygon(linear, null, fact); return polygonObject; } });
/** * Creates an elliptical {@link Polygon}. * If the supplied envelope is square the * result will be a circle. * * @return an ellipse or circle */ public Polygon createEllipse() { Envelope env = dim.getEnvelope(); double xRadius = env.getWidth() / 2.0; double yRadius = env.getHeight() / 2.0; double centreX = env.getMinX() + xRadius; double centreY = env.getMinY() + yRadius; Coordinate[] pts = new Coordinate[nPts + 1]; int iPt = 0; for (int i = 0; i < nPts; i++) { double ang = i * (2 * Math.PI / nPts); double x = xRadius * Math.cos(ang) + centreX; double y = yRadius * Math.sin(ang) + centreY; pts[iPt++] = coord(x, y); } pts[iPt] = new Coordinate(pts[0]); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly); } /**
static public Polygon toPolygon(Envelope env, int SRID) { Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate(env.getMinX(), env.getMinY()); coords[1] = new Coordinate(env.getMinX(), env.getMaxY()); coords[2] = new Coordinate(env.getMaxX(), env.getMaxY()); coords[3] = new Coordinate(env.getMaxX(), env.getMinY()); coords[4] = new Coordinate(env.getMinX(), env.getMinY()); LinearRing shell = geomFactory.createLinearRing(coords); Polygon pg = geomFactory.createPolygon(shell, null); pg.setSRID(SRID); return pg; }
if (envelope.isNull()) { return createPoint((CoordinateSequence)null); if (envelope.getMinX() == envelope.getMaxX() && envelope.getMinY() == envelope.getMaxY()) { return createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY())); if (envelope.getMinX() == envelope.getMaxX() || envelope.getMinY() == envelope.getMaxY()) { return createLineString(new Coordinate[]{ new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()) }); return createPolygon(createLinearRing(new Coordinate[]{ new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMinY()) }), null);
/** * Computes and returns the area of validity for the given CoordinateReferenceSystem. * <p> * This method returns the prescribed area of validity for the CRS as computed by * {@link CRS#getEnvelope(CoordinateReferenceSystem)} with the exception that the following * {@code EPSG:900913} compatible CRS's return the GeoWebCache prescribed bounds so that they * align with Google Map tiles: {@code EPSG:900913, EPSG:3857, EPSG:3785}. * </p> * * @param coordSys * the CRS to compute the area of validity for * @return the aov for the CRS, or {@code null} if the CRS does not provide such information * (with the exception of EPSG:900913, see above). */ public ReferencedEnvelope getAreaOfValidity(final CoordinateReferenceSystem coordSys) { Geometry aovGeom = getAreaOfValidityAsGeometry(coordSys, gridSetBroker); if (aovGeom == null) { return null; } Envelope envelope = aovGeom.getEnvelopeInternal(); double x1 = envelope.getMinX(); double x2 = envelope.getMaxX(); double y1 = envelope.getMinY(); double y2 = envelope.getMaxY(); ReferencedEnvelope aov = new ReferencedEnvelope(coordSys); aov.init(x1, x2, y1, y2); return aov; }
/** * At zoom level zero, our coordinates are pixels in a single planetary tile, with coordinates are in the range * [0...256). We want to export with a conventional web Mercator envelope in meters. */ public ReferencedEnvelope getMercatorEnvelopeMeters() { Coordinate topLeft = mercatorPixelToMeters(west, north); Coordinate bottomRight = mercatorPixelToMeters(west + width, north + height); Envelope mercatorEnvelope = new Envelope(topLeft, bottomRight); try { // Get Spherical Mercator pseudo-projection CRS CoordinateReferenceSystem webMercator = CRS.decode("EPSG:3857"); ReferencedEnvelope env = new ReferencedEnvelope(mercatorEnvelope, webMercator); return env; } catch (Exception ex) { throw new RuntimeException(ex); } }
int nSide = nPts / 4; if (nSide < 1) nSide = 1; double XsegLen = dim.getEnvelope().getWidth() / nSide; double YsegLen = dim.getEnvelope().getHeight() / nSide; double x = env.getMinX() + i * XsegLen; double y = env.getMinY(); pts[ipt++] = coord(x, y); double x = env.getMaxX(); double y = env.getMinY() + i * YsegLen; pts[ipt++] = coord(x, y); double x = env.getMaxX() - i * XsegLen; double y = env.getMaxY(); pts[ipt++] = coord(x, y); double x = env.getMinX(); double y = env.getMaxY() - i * YsegLen; pts[ipt++] = coord(x, y); pts[ipt++] = new Coordinate(pts[0]); LinearRing ring = geomFact.createLinearRing(pts); Polygon poly = geomFact.createPolygon(ring, null); return (Polygon) rotate(poly);
protected LineString horizontalBisector(Geometry geometry) { Envelope envelope = geometry.getEnvelopeInternal(); // Assert: for areas, minx <> maxx double avgY = avg(envelope.getMinY(), envelope.getMaxY()); return factory.createLineString(new Coordinate[] { new Coordinate(envelope.getMinX(), avgY), new Coordinate(envelope.getMaxX(), avgY) }); }
/** * DOCUMENT ME! * * @param featureWriter DOCUMENT ME! * @param ft DOCUMENT ME! * * @throws IOException DOCUMENT ME! */ public void startFeature(SVGFeatureWriter featureWriter, SimpleFeature ft) throws IOException { handler.startFeature(featureWriter, ft); Geometry geom = (Geometry) ft.getDefaultGeometry(); Envelope env = geom.getEnvelopeInternal(); write(" bounds=\""); write(env.getMinX()); write(' '); write(env.getMinY()); write(' '); write(env.getMaxX()); write(' '); write(env.getMaxY()); write('\"'); } }
private STRtree buildSpatialIndex(SimpleFeatureCollection features) { STRtree spatialIndex = new STRtree(); SimpleFeatureIterator featureIter = features.features(); try { while (featureIter.hasNext()) { SimpleFeature feature = featureIter.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coordinate centroid = geometry.getCentroid().getCoordinate(); SpatialEvent event = new SpatialEvent(feature.getID(), centroid); spatialIndex.insert(new Envelope(centroid), event); featureCount++; } } finally { featureIter.close(); } return spatialIndex; } }
private ReferencedEnvelope transformEnvelope(CoordinateReferenceSystem fromCRS, CoordinateReferenceSystem toCRS, Rectangle2D bounds) { try { MathTransform transform = CRS.findMathTransform(fromCRS, toCRS); Envelope sourceEnvelope = new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY()); final Envelope envelope = JTS.transform(sourceEnvelope, transform); return new ReferencedEnvelope(envelope.getMinX(), envelope.getMaxX(), envelope.getMinY(), envelope.getMaxY(), toCRS); } catch (FactoryException | TransformException e) { e.printStackTrace(); return null; } }
SimpleFeatureIterator r = features(); try { Envelope newBBox = new Envelope(); Envelope internal; SimpleFeature feature; final Geometry geometry = ((Geometry)feature.getDefaultGeometry()); if(geometry != null) { internal = geometry.getEnvelopeInternal(); newBBox.expandToInclude(internal); return ReferencedEnvelope.reference(newBBox); } catch (Exception e) { throw new RuntimeException("Exception occurred while computing reprojected bounds",