Hi
Just a quick guess without looking at the patch: did you try patch -lp0
to ignore white space differences?
It doesn't apply for me either. This is because the existing file has
DOS line endings, whereas the patch has UNIX line-endings. If you add a
CR (^M) to every line *except* for the diff control lines then it will
apply.
I've attached the result.
..Steve
Index: src/uk/me/parabola/mkgmap/reader/osm/Areas2POIHook.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/Areas2POIHook.java (revision 2063)
+++ src/uk/me/parabola/mkgmap/reader/osm/Areas2POIHook.java (working copy)
@@ -52,6 +52,8 @@
/** Name of the bool tag that is set to true if a POI is created from an area */
public static final String AREA2POI_TAG = "mkgmap:area2poi";
+ public static final String LINE2POI_TAG = "mkgmap:line2poi";
+ public static final String LINE2POI_TYPE_TAG = "mkgmap:line2poitype";
public boolean init(ElementSaver saver, EnhancedProperties props) {
if (props.containsKey("add-pois-to-areas") == false) {
@@ -166,62 +168,130 @@
log.debug("Found", labelCoords.size(), "label coords");
int ways2POI = 0;
+ int lines2POI = 0;
for (Way w : saver.getWays().values()) {
- // check if it is an area
- if (w.isClosed() == false) {
+ // check if way has any tags
+ if (w.getTagCount() == 0) {
continue;
}
- if (w.getTagCount() == 0) {
- continue;
- }
-
// do not add POIs for polygons created by multipolygon processing
if (w.isBoolTag(MultiPolygonRelation.MP_CREATED_TAG)) {
log.debug("MP processed: Do not create POI for", w.toTagString());
continue;
}
- // get the coord where the poi is placed
- Coord poiCoord = null;
- // do we have some labeling coords?
- if (labelCoords.size() > 0) {
- int poiOrder = Integer.MAX_VALUE;
- // go through all points of the way and check if one of the coords
- // is a labeling coord
- for (Coord c : w.getPoints()) {
- Integer cOrder = labelCoords.get(c);
- if (cOrder != null && cOrder.intValue() < poiOrder) {
- // this coord is a labeling coord
- // use it for the current way
- poiCoord = c;
- poiOrder = cOrder;
- if (poiOrder == 0) {
- // there is no higher order
- break;
- }
+
+ // check if it is an area
+ if (w.isClosed()) {
+ addPOItoPolygon(w, labelCoords);
+ ways2POI++;
+ } else {
+ lines2POI += addPOItoLine(w);
+ }
+ }
+
+ log.error(ways2POI+ " POIs from single areas created");
+ log.error(lines2POI+ " POIs from lines created");
+ }
+
+ private void addPOItoPolygon(Way polygon, Map<Coord, Integer> labelCoords) {
+ // get the coord where the poi is placed
+ Coord poiCoord = null;
+ // do we have some labeling coords?
+ if (labelCoords.size() > 0) {
+ int poiOrder = Integer.MAX_VALUE;
+ // go through all points of the way and check if one of the coords
+ // is a labeling coord
+ for (Coord c : polygon.getPoints()) {
+ Integer cOrder = labelCoords.get(c);
+ if (cOrder != null && cOrder.intValue() < poiOrder) {
+ // this coord is a labeling coord
+ // use it for the current way
+ poiCoord = c;
+ poiOrder = cOrder;
+ if (poiOrder == 0) {
+ // there is no higher order
+ break;
}
}
}
- if (poiCoord == null) {
- // did not find any label coord
- // use the common center point of the area
- poiCoord = w.getCofG();
+ }
+ if (poiCoord == null) {
+ // did not find any label coord
+ // use the common center point of the area
+ poiCoord = polygon.getCofG();
+ }
+
+ Node poi = createPOI(polygon, poiCoord, AREA2POI_TAG);
+ saver.addNode(poi);
+ }
+
+ private int addPOItoLine(Way line) {
+ Node startNode = createPOI(line, line.getPoints().get(0), LINE2POI_TAG);
+ startNode.addTag(LINE2POI_TYPE_TAG,"start");
+ saver.addNode(startNode);
+
+ Node endNode = createPOI(line, line.getPoints().get(line.getPoints().size()-1), LINE2POI_TAG);
+ endNode.addTag(LINE2POI_TYPE_TAG,"end");
+ saver.addNode(endNode);
+
+ int noPOIs = 2;
+
+ if (line.getPoints().size() > 2) {
+ for (Coord inPoint : line.getPoints().subList(1, line.getPoints().size()-1)) {
+ Node innerNode = createPOI(line, inPoint, LINE2POI_TAG);
+ innerNode.addTag(LINE2POI_TYPE_TAG,"inner");
+ saver.addNode(innerNode);
+ noPOIs++;
}
-
- Node poi = new Node(FakeIdGenerator.makeFakeId(), poiCoord);
- poi.copyTags(w);
- poi.deleteTag(MultiPolygonRelation.STYLE_FILTER_TAG);
- poi.addTag(AREA2POI_TAG, "true");
- log.debug("Create POI",poi.toTagString(),"from",w.getId(),w.toTagString());
- saver.addNode(poi);
- ways2POI++;
}
- log.info(ways2POI, "POIs from single areas created");
+
+ // calculate the middle of the line
+ Coord prevC = null;
+ double sumDist = 0.0;
+ ArrayList<Double> dists = new ArrayList<Double>(line.getPoints().size()-1);
+ for (Coord c : line.getPoints()) {
+ if (prevC != null) {
+ double dist = prevC.distance(c);
+ dists.add(dist);
+ sumDist+=dist;
+ }
+ prevC = c;
+ }
+
+ Coord midPoint = null;
+ double remMidDist = sumDist/2;
+ for (int midPos =0; midPos < dists.size(); midPos++) {
+ double nextDist = dists.get(midPos);
+ if (remMidDist <= nextDist) {
+ double frac = remMidDist/nextDist;
+ midPoint = line.getPoints().get(midPos).makeBetweenPoint(line.getPoints().get(midPos+1), frac);
+ break;
+ }
+ remMidDist -= nextDist;
+ }
+ Node midNode = createPOI(line, midPoint, LINE2POI_TAG);
+ midNode.addTag(LINE2POI_TYPE_TAG,"mid");
+ saver.addNode(midNode);
+ noPOIs++;
+
+ return noPOIs;
+
}
+ private Node createPOI(Element source, Coord poiCoord, String poiTypeTag) {
+ Node poi = new Node(FakeIdGenerator.makeFakeId(), poiCoord);
+ poi.copyTags(source);
+ poi.deleteTag(MultiPolygonRelation.STYLE_FILTER_TAG);
+ poi.addTag(poiTypeTag, "true");
+ log.debug("Create POI",poi.toTagString(),"from",source.getId(),source.toTagString());
+ return poi;
+
+ }
+
private void addPOIsToMPs() {
int mps2POI = 0;
for (Relation r : saver.getRelations().values()) {
@@ -236,16 +306,13 @@
continue;
}
- Node poi = new Node(FakeIdGenerator.makeFakeId(), point);
- poi.copyTags(r);
+ Node poi = createPOI(r, point, AREA2POI_TAG);
// remove the type tag which makes only sense for relations
poi.deleteTag("type");
- poi.addTag(AREA2POI_TAG, "true");
- log.debug("Create POI",poi.toTagString(),"from mp",r.getId(),r.toTagString());
saver.addNode(poi);
mps2POI++;
}
- log.info(mps2POI, "POIs from multipolygons created");
+ log.error(mps2POI+ " POIs from multipolygons created");
}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev