use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class TileRendererManager method renderTile.
public BufferedImage renderTile(final TileRequest tileRequest, String layer) {
TileRenderContext context = new TileRenderContext() {
@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;
}
};
context.graph = graph;
TileRenderer renderer = renderers.get(layer);
if (renderer == null)
throw new IllegalArgumentException("Unknown layer: " + layer);
// The best place for caching tiles may be here
BufferedImage image = new BufferedImage(tileRequest.width, tileRequest.height, renderer.getColorModel());
context.graphics = image.createGraphics();
Envelope2D trbb = tileRequest.bbox;
context.bbox = new Envelope(trbb.x, trbb.x + trbb.width, trbb.y, trbb.y + trbb.height);
context.transform = new AffineTransformation();
double xScale = tileRequest.width / trbb.width;
double yScale = tileRequest.height / trbb.height;
context.transform.translate(-trbb.x, -trbb.y - trbb.height);
context.transform.scale(xScale, -yScale);
context.metersPerPixel = Math.toRadians(trbb.height) * 6371000 / tileRequest.height;
context.tileWidth = tileRequest.width;
context.tileHeight = tileRequest.height;
long start = System.currentTimeMillis();
renderer.renderTile(context);
LOG.debug("Rendered tile at {},{} in {} ms", tileRequest.bbox.y, tileRequest.bbox.x, System.currentTimeMillis() - start);
return image;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class HashGridTest method testHashGridRandom.
/**
* We perform a non-regression random test. We insert many random-envelop objects
* into both a hash grid (OTP) and STRtree (JTS) spatial indexes. We check with
* many random query that the set of returned objects is the same (after pruning
* because both could return false positives).
*/
@SuppressWarnings("unchecked")
public void testHashGridRandom() {
final double X0 = -0.05;
final double Y0 = 44.0;
final double DX = 0.1;
final double DY = 0.1;
final int N_OBJS = 1000;
final int N_QUERIES = 1000;
Random rand = new Random(42);
SpatialIndex hashGrid = new HashGridSpatialIndex<>();
SpatialIndex strTree = new STRtree();
for (int i = 0; i < N_OBJS; i++) {
Coordinate a = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
Coordinate b = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
DummyObject obj = new DummyObject();
obj.envelope = new Envelope(a, b);
hashGrid.insert(obj.envelope, obj);
strTree.insert(obj.envelope, obj);
}
for (int i = 0; i < N_QUERIES; i++) {
Coordinate a = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
Coordinate b = new Coordinate(rand.nextDouble() * DX + X0, rand.nextDouble() * DY + Y0);
Envelope searchEnv = new Envelope(a, b);
List<DummyObject> hashGridObjs = hashGrid.query(searchEnv);
// Need to remove non intersecting
Set<DummyObject> hashGridObjs2 = new HashSet<>();
for (DummyObject obj : hashGridObjs) {
if (obj.envelope.intersects(searchEnv))
hashGridObjs2.add(obj);
}
List<DummyObject> strtreeObjs = hashGrid.query(searchEnv);
// Need to remove non intersecting
Set<DummyObject> strtreeObjs2 = new HashSet<>();
for (DummyObject obj : strtreeObjs) {
if (obj.envelope.intersects(searchEnv))
strtreeObjs2.add(obj);
}
boolean equals = hashGridObjs2.equals(strtreeObjs2);
assertTrue(equals);
}
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class ShowGraph method mouseClicked.
@SuppressWarnings("unchecked")
public void mouseClicked() {
Envelope screenEnv = new Envelope(new Coordinate(mouseX, mouseY));
screenEnv.expandBy(4, 4);
Envelope env = new Envelope(toModelX(screenEnv.getMinX()), toModelX(screenEnv.getMaxX()), toModelY(screenEnv.getMinY()), toModelY(screenEnv.getMaxY()));
List<Vertex> nearby = (List<Vertex>) vertexIndex.query(env);
selector.verticesSelected(nearby);
drawLevel = DRAW_ALL;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class ShowGraph method zoomToVertex.
public void zoomToVertex(Vertex v) {
Envelope e = new Envelope();
e.expandToInclude(v.getCoordinate());
e.expandBy(0.002);
modelBounds = e;
drawLevel = DRAW_ALL;
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class ShowGraph method zoomToLocation.
public void zoomToLocation(Coordinate c) {
Envelope e = new Envelope();
e.expandToInclude(c);
e.expandBy(0.002);
modelBounds = e;
matchAspect();
drawLevel = DRAW_ALL;
}
Aggregations