How to extract streetnames with osmosis (Java)?
I have tried to process all Nodes. I put them in a Map<String, List>
meaning Map<CityName, ListOfStreetnamesOfThatCity>
:
@Override
public void process(EntityContainer entityContainer) {
if (entityContainer instanceof NodeContainer) {
final NodeContainer entityContainer1 = (NodeContainer) entityContainer;
if(containsTagWithKeys(entityContainer1.getEntity().getTags(), "addr:city", "addr:street")) {
final Map<String, String> tags = entityContainer1.getEntity().getTags()
.stream()
.collect(Collectors.toMap(Tag::getKey, Tag::getValue));
if( cityStreetnames.get(tags.get("addr:city")) == null) {
cityStreetnames.put(tags.get("addr:city"), new ArrayList<>());
}
String streetname = tags.get("addr:street");
cityStreetnames.get(tags.get("addr:city")).add(streetname);
}
}
}
This gives me a subset of all streets per city only. (Not sufficient)
I tried to process all Way nodes
if (entityContainer instanceof WayContainer) {
Way myWay = ((WayContainer) entityContainer).getEntity();
final Map<String, String> tags = myWay.getTags()
.stream()
.collect(Collectors.toMap(Tag::getKey, Tag::getValue));
if(containsTagWithKeys(myWay.getTags(), "name", "highway") && tags.get("name").length() > 2) {
names.add(tags.get("name"));
}
}
This gives me a lot of streets but I don't know in which city these ways are located.
I'm really new to OSM data. Is there a way to map a way node to a city? Is there a better way to get all streetnames of a city?
I have used .osm.pbf for Germany from geofabrik.de.