
Hi, until now the --add-pois-to-areas function only checked area types that are listed in the polygon style file. This patch for the latest trunk R974 removes this restriction. Patch also include the address support for area pois. Please let me know if this one is useful... Thanks Berni. Index: mkgmap/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java =================================================================== --- mkgmap/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java (.../upstream) (revision 317) +++ mkgmap/src/uk/me/parabola/mkgmap/osmstyle/StyledConverter.java (.../work_areapoi) (revision 317) @@ -89,7 +89,8 @@ private final Rule nodeRules; private final Rule relationRules; - + private boolean add_pois_to_areas = false; + class AccessMapping { private final String type; private final int index; @@ -134,7 +135,12 @@ if (overlayAdder != null) lineAdder = overlayAdder; } - + + public void enableAreasPois(boolean enable) + { + add_pois_to_areas = enable; + } + /** * This takes the way and works out what kind of map feature it is and makes * the relevant call to the mapper callback. @@ -151,19 +157,46 @@ preConvertRules(way); GType foundType = wayRules.resolveType(way); - if (foundType == null) - return; + + MapShape shape = null; + + if (foundType != null) + { + postConvertRules(way, foundType); - postConvertRules(way, foundType); + if (foundType.getFeatureKind() == GType.POLYLINE) { + if(foundType.isRoad()) + addRoad(way, foundType); + else + addLine(way, foundType); + } + else + shape = addShape(way, foundType); + } - if (foundType.getFeatureKind() == GType.POLYLINE) { - if(foundType.isRoad()) - addRoad(way, foundType); - else - addLine(way, foundType); + // Now check for area poi stuff + + if(add_pois_to_areas) + { + GType pointType = nodeRules.resolveType(way); + + if(pointType != null) + { + if(shape == null) // Check if a shape was created for this poi + { + // If not create a dummy shape with type 0 + shape = new MapShape(); + postConvertRules(way, pointType); + elementSetup(shape, pointType, way); + shape.setType(0); + shape.setPoints(way.getPoints()); + clipper.clipShape(shape, collector); + shape.setPoiType(pointType.getType()); + // We will later remove this dummy shapes while we build up the area pois + } + shape.setPoiType(pointType.getType()); + } } - else - addShape(way, foundType); } /** @@ -271,17 +304,12 @@ clipper.clipLine(line, lineAdder); } - private void addShape(Way way, GType gt) { + private MapShape addShape(Way way, GType gt) { MapShape shape = new MapShape(); elementSetup(shape, gt, way); shape.setPoints(way.getPoints()); - - clipper.clipShape(shape, collector); - - GType pointType = nodeRules.resolveType(way); - - if(pointType != null) - shape.setPoiType(pointType.getType()); + clipper.clipShape(shape, collector); + return shape; } private void addPoint(Node node, GType gt) { Index: mkgmap/src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java =================================================================== --- mkgmap/src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java (.../upstream) (revision 317) +++ mkgmap/src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java (.../work_areapoi) (revision 317) @@ -78,6 +78,7 @@ private final boolean ignoreBounds; private final boolean ignoreTurnRestrictions; private final boolean routing; + private final boolean add_pois_to_areas; private final String frigRoundabouts; public Osm5XmlHandler(EnhancedProperties props) { @@ -94,6 +95,7 @@ wayMap = new HashMap<Long, Way>(5000); relationMap = new HashMap<Long, Relation>(); } + add_pois_to_areas = props.getProperty("add-pois-to-areas",false); } /** @@ -322,6 +324,9 @@ */ public void endDocument() throws SAXException { coordMap = null; + + converter.enableAreasPois(add_pois_to_areas); + for (Relation r : relationMap.values()) converter.convertRelation(r); Index: mkgmap/src/uk/me/parabola/mkgmap/reader/osm/OsmConverter.java =================================================================== --- mkgmap/src/uk/me/parabola/mkgmap/reader/osm/OsmConverter.java (.../upstream) (revision 317) +++ mkgmap/src/uk/me/parabola/mkgmap/reader/osm/OsmConverter.java (.../work_areapoi) (revision 317) @@ -67,5 +67,7 @@ * @param bbox The bounding area. */ public void setBoundingBox(Area bbox); + + public void enableAreasPois(boolean enable); } Index: mkgmap/src/uk/me/parabola/mkgmap/main/MapMaker.java =================================================================== --- mkgmap/src/uk/me/parabola/mkgmap/main/MapMaker.java (.../upstream) (revision 317) +++ mkgmap/src/uk/me/parabola/mkgmap/main/MapMaker.java (.../work_areapoi) (revision 317) @@ -22,6 +22,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.Vector; import uk.me.parabola.imgfmt.ExitException; import uk.me.parabola.imgfmt.FileExistsException; @@ -150,6 +151,8 @@ poiMap.put(null, point); } + List<MapShape> shapeToRemove = new Vector<MapShape>(); + for (MapShape shape : src.getShapes()) { String shapeName = shape.getName(); @@ -158,8 +161,10 @@ // only make a point if the shape has a name and we know what type of point to make if (pointType == 0) continue; - + if(shape.getType() == 0) + shapeToRemove.add(shape); + // We don't want to add unnamed cities !! if(MapPoint.isCityType(pointType) && shapeName == null) continue; @@ -170,12 +175,18 @@ { MapPoint newPoint = new MapPoint(); newPoint.setName(shapeName); + newPoint.copyAddress(shape); newPoint.setType(pointType); newPoint.setLocation(shape.getLocation()); // TODO use centriod src.getPoints().add(newPoint); log.info("created POI ", shapeName, "from shape"); } } + + for (MapShape shape : shapeToRemove) + { + src.getShapes().remove(shape); + } } } Index: mkgmap/src/uk/me/parabola/mkgmap/general/MapElement.java =================================================================== --- mkgmap/src/uk/me/parabola/mkgmap/general/MapElement.java (.../upstream) (revision 317) +++ mkgmap/src/uk/me/parabola/mkgmap/general/MapElement.java (.../work_areapoi) (revision 317) @@ -57,7 +57,7 @@ * @return the copy; */ public abstract MapElement copy(); - + public String getName() { return name; } @@ -67,6 +67,15 @@ this.name = name.toUpperCase(); } + public void copyAddress(MapElement orig) + { + zipCode = orig.zipCode; + city = orig.city; + region = orig.region; + country = orig.country; + attributes.putAll(orig.attributes); + } + public String getCity() { return city; }