use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class GeocoderServerTest method testGeocodeValidAddress.
@Test
public void testGeocodeValidAddress() {
final double lat = 78.121;
final double lng = -43.237;
final String description = "121 elm street";
geocoderServer.geocoder = new Geocoder() {
@Override
public GeocoderResults geocode(String address, Envelope bbox) {
GeocoderResult result = new GeocoderResult(lat, lng, description);
return new GeocoderResults(Arrays.asList(result));
}
};
GeocoderResults results = geocoderServer.geocode("121 elm street", null);
for (GeocoderResult result : results.getResults()) {
// should only have one result
assertEquals("description matches", description, result.getDescription());
assertEquals(lat, result.getLat(), 0.001);
assertEquals(lng, result.getLng(), 0.001);
}
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class ShowGraph method buildSpatialIndex.
/*
* Iterate through all vertices and their (outgoing) edges. If they are of 'interesting' types,
* add them to the corresponding spatial index.
*/
public synchronized void buildSpatialIndex() {
vertexIndex = new STRtree();
edgeIndex = new STRtree();
Envelope env;
// int xminx, xmax, ymin, ymax;
for (Vertex v : graph.getVertices()) {
Coordinate c = v.getCoordinate();
env = new Envelope(c);
vertexIndex.insert(env, v);
for (Edge e : v.getOutgoing()) {
if (e.getGeometry() == null)
continue;
if (e instanceof PatternEdge || e instanceof StreetTransitLink || e instanceof StreetEdge || e instanceof PathwayEdge || e instanceof SimpleTransfer) {
env = e.getGeometry().getEnvelopeInternal();
edgeIndex.insert(env, e);
}
}
}
vertexIndex.build();
edgeIndex.build();
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class ShowGraph method setup.
/*
* Setup Processing applet
*/
public void setup() {
size(getSize().width, getSize().height, P2D);
/* Build spatial index of vertices and edges */
buildSpatialIndex();
/* Set model bounds to encompass all vertices in the index, and then some */
modelBounds = (Envelope) (vertexIndex.getRoot().getBounds());
modelBounds.expandBy(0.02);
matchAspect();
/* save this zoom level to allow returning to default later */
modelOuterBounds = new Envelope(modelBounds);
/* find and set up the appropriate font */
String[] fonts = PFont.list();
String[] preferredFonts = { "Mono", "Courier" };
PFont font = null;
for (String preferredFontName : preferredFonts) {
for (String fontName : fonts) {
if (fontName.contains(preferredFontName)) {
font = createFont(fontName, 16);
break;
}
}
if (font != null) {
break;
}
}
textFont(font);
textMode(SCREEN);
addMouseWheelListener(this);
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
Point p = e.getPoint();
mouseModelX = toModelX(p.x);
mouseModelY = toModelY(p.y);
}
});
addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
matchAspect();
drawLevel = DRAW_PARTIAL;
}
});
frameRate(FRAME_RATE);
}
use of com.vividsolutions.jts.geom.Envelope in project OpenTripPlanner by opentripplanner.
the class ShowGraph method drawAnotation.
public void drawAnotation(GraphBuilderAnnotation anno) {
Envelope env = new Envelope();
Edge e = anno.getReferencedEdge();
if (e != null) {
this.enqueueHighlightedEdge(e);
env.expandToInclude(e.getFromVertex().getCoordinate());
env.expandToInclude(e.getToVertex().getCoordinate());
}
ArrayList<Vertex> vertices = new ArrayList<Vertex>();
Vertex v = anno.getReferencedVertex();
if (v != null) {
env.expandToInclude(v.getCoordinate());
vertices.add(v);
}
if (e == null && v == null)
return;
// make it a little bigger, especially needed for STOP_UNLINKED
env.expandBy(0.02);
// highlight relevant things
this.clearHighlights();
this.setHighlightedVertices(vertices);
// zoom the graph display
this.zoomToEnvelope(env);
// and draw
this.draw();
}
use of com.vividsolutions.jts.geom.Envelope in project GeoGig by boundlessgeo.
the class LsTree method runInternal.
@Override
public void runInternal(final GeogigCLI cli) throws IOException {
String ref;
if (refList.isEmpty()) {
ref = null;
} else {
ref = refList.get(0);
}
Strategy lsStrategy = Strategy.CHILDREN;
if (recursive) {
if (includeTrees) {
lsStrategy = Strategy.DEPTHFIRST;
} else if (onlyTrees) {
lsStrategy = Strategy.DEPTHFIRST_ONLY_TREES;
} else {
lsStrategy = Strategy.DEPTHFIRST_ONLY_FEATURES;
}
} else {
if (onlyTrees) {
lsStrategy = Strategy.TREES_ONLY;
}
}
Iterator<NodeRef> iter = cli.getGeogig().command(LsTreeOp.class).setReference(ref).setStrategy(lsStrategy).call();
final ConsoleReader console = cli.getConsole();
Function<NodeRef, CharSequence> printFunctor = new Function<NodeRef, CharSequence>() {
@Override
public CharSequence apply(NodeRef input) {
StringBuilder sb = new StringBuilder();
if (!verbose) {
sb.append(input.path());
} else {
Envelope env = new Envelope();
input.getNode().expand(env);
StringBuilder sbenv = new StringBuilder();
sbenv.append(Double.toString(env.getMinX())).append(";").append(Double.toString(env.getMaxX())).append(";").append(Double.toString(env.getMinY())).append(";").append(Double.toString(env.getMaxY()));
sb.append(input.getMetadataId().toString()).append(' ').append(input.getType().toString().toLowerCase()).append(' ').append(input.objectId().toString()).append(' ').append(input.path()).append(' ').append(sbenv);
if (input.getType().equals(TYPE.TREE)) {
RevTree tree = cli.getGeogig().command(RevObjectParse.class).setObjectId(input.objectId()).call(RevTree.class).get();
sb.append(' ').append(tree.size()).append(' ').append(tree.numTrees());
}
}
return sb;
}
};
Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);
while (lines.hasNext()) {
console.println(lines.next());
}
console.flush();
}
Aggregations