From: Scott Crosby <[email protected]>
---
.../me/parabola/splitter/DensityMapCollector.java | 14 +------
src/uk/me/parabola/splitter/MapProcessor.java | 39 +------------------
src/uk/me/parabola/splitter/NodeCollector.java | 14 +------
src/uk/me/parabola/splitter/OSMParser.java | 14 +++---
src/uk/me/parabola/splitter/SplitProcessor.java | 41 +++++++++-----------
5 files changed, 29 insertions(+), 93 deletions(-)
diff --git a/src/uk/me/parabola/splitter/DensityMapCollector.java
b/src/uk/me/parabola/splitter/DensityMapCollector.java
index b4a5953..b94eda8 100644
--- a/src/uk/me/parabola/splitter/DensityMapCollector.java
+++ b/src/uk/me/parabola/splitter/DensityMapCollector.java
@@ -56,22 +56,10 @@ class DensityMapCollector implements MapCollector {
}
@Override
- public void startRelation(int id) {}
-
- @Override
- public void relationTag(String key, String value) {}
-
- @Override
- public void relationNode(int nodeId, String role) {}
-
- @Override
- public void relationWay(int wayId, String role) {}
-
- @Override
public void processWay(Way w) {}
@Override
- public void endRelation() {}
+ public void processRelation(Relation r) {}
@Override
public void endMap() {}
diff --git a/src/uk/me/parabola/splitter/MapProcessor.java
b/src/uk/me/parabola/splitter/MapProcessor.java
index b179d85..2bd020f 100644
--- a/src/uk/me/parabola/splitter/MapProcessor.java
+++ b/src/uk/me/parabola/splitter/MapProcessor.java
@@ -33,51 +33,16 @@ public interface MapProcessor {
*/
void boundTag(Area bounds);
- /**
- * Called when a relation is encountered.
- * @param id the relation's ID.
- */
- void startRelation(int id);
-
/**
* Called when a whole node has been processed.
*/
void processNode(Node n);
- /**
- * Called when a tag is encountered on a relation. This method will
- * be called for every tag associated with the relation that was
- * specified in the most recent call to {...@link #startRelation(int)}.
- * @param key the tag's key.
- * @param value the tag's value.
- */
- void relationTag(String key, String value);
-
- /**
- * Called when a reference to a node is encountered within a relation.
- * This method will be called for every node that is associated with the
- * relation that was specified in the most recent call to {...@link
#startRelation(int)} .
- * @param nodeId the ID of the node.
- */
- void relationNode(int nodeId, String role);
-
- /**
- * Called when a reference to a way is encountered within a relation.
- * This method will be called for every way that is associated with the
relation
- * that was specified in the most recent call to {...@link
#startRelation(int)} .
- * @param nodeId the ID of the node.
- */
- void relationWay(int wayId, String role);
-
void processWay(Way w);
- /**
- * Called when processing is complete for a relation. This method will
be called once
- * there is no further data available for the relation specified in the
most recent
- * call to {...@link #startRelation(int)}.
- */
- void endRelation();
+ void processRelation(Relation w);
+
/**
* Called once the entire map has finished processing.
diff --git a/src/uk/me/parabola/splitter/NodeCollector.java
b/src/uk/me/parabola/splitter/NodeCollector.java
index 2607d18..409545f 100644
--- a/src/uk/me/parabola/splitter/NodeCollector.java
+++ b/src/uk/me/parabola/splitter/NodeCollector.java
@@ -49,22 +49,10 @@ class NodeCollector implements MapCollector {
}
@Override
- public void startRelation(int id) {}
-
- @Override
- public void relationTag(String key, String value) {}
-
- @Override
- public void relationNode(int nodeId, String role) {}
-
- @Override
- public void relationWay(int wayId, String role) {}
-
- @Override
public void processWay(Way w) {}
@Override
- public void endRelation() {}
+ public void processRelation(Relation r) {}
@Override
public void endMap() {}
diff --git a/src/uk/me/parabola/splitter/OSMParser.java
b/src/uk/me/parabola/splitter/OSMParser.java
index 081bc83..50569be 100644
--- a/src/uk/me/parabola/splitter/OSMParser.java
+++ b/src/uk/me/parabola/splitter/OSMParser.java
@@ -31,6 +31,7 @@ class OSMParser extends AbstractXppParser implements
MapReader {
private Node currentNode = new Node();
private Way currentWay = new Way();
+ private Relation currentRelation = new Relation();
private final MapProcessor processor;
@@ -154,7 +155,8 @@ class OSMParser extends AbstractXppParser implements
MapReader {
}
private void startRelation() {
- processor.startRelation(getIntAttr("id"));
+ currentRelation = new Relation();
+ currentRelation.set(getIntAttr("id"));
state = State.Relation;
}
@@ -174,15 +176,13 @@ class OSMParser extends AbstractXppParser implements
MapReader {
private void processRelation(CharSequence name) {
if (name.equals("tag")) {
- processor.relationTag(getAttr("k"), getAttr("v"));
+ currentRelation.addTag(getAttr("k"), getAttr("v"));
} else if (name.equals("member")) {
String type = getAttr("type");
int id = getIntAttr("ref");
String role = getAttr("role");
- if ("node".equals(type)) {
- processor.relationNode(id, role);
- } else if ("way".equals(type)) {
- processor.relationWay(id, role);
+ if ("node".equals(type) || "way".equals(type)) {
+ currentRelation.addMember(type, id, role);
}
}
}
@@ -260,7 +260,7 @@ class OSMParser extends AbstractXppParser implements
MapReader {
} else if (state == State.Relation) {
if (name.equals("relation")) {
if (!startNodeOnly)
- processor.endRelation();
+
processor.processRelation(currentRelation);
state = State.None;
relationCount++;
if (relationCount %
RELATION_STATUS_UPDATE_THRESHOLD == 0) {
diff --git a/src/uk/me/parabola/splitter/SplitProcessor.java
b/src/uk/me/parabola/splitter/SplitProcessor.java
index 693ebc5..24d23db 100644
--- a/src/uk/me/parabola/splitter/SplitProcessor.java
+++ b/src/uk/me/parabola/splitter/SplitProcessor.java
@@ -19,6 +19,8 @@ import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
+import uk.me.parabola.splitter.Relation.Member;
+
/**
* Splits a map into multiple areas.
*/
@@ -35,8 +37,6 @@ class SplitProcessor implements MapProcessor {
private int currentNodeAreaSet;
private BitSet currentWayAreaSet;
-
- private Relation currentRelation = new Relation();
private BitSet currentRelAreaSet;
private final int maxThreads;
@@ -73,20 +73,8 @@ class SplitProcessor implements MapProcessor {
public void boundTag(Area bounds) {
}
- @Override
- public void startRelation(int id) {
- currentRelation.set(id);
- }
-
- @Override
- public void relationTag(String key, String value) {
- currentRelation.addTag(key, value);
- }
-
- @Override
- public void relationNode(int id, String role) {
+ private void relationNode(int id, String role) {
{
- currentRelation.addMember("node", id, role);
int set = coords.get(id);
if (set != 0) {
int mask = 0xff;
@@ -101,11 +89,9 @@ class SplitProcessor implements MapProcessor {
}
}
- @Override
- public void relationWay(int id, String role) {
+ private void relationWay(int id, String role) {
{
long[] bigSet;
- currentRelation.addMember("way", id, role);
int set = ways.get(id);
if (set != 0) {
int mask = 0xff;
@@ -168,13 +154,22 @@ class SplitProcessor implements MapProcessor {
}
@Override
- public void endRelation() {
+ public void processRelation(Relation r) {
try {
- writeRelation();
- currentRelation = new Relation();
+ for (Member mem : r.getMembers()) {
+ String role = mem.getRole();
+ int id = mem.getRef();
+ if (mem.getType().equals("node")) {
+ relationNode(id,role);
+ } else if (mem.getType().equals("way")){
+ relationWay(id,role);
+ }
+ }
+
+ writeRelation(r);
currentRelAreaSet.clear();
} catch (IOException e) {
- throw new RuntimeException("failed to write relation "
+ currentRelation.getId(), e);
+ throw new RuntimeException("failed to write relation "
+ r.getId(), e);
}
}
@@ -262,7 +257,7 @@ class SplitProcessor implements MapProcessor {
private boolean seenRel;
- private void writeRelation() throws IOException {
+ private void writeRelation(Relation currentRelation) throws IOException
{
if (!seenRel) {
seenRel = true;
System.out.println("Writing relations " + new Date());
--
1.7.2.3
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev