use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class DefaultMap method compile.
/**
* Separates way nodes from points of interests, cleans up useless garbage
* and creates a kd-tree for the remaining entities. Always call this method
* before using using the container for viewing.
*/
public void compile() {
ArrayList<Long> toDelete = new ArrayList<Long>();
for (MapNode node : nodes.values()) {
if (node.hasPosition()) {
if (node.getName() != null || node.getAttributes().length > 0)
pois.add(node);
else if (node.getWayRefs().isEmpty())
toDelete.add(node.getId());
} else {
LOG.warning("No definition found for referenced node " + node.getId() + ".");
toDelete.add(node.getId());
}
}
for (long id : toDelete) {
nodes.remove(id);
}
BoundingBox bbAllNodes = new BoundingBox();
bbAllNodes.adjust(nodes.values());
bbAllNodes.adjust(pois);
if (boundingBox == null)
boundingBox = bbAllNodes;
else
boundingBox.intersectWith(bbAllNodes);
applyClassifierAndUpdateTree(bbAllNodes);
fireMapDataEvent(new MapEvent(this, MapEvent.Type.MAP_NEW));
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class DefaultMapBuilder method isNodeDefined.
/** {@inheritDoc} */
@Override
public boolean isNodeDefined(long id, BoundingBox bb) {
MapNode node = result.getNode(id);
boolean result = (node != null && node.hasPosition());
if (result && bb != null)
result = bb.isInside(node.getLat(), node.getLon());
return result;
}
use of aimax.osm.data.entities.MapNode in project aima-java by aimacode.
the class DefaultMapWay method toString.
@Override
public String toString() {
StringBuffer result = new StringBuffer("Way(" + id + ", [ ");
for (MapNode node : nodes) result.append(node.getId() + " ");
result.append("])");
return result.toString();
}
use of aimax.osm.data.entities.MapNode 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.entities.MapNode in project aima-java by aimacode.
the class DefaultMap method getWayNodes.
/** Reduces the level of detail by selecting some of the given nodes. */
@Override
public List<MapNode> getWayNodes(MapWay way, float scale) {
List<MapNode> wayNodes = way.getNodes();
int zoomLevel;
if (scale <= 1f / 10000000)
zoomLevel = 3;
else if (scale <= 1f / 750000)
zoomLevel = 2;
else if (scale <= 1f / 350000)
zoomLevel = 1;
else
zoomLevel = 0;
if (zoomLevel > 0) {
int size = wayNodes.size();
List<MapNode> result = new ArrayList<MapNode>(size / zoomLevel + 2);
int i = 0;
for (MapNode node : wayNodes) {
if (i == 0 || i == size - 1 || node.getId() % (4 * zoomLevel) == 0)
result.add(node);
i++;
}
if (wayNodes.get(0) == wayNodes.get(size - 1) && result.size() < 4)
result.clear();
return result;
} else {
return Collections.unmodifiableList(wayNodes);
}
}
Aggregations