use of aimax.osm.data.BoundingBox in project aima-java by aimacode.
the class KDTree method insertEntity.
/**
* Adds an entity at the right position in the tree and extends
* the tree if necessary. It is assumed that the entity contains
* view information.
*/
public void insertEntity(DefaultMapEntity entity) {
if (children == null) {
entities.add(entity);
isSorted = false;
if (entities.size() > maxEntities && depth < maxDepth) {
computeSplitValues();
BoundingBox c1bb;
BoundingBox c2bb;
if (splitAtLat) {
c1bb = new BoundingBox(bb.getLatMin(), bb.getLonMin(), splitValue, bb.getLonMax());
c2bb = new BoundingBox(splitValue, bb.getLonMin(), bb.getLatMax(), bb.getLonMax());
} else {
c1bb = new BoundingBox(bb.getLatMin(), bb.getLonMin(), bb.getLatMax(), splitValue);
c2bb = new BoundingBox(bb.getLatMin(), splitValue, bb.getLatMax(), bb.getLonMax());
}
children = new KDTree[2];
children[0] = new KDTree(c1bb, maxEntities, maxDepth, depth + 1);
children[1] = new KDTree(c2bb, maxEntities, maxDepth, depth + 1);
List<DefaultMapEntity> tmp = entities;
entities = new ArrayList<DefaultMapEntity>();
for (DefaultMapEntity ne : tmp) insertEntity(ne);
}
} else {
int cr = (splitAtLat ? entity.compareLatitude(splitValue) : entity.compareLongitude(splitValue));
if (cr < 0)
children[0].insertEntity(entity);
else if (cr > 0)
children[1].insertEntity(entity);
else {
entities.add(entity);
isSorted = false;
}
}
}
use of aimax.osm.data.BoundingBox in project aima-java by aimacode.
the class MapAdapter method getLocations.
/** {@inheritDoc} Very expensive for large maps! */
@Override
public List<String> getLocations() {
List<String> result = new ArrayList<>();
HashSet<MapNode> nodeHash = new HashSet<>();
for (MapWay way : osmMap.getWays(new BoundingBox(-90, -180, 90, 180))) {
if (filter == null || filter.isAccepted(way)) {
for (MapNode node : way.getNodes()) if (!nodeHash.contains(node)) {
result.add(Long.toString(node.getId()));
nodeHash.add(node);
}
}
}
return result;
}
use of aimax.osm.data.BoundingBox in project aima-java by aimacode.
the class MapViewFrame method askForBoundingBox.
protected BoundingBox askForBoundingBox() {
BoundingBox result = null;
JTextField minLat = new JTextField("-90");
JTextField minLon = new JTextField("-180");
JTextField maxLat = new JTextField("90");
JTextField maxLon = new JTextField("180");
if (getMap().getMarkers().size() == 2) {
MapNode m1 = getMap().getMarkers().get(0);
MapNode m2 = getMap().getMarkers().get(1);
minLat.setText(Float.toString(Math.min(m1.getLat(), m2.getLat())));
minLon.setText(Float.toString(Math.min(m1.getLon(), m2.getLon())));
maxLat.setText(Float.toString(Math.max(m1.getLat(), m2.getLat())));
maxLon.setText(Float.toString(Math.max(m1.getLon(), m2.getLon())));
}
Object[] content = new Object[] { "Min Latitude:", minLat, "Min Longitude:", minLon, "Max Latitude:", maxLat, "Max Longitude:", maxLon };
boolean done;
do {
done = true;
if (JOptionPane.showConfirmDialog(this, content, "Specify Bounding Box", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
try {
result = new BoundingBox(Float.parseFloat(minLat.getText()), Float.parseFloat(minLon.getText()), Float.parseFloat(maxLat.getText()), Float.parseFloat(maxLon.getText()));
} catch (NumberFormatException e) {
done = false;
}
}
} while (!done);
return result;
}
Aggregations