use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.
the class BoundaryQuadTree method get.
/**
* Return location relevant Tags for the point defined by Coord
* @param co the point
* @return a reference to the internal Tags or null if the point was not found.
* The returned Tags must not be modified by the caller.
*/
public Tags get(Coord co) {
Tags res = root.get(co);
if (res == null && bbox.contains(co.getLongitude(), co.getLatitude())) {
// we did not find the point, probably it lies on a boundary and
// the clauses regarding insideness of areas make it "invisible"
// try again a few other nearby points
Coord neighbour1 = new Coord(co.getLatitude() - 1, co.getLongitude());
Coord neighbour2 = new Coord(co.getLatitude(), co.getLongitude() - 1);
Coord neighbour3 = new Coord(co.getLatitude() + 1, co.getLongitude());
Coord neighbour4 = new Coord(co.getLatitude(), co.getLongitude() + 1);
res = root.get(neighbour1);
if (res == null)
res = root.get(neighbour2);
if (res == null)
res = root.get(neighbour3);
if (res == null)
res = root.get(neighbour4);
}
return res;
}
use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.
the class BoundaryQuadTree method readStreamQuadTreeFormat.
/**
* Read a stream in QUADTREE_DATA_FORMAT
* @param inpStream the already opened DataInputStream
* @param searchBBox a bounding box. Areas not intersecting the bbox are
* ignored.
* @throws IOException
*/
private void readStreamQuadTreeFormat(DataInputStream inpStream, uk.me.parabola.imgfmt.app.Area searchBBox) throws IOException {
boolean isFirstArea = true;
try {
while (true) {
String type = inpStream.readUTF();
if (type.equals("TAGS")) {
String id = inpStream.readUTF();
Tags tags = new Tags();
int noOfTags = inpStream.readInt();
for (int i = 0; i < noOfTags; i++) {
String name = inpStream.readUTF();
String value = inpStream.readUTF();
tags.put(name, value.intern());
}
boundaryTags.put(id, tags);
} else if (type.equals("AREA")) {
if (isFirstArea) {
isFirstArea = false;
prepareLocationInfo();
}
int minLat = inpStream.readInt();
int minLong = inpStream.readInt();
int maxLat = inpStream.readInt();
int maxLong = inpStream.readInt();
if (log.isDebugEnabled()) {
log.debug("Next boundary. Lat min:", minLat, "max:", maxLat, "Long min:", minLong, "max:", maxLong);
}
uk.me.parabola.imgfmt.app.Area rBbox = new uk.me.parabola.imgfmt.app.Area(minLat, minLong, maxLat, maxLong);
int bSize = inpStream.readInt();
log.debug("Size:", bSize);
if (searchBBox == null || searchBBox.intersects(rBbox)) {
log.debug("Bbox intersects. Load the boundary");
String treePath = inpStream.readUTF();
String id = inpStream.readUTF();
String refs = inpStream.readUTF();
if (refs.isEmpty())
refs = null;
Area area = BoundaryUtil.readAreaAsPath(inpStream);
if (area != null && area.isEmpty() == false)
root.add(area, refs, id, treePath);
else {
log.warn(refs, id, treePath, "invalid or empty or too small area");
}
} else {
log.debug("Bbox does not intersect. Skip", bSize);
inpStream.skipBytes(bSize);
}
} else {
log.error("unknown type field " + type);
}
}
} catch (EOFException exp) {
// it's always thrown at the end of the file
// log.error("Got EOF at the end of the file");
}
}
use of uk.me.parabola.mkgmap.reader.osm.Tags in project mkgmap by openstreetmap.
the class BoundaryDiff method loadArea.
/**
* Calculate the area that is covered by a given tag /value pair, e.g. admin_level=2
* @param dirName the name of a directory or *.zip file containing *.bnd files, or a single *.bnd file
* @param fileName the name of the *.bnd file that should be read
* @param tag the tag key
* @param value the tag value
* @return a new Area (which might be empty)
*/
private static Area loadArea(String dirName, String fileName, String tag, String value) {
String dir = dirName;
String bndFileName = fileName;
if (dir.endsWith(".bnd")) {
File f = new File(dir);
if (f.isFile()) {
dir = f.getParent();
bndFileName = f.getName();
}
if (dir == null)
// the local directory
dir = ".";
}
BoundaryQuadTree bqt = BoundaryUtil.loadQuadTree(dir, bndFileName);
if (tag.equals("admin_level"))
return (bqt.getCoveredArea(Integer.valueOf(value)));
Map<String, Tags> bTags = bqt.getTagsMap();
Map<String, List<Area>> areas = bqt.getAreas();
Path2D.Double path = new Path2D.Double();
for (Entry<String, Tags> entry : bTags.entrySet()) {
if (value.equals(entry.getValue().get(tag))) {
List<Area> aList = areas.get(entry.getKey());
for (Area area : aList) {
path.append(area, false);
}
}
}
Area a = new Area(path);
return a;
}
Aggregations