use of uk.me.parabola.mkgmap.reader.osm.GeneralRelation in project mkgmap by openstreetmap.
the class O5mBinHandler method readRel.
/**
* read a relation data set
* @throws IOException
*/
private void readRel() throws IOException {
lastRelId += readSignedNum64();
if (bytesToRead == 0)
// only relId: this is a delete action, we ignore it
return;
readVersionTsAuthor();
if (bytesToRead == 0)
// only relId + version: this is a delete action, we ignore it
return;
GeneralRelation rel = new GeneralRelation(lastRelId);
long refSize = readUnsignedNum32();
long stop = bytesToRead - refSize;
while (bytesToRead > stop) {
Element el = null;
long deltaRef = readSignedNum64();
int refType = readRelRef();
String role = stringPair[1];
lastRef[refType] += deltaRef;
long memId = lastRef[refType];
if (refType == 0) {
el = saver.getNode(memId);
if (el == null) {
// we didn't make a node for this point earlier,
// do it now (if it exists)
Coord co = saver.getCoord(memId);
if (co != null) {
el = new Node(memId, co);
saver.addNode((Node) el);
}
}
} else if (refType == 1) {
el = saver.getWay(memId);
} else if (refType == 2) {
el = saver.getRelation(memId);
if (el == null) {
saver.deferRelation(memId, rel, role);
}
} else {
assert false;
}
if (// ignore non existing ways caused by splitting files
el != null)
rel.addElement(role, el);
}
boolean tagsIncomplete = readTags(rel);
rel.setTagsIncomplete(tagsIncomplete);
saver.addRelation(rel);
}
use of uk.me.parabola.mkgmap.reader.osm.GeneralRelation in project mkgmap by openstreetmap.
the class ActionReaderTest method makeRelation.
private Relation makeRelation() {
Relation rel = new GeneralRelation(23);
rel.addElement("bar", makeElement());
rel.addElement("foo", makeElement());
return rel;
}
use of uk.me.parabola.mkgmap.reader.osm.GeneralRelation in project mkgmap by openstreetmap.
the class PrecompSeaMerger method run.
public void run() {
Area merge = null;
try {
merge = mergeData.toMerge.poll(5, TimeUnit.MILLISECONDS);
} catch (InterruptedException exp) {
exp.printStackTrace();
}
int merges = 0;
while (merge != null) {
Area landClipped = new Area(mergeData.bounds);
landClipped.intersect(merge);
mergeData.tmpLandPath.append(landClipped, false);
merges++;
if (merges % 500 == 0) {
// store each 500 polygons into a temporary area
// and merge them after that. That seems to be quicker
// than adding lots of very small areas to a highly
// scattered area
Area tmpLandArea = new Area(mergeData.tmpLandPath);
mergeData.landArea.add(tmpLandArea);
mergeData.tmpLandPath.reset();
}
if (merges % 500 == 0) {
break;
}
merge = mergeData.toMerge.poll();
}
if (mergeData.ready.get() == false || mergeData.toMerge.isEmpty() == false) {
// repost the merge thread
service.execute(this);
return;
}
if (mergeData.landArea.isEmpty())
mergeData.landArea = new Area(mergeData.tmpLandPath);
else
mergeData.landArea.add(new Area(mergeData.tmpLandPath));
mergeData.tmpLandPath = null;
// post processing //
// convert the land area to a list of ways
List<Way> ways = convertToWays(mergeData.landArea, "land");
if (ways.isEmpty()) {
// no land in this tile => create a sea way only
ways.addAll(convertToWays(new Area(mergeData.bounds), "sea"));
} else {
Map<Long, Way> landWays = new HashMap<Long, Way>();
List<List<Coord>> landParts = Java2DConverter.areaToShapes(mergeData.landArea);
for (List<Coord> landPoints : landParts) {
Way landWay = new Way(FakeIdGenerator.makeFakeId(), landPoints);
landWays.put(landWay.getId(), landWay);
}
Way seaWay = new Way(FakeIdGenerator.makeFakeId());
seaWay.addPoint(new Coord(-90.0d, -180.0d));
seaWay.addPoint(new Coord(90.0d, -180.0d));
seaWay.addPoint(new Coord(90.0d, 180.0d));
seaWay.addPoint(new Coord(-90.0d, 180.0d));
// close shape
seaWay.addPoint(seaWay.getPoints().get(0));
seaWay.setClosedInOSM(true);
landWays.put(seaWay.getId(), seaWay);
Relation rel = new GeneralRelation(FakeIdGenerator.makeFakeId());
for (Way w : landWays.values()) {
rel.addElement((w == seaWay ? "outer" : "inner"), w);
}
// process the tile as sea multipolygon to create simple polygons only
MultiPolygonRelation mpr = new MultiPolygonRelation(rel, landWays, Java2DConverter.createBbox(new Area(mergeData.bounds))) {
// do not calculate the area size => it is not required and adds
// a superfluous tag
protected boolean isAreaSizeCalculated() {
return false;
}
};
mpr.addTag("type", "multipolygon");
mpr.addTag("natural", "sea");
mpr.processElements();
for (Way w : landWays.values()) {
// be ignored here
if (MultiPolygonRelation.STYLE_FILTER_POLYGON.equals(w.getTag(MultiPolygonRelation.STYLE_FILTER_TAG))) {
String tag = w.getTag("natural");
if ("sea".equals(tag) == false) {
// ignore the land polygons - we already have them in our list
continue;
}
w.deleteTag(MultiPolygonRelation.STYLE_FILTER_TAG);
w.deleteTag(MultiPolygonRelation.MP_CREATED_TAG);
ways.add(w);
}
}
}
try {
// forward the ways to the queue of the saver thread
saveQueue.put(new SimpleEntry<String, List<Way>>(mergeData.getKey(), ways));
} catch (InterruptedException exp) {
exp.printStackTrace();
}
// signal that this tile is finished
signal.countDown();
}
Aggregations