use of aimax.osm.data.Position in project aima-java by aimacode.
the class OsmRoutePlannerApp method getTrackInfo.
protected String getTrackInfo(Track track) {
List<MapNode> nodes = track.getNodes();
DecimalFormat f1 = new DecimalFormat("#0.00");
double km = Position.getTrackLengthKM(nodes);
String info = track.getName() + ": Length " + f1.format(km) + " km";
if (nodes.size() == 2) {
DecimalFormat f2 = new DecimalFormat("#000");
MapNode m1 = nodes.get(nodes.size() - 2);
MapNode m2 = nodes.get(nodes.size() - 1);
int course = new Position(m1).getCourseTo(m2);
info += "; Direction " + f2.format(course);
}
return info;
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class OsmLRTAStarAgentApp method updateTrack.
/** Visualizes agent positions. Call from simulation thread. */
private void updateTrack(Agent agent, Metrics metrics) {
MapAdapter map = (MapAdapter) env.getMap();
MapNode node = map.getWayNode(env.getAgentLocation(agent));
if (node != null) {
Platform.runLater(() -> map.getOsmMap().addToTrack(TRACK_NAME, new Position(node.getLat(), node.getLon())));
}
simPaneCtrl.setStatus(metrics.toString());
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class DefaultMap method createTrack.
/** {@inheritDoc} */
@Override
public void createTrack(String trackName, List<Position> positions) {
clearTrack(trackName);
Track track = new DefaultTrack(nextTrackId++, trackName, trackName);
updateEntityViewInfo(track, false);
tracks.add(track);
for (Position pos : positions) track.addNode(pos);
fireMapDataEvent(new MapEvent(this, MapEvent.Type.TRACK_MODIFIED, track.getId()));
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class DefaultEntityFinder method find.
/**
* Searches for entities which comply to the current search specification
* and stores them as results.
*/
@Override
protected void find(boolean findMore) {
BestMatchFinder bmf = new BestMatchFinder(pattern);
List<MapEntity> results = getResults();
BoundingBox bb = new BoundingBox(position, nextRadius);
if (!results.isEmpty())
bmf.checkMatchQuality(results.get(0));
if (mode.equals(Mode.ENTITY) || mode.equals(Mode.NODE)) {
for (MapNode node : getStorage().getPois(bb)) {
int match = bmf.checkMatchQuality(node);
if (match >= 0) {
if (match > 0) {
results.clear();
bmf.useAsReference(node);
}
if (position.insertInAscendingDistanceOrder(results, node))
if (results.size() > 100)
results.remove(99);
}
}
}
if (mode.equals(Mode.ENTITY) || mode.equals(Mode.WAY)) {
for (MapWay way : getStorage().getWays(bb)) {
int match = bmf.checkMatchQuality(way);
if (match >= 0) {
if (match > 0) {
results.clear();
bmf.useAsReference(way);
}
if (position.insertInAscendingDistanceOrder(results, way))
if (results.size() > 100)
results.remove(99);
}
}
}
if (mode.equals(Mode.ADDRESS)) {
List<MapEntity> iResults = getIntermediateResults();
StringTokenizer tokenizer = new StringTokenizer(pattern, ",");
String placeName = null;
String wayName = null;
if (tokenizer.hasMoreElements())
placeName = tokenizer.nextToken();
if (tokenizer.hasMoreElements())
wayName = tokenizer.nextToken().trim();
if (placeName != null && !findMore) {
for (MapNode place : getStorage().getPlaces(placeName)) {
position.insertInAscendingDistanceOrder(iResults, place);
if (iResults.size() > 100)
iResults.remove(99);
}
nextRadius = -1;
}
if (iResults.size() == 1 && wayName != null) {
MapNode place = (MapNode) iResults.get(0);
findWay(wayName, new Position(place.getLat(), place.getLon()), null);
}
} else {
nextRadius *= 2;
if (results.isEmpty() && getIntermediateResults().isEmpty() && nextRadius <= getMaxRadius())
find(true);
}
}
use of aimax.osm.data.Position in project aima-java by aimacode.
the class OsmMoveAction method getTravelDistance.
/** Returns the distance in KM. */
public float getTravelDistance() {
float result = 0f;
int size = Math.abs(toIndex - fromIndex) + 1;
List<MapNode> nodes = way.getNodes();
Position pos = new Position(nodes.get(fromIndex));
for (int i = 1; i < size; i++) {
MapNode next = nodes.get(fromIndex < toIndex ? fromIndex + i : fromIndex - i);
result += pos.getDistKM(next);
pos = new Position(next);
}
return result;
}
Aggregations