use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class ElementQuadTreeNode method split.
/**
* Splits this quadtree node into 4 subnodes.
*/
private void split() {
if (bounds.getHeight() <= 5 || bounds.getWidth() <= 5) {
log.error("Do not split more due to too small bounds: " + bounds);
return;
}
int halfLat = (bounds.getMinLat() + bounds.getMaxLat()) / 2;
int halfLong = (bounds.getMinLong() + bounds.getMaxLong()) / 2;
children = new ElementQuadTreeNode[4];
Area[] childBounds = new Area[4];
childBounds[0] = new Area(bounds.getMinLat(), bounds.getMinLong(), halfLat, halfLong);
childBounds[1] = new Area(halfLat, bounds.getMinLong(), bounds.getMaxLat(), halfLong);
childBounds[2] = new Area(bounds.getMinLat(), halfLong, halfLat, bounds.getMaxLong());
childBounds[3] = new Area(halfLat, halfLong, bounds.getMaxLat(), bounds.getMaxLong());
List<Map<Element, List<Coord>>> childElems = new ArrayList<Map<Element, List<Coord>>>(4);
for (int i = 0; i < 4; i++) {
childElems.add(new HashMap<Element, List<Coord>>());
}
for (Entry<Element, List<Coord>> elem : elementMap.entrySet()) {
if (elem.getKey() instanceof Node) {
Node node = (Node) elem.getKey();
for (int i = 0; i < childBounds.length; i++) {
if (childBounds[i].contains(node.getLocation())) {
childElems.get(i).put(node, EMPTY_LIST);
break;
}
}
} else if (elem.getKey() instanceof Way) {
List<List<Coord>> points = new ArrayList<List<Coord>>(4);
for (int i = 0; i < 4; i++) {
// usually ways are quite local
// therefore there is a high probability that only one child is covered
// dim the new list as the old list
points.add(new ArrayList<Coord>(elem.getValue().size()));
}
for (Coord c : elem.getValue()) {
for (int i = 0; i < childBounds.length; i++) {
if (childBounds[i].contains(c)) {
points.get(i).add(c);
break;
}
}
}
for (int i = 0; i < 4; i++) {
if (points.get(i).isEmpty() == false) {
childElems.get(i).put(elem.getKey(), points.get(i));
}
}
}
}
for (int i = 0; i < 4; i++) {
children[i] = new ElementQuadTreeNode(childBounds[i], childElems.get(i));
}
elementMap = null;
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class ElementQuadTreeNode method get.
/**
* Retrieves all elements that intersects the given polygon.
* @param polygon the polygon
* @param resultList results are stored in this collection
* @return the resultList
*/
public Set<Element> get(ElementQuadTreePolygon polygon, Set<Element> resultList) {
if (isEmpty()) {
return resultList;
}
if (polygon.getBbox().intersects(getBounds())) {
if (isLeaf()) {
for (Entry<Element, List<Coord>> elem : elementMap.entrySet()) {
if (resultList.contains(elem.getKey())) {
continue;
}
if (elem.getKey() instanceof Node) {
Node n = (Node) elem.getKey();
Coord c = n.getLocation();
if (polygon.getArea().contains(c.getLongitude(), c.getLatitude())) {
resultList.add(n);
}
} else if (elem.getKey() instanceof Way) {
for (Coord c : elem.getValue()) {
if (polygon.getArea().contains(c.getLongitude(), c.getLatitude())) {
resultList.add(elem.getKey());
break;
}
}
}
}
} else {
for (ElementQuadTreeNode child : children) {
if (child.isEmpty() == false && polygon.getArea().intersects(child.getBoundsAsRectangle())) {
java.awt.geom.Area subArea = (java.awt.geom.Area) polygon.getArea().clone();
subArea.intersect(Java2DConverter.createBoundsArea(new Area(child.getBounds().getMinLat() - 1, child.getBounds().getMinLong() - 1, child.getBounds().getMaxLat() + 1, child.getBounds().getMaxLong() + 1)));
child.get(new ElementQuadTreePolygon(subArea), resultList);
}
}
}
}
return resultList;
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class ActionReaderTest method testSimpleAdd.
@Test
public void testSimpleAdd() {
List<Action> actions = readActionsFromString("{add park=yes}");
assertEquals("one action", 1, actions.size());
// add does not overwrite existing tags.
Element el = stdElementRun(actions);
assertEquals("park not overwritten", "no", el.getTag("park"));
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class ActionReaderTest method testFreeForm.
/**
* Test with embedded comment, newlines, semicolon used as separator.
*/
@Test
public void testFreeForm() {
List<Action> actions = readActionsFromString(" { set web='world wide';" + "set \nribbon = 'yellow' \n# a comment } ");
assertEquals("number of actions", 2, actions.size());
Element el = stdElementRun(actions);
assertEquals("park not overwritten", "no", el.getTag("park"));
assertEquals("word with spaces", "world wide", el.getTag("web"));
assertEquals("yellow ribbon", "yellow", el.getTag("ribbon"));
}
use of uk.me.parabola.mkgmap.reader.osm.Element in project mkgmap by openstreetmap.
the class ActionReaderTest method testDoubleName.
/**
* Test with two name actions. This works just the same as having several
* name options on the same name command, in that it is still the
* first one to match that counts.
*/
@Test
public void testDoubleName() {
List<Action> actions = readActionsFromString("{name '${name} (${ref})' |" + " '${ref}' | '${name}' ; " + " name 'fred';}");
// Something that matches nothing in the first name command.
Element el = makeElement();
Rule rule = new ActionRule(null, actions);
rule.resolveType(el, TypeResult.NULL_RESULT);
assertEquals("no tags, second action matches", "fred", el.getName());
el = makeElement();
el.addTag("ref", "A1");
rule.resolveType(el, TypeResult.NULL_RESULT);
assertEquals("just a ref tag", "A1", el.getName());
el = makeElement();
el.addTag("ref", "A1");
el.addTag("name", "Main St");
rule.resolveType(el, TypeResult.NULL_RESULT);
assertEquals("ref and name", "Main St (A1)", el.getName());
}
Aggregations