private URL getBanoGeocoderUrl(String address, Envelope bbox) throws IOException { UriBuilder uriBuilder = UriBuilder.fromUri(BANO_URL); uriBuilder.queryParam("q", address); uriBuilder.queryParam("limit", CLAMP_RESULTS); if (bbox != null) { uriBuilder.queryParam("lat", bbox.centre().y); uriBuilder.queryParam("lon", bbox.centre().x); } URI uri = uriBuilder.build(); return new URL(uri.toString()); } }
void matchAspect() { /* Basic sinusoidal projection of lat/lon data to square pixels */ double yCenter = modelBounds.centre().y; float xScale = cos(radians((float) yCenter)); double newX = modelBounds.getHeight() * (1 / xScale) * ((float) this.getWidth() / this.getHeight()); modelBounds.expandBy((newX - modelBounds.getWidth()) / 2f, 0); }
public Coordinate getCentre() { return extent.centre(); }
public void setEnvelope(Envelope env) { this.width = env.getWidth(); this.height = env.getHeight(); this.base = new Coordinate(env.getMinX(), env.getMinY()); this.centre = new Coordinate(env.centre()); }
public Coordinate getCentre() { return extent.centre(); }
public static Coordinate getCenter(Geometry g) { return g.getEnvelopeInternal().centre(); }
public static Coordinate getCenter(Geometry g) { return g.getEnvelopeInternal().centre(); }
/** * Create the OSM map link based on the bounding box of the geometry. * * @param geom the input geometry. * @param withMarker true to place a marker on the center of the BBox. * @return */ public static String generateLink(Geometry geom, boolean withMarker) { if (geom == null) { return null; } Envelope env = geom.getEnvelopeInternal(); StringBuilder sb = new StringBuilder("http://www.openstreetmap.org/?"); sb.append("minlon=").append(env.getMinX()); sb.append("&minlat=").append(env.getMinY()); sb.append("&maxlon=").append(env.getMaxX()); sb.append("&maxlat=").append(env.getMaxY()); if (withMarker) { Coordinate centre = env.centre(); sb.append("&mlat=").append(centre.y); sb.append("&mlon=").append(centre.x); } return sb.toString(); } }
public void setEnvelope(Envelope env) { this.width = env.getWidth(); this.height = env.getHeight(); this.base = new Coordinate(env.getMinX(), env.getMinY()); this.centre = new Coordinate(env.centre()); }
/** * Create the OSM map link based on the bounding box of the geometry. * * @param geom the input geometry. * @param withMarker true to place a marker on the center of the BBox. * @return */ public static String generateLink(Geometry geom, boolean withMarker) { if (geom == null) { return null; } Envelope env = geom.getEnvelopeInternal(); StringBuilder sb = new StringBuilder("http://www.openstreetmap.org/?"); sb.append("minlon=").append(env.getMinX()); sb.append("&minlat=").append(env.getMinY()); sb.append("&maxlon=").append(env.getMaxX()); sb.append("&maxlat=").append(env.getMaxY()); if (withMarker) { Coordinate centre = env.centre(); sb.append("&mlat=").append(centre.y); sb.append("&mlon=").append(centre.x); } return sb.toString(); } }
/** * Rotates a geometry by a given angle (in radians) about the center * of the geometry's envelope. * * @param geom Geometry * @param theta Angle * @return The geometry rotated about the center of its envelope */ public static Geometry rotate(Geometry geom, double theta) { if (geom != null) { Coordinate center = geom.getEnvelopeInternal().centre(); return rotate(geom, theta, center.x, center.y); } else { return null; } }
/** * Rotates a geometry by a given angle (in radians) about the center * of the geometry's envelope. * * @param geom Geometry * @param theta Angle * @return The geometry rotated about the center of its envelope */ public static Geometry rotate(Geometry geom, double theta) { if (geom != null) { Coordinate center = geom.getEnvelopeInternal().centre(); return rotate(geom, theta, center.x, center.y); } else { return null; } }
public @Test void testCollapse() { final Envelope deepestQuadBounds = support.quadBounds(NE, NE, NE, NE); final Envelope point = new Envelope(deepestQuadBounds.centre()); System.err.println(deepestQuadBounds); System.err.println(point); }
@Override public void handleWay(Way line, List<Point> coords) { Envelope bbox = new Envelope(); for (Point p : coords) { bbox.expandToInclude(p.getEnvelopeInternal()); } Coordinate centre = bbox.centre(); TileNumber tileNumber = getTileNumber(centre.y, centre.x, this.lvl); OSMXMLWriter writer = getWriter(tileNumber); writeWayNodes(coords, writer); writer.writeWay(line.id, line.nodes, line.tags); }
public void writePlacemarkPoint(final Envelope envelope, final String name, final String styleUrl) { startTag(PLACEMARK); if (name != null) { element(NAME, name); } if (styleUrl != null) { element(STYLE_URL, styleUrl); } startTag(POINT); startTag(COORDINATES); final Coordinate centre = envelope.centre(); write(Double.toString(centre.x)); write(','); write(Double.toString(centre.y)); endTag(); endTag(); endTag(); }
public @Test void testComputeQuadrantPointOnQuadEdge() { Envelope quadBounds = new Envelope(testMaxBounds); for (int depthIndex = 0; depthIndex < testMaxDepth; depthIndex++) { Envelope centerPoint = new Envelope(quadBounds.centre()); // the point is at the exact center of the quad.The evaluation is performed in // clockwise order so SW should win assertEquals(SW, quad.computeQuadrant(centerPoint, depthIndex)); Envelope middleEastPoint = new Envelope(quadBounds.getMaxX(), quadBounds.getMaxX(), quadBounds.centre().y, quadBounds.centre().y); // the point is the eastmost shared point between NE and SE. NE should win assertEquals(NE, quad.computeQuadrant(middleEastPoint, depthIndex)); quadBounds = SW.slice(quadBounds); } }
public static int findMaxDepth(Envelope maxBounds, final int absoluteMaxDepth) { // choose the quad that tends to the biggest abs value maxBounds = Node.makePrecise(maxBounds); final Quadrant testQuad = findBiggestMagnitudeQuad(maxBounds); Envelope parent = new Envelope(maxBounds); Envelope child = new Envelope(); Envelope float32Center = new Envelope(); for (int d = 0; d < absoluteMaxDepth; d++) { testQuad.slice(parent, child); Coordinate center = child.centre(); toFloat32(center, float32Center); if (!child.contains(float32Center)) { return d; } parent.init(child); } return absoluteMaxDepth; }
/** * Sets the scale denominator, the Map extent is updated * @param denominator */ public void setScaleDenominator(double denominator) { if (!adjustedExtent.isNull()) { double currentScale = getScaleDenominator(); Coordinate center = getExtent().centre(); double expandFactor = (denominator/currentScale); Envelope nextScaleEnvelope = new Envelope(center); nextScaleEnvelope.expandBy(expandFactor*getExtent().getWidth()/2.,expandFactor*getExtent().getHeight()/2.); setExtent(nextScaleEnvelope); } } /**
public Envelope getQuadCenter(Quadrant... quadrants) { Envelope quadBounds = getMaxBounds(); if (quadrants != null) { for (Quadrant quad : quadrants) { quadBounds = quad.slice(quadBounds); } } Coordinate center = quadBounds.centre(); Envelope nodeBounds = Node.makePrecise(new Envelope(center)); if (!quadBounds.contains(nodeBounds)) { GeometryFactory gf = new GeometryFactory(); Polygon qgeom = JTS.toGeometry(quadBounds, gf); ArrayList<Geometry> pointGeoms = Lists.newArrayList(gf.createPoint(center), JTS.toGeometry(nodeBounds, gf)); Geometry point = gf.buildGeometry(pointGeoms); String msg = qgeom + " does not contain " + point; Assert.fail(msg); } return nodeBounds; }
private void testSliceMaxDepth(final Envelope maxBounds) { final int maxDepth = Quadrant.findMaxDepth(maxBounds, ABSOLUTE_MAX_DEPTH); Envelope parent = Node.makePrecise(maxBounds); Envelope[] qbounds; for (int d = 0; d < maxDepth; d++) { qbounds = assertSlice(parent); Envelope sw = qbounds[0]; Envelope minimalEnv = Node.makePrecise(new Envelope(sw.centre())); assertTrue("at index " + d, sw.contains(minimalEnv)); parent = sw; } }