0

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.

  • Maybe you can get some hints via help.openstreetmap.org by doing a search there for "street list" ? – stephan75 Dec 30 '18 at 19:33
  • I want to extract the data in java with osmosis. Most solutions require to execute command line. Some suggest to import into postgresql. Not really what I want to do. – No3x Dec 30 '18 at 21:55
1

Address tags are not only present at nodes, they do exist on ways and relations, too. So you need to process all elements in order to get all addr:street and addr:city combinations.

In the end this is really a task for a gecoder such as Nominatim. Your approach will work for many situations but not for all of them. For example some elements will only contain an addr:street tag but no addr:city tag. A geocoder will be able to resolve the missing city by looking at administrative boundary relations, your approach won't.

  • Thank you. I already found stackoverflow.com/a/24444767/772883 very useful. I'm still looking for a geocoder that works offline. – No3x Jan 2 at 17:02
  • Nominatim works offline if you install your own local instance. It requires a postgresql database though. – scai Jan 3 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.