Back to Home

OpenStreetMap, how to get address coordinates, part simple

geodata

OpenStreetMap, how to get address coordinates, part simple



    Recently, I have observed a trend that more and more people are faced with problems in the absence of geodata. Or rather, not even so, in their closeness. If yesterday everyone was satisfied with the possibilities of map services for placing markers, now the user wants more: to highlight the street, show houses on it, calculate the length of rivers, etc. And then a surprise awaits them, it would seem that on the map they see all this, but they can’t do anything - it's just pictures. Development, that Google.Maps, that Yandex.Maps stopped at showing pictures, geocoding, and navigation.


    Step to the right, step to the left and you are at a standstill. The only way is to recreate the necessary geometry yourself. And if you draw a road and a dozen houses along the street quite quickly and easily, then say a hundred other kilometers of the waterway discourages all desire.


    It is in such difficult moments behind the advertised Google and Yandex that the OpenStreetMap project becomes visible, and he states: - I have the data you want .


    Yes, maybe not so complete in places, but geodata, and not funny pictures. And this opens up great opportunities for their processing and analysis. In addition, the data is available under the ODbL open source license and has two main conditions of use: a mandatory link to the data source (OpenStreetMap members) and, in the case of public derived data, it must also be published under the ODbL license.


    Go


    And now we’ll plunge into this data. Today our goal is to extract addresses from them and get their coordinates. And we will do this not individually, as the geocoders do - by entering the address and receiving coordinates, but all available at once. We will save the result in CSV.


    The peculiarity of the simple method is that we do not need any databases, know to copy and paste. But to make this possible, you have to make sacrifices. Namely, our simplification is that we will extract addresses for a pre-agreed one settlement. We will simply initially limit our searches to a given territory - we will cut the desired settlement out of a common data set.


    Raw material


    So, the starting point is OSM data about the entire planet . But they are very large, so if we do not need coverage of the entire planet, then we take more local territories, for example, Geofabric is divided into continents. For the Russian segment, the best option is Gis-Lab , where files by region are conveniently cut. We take the necessary region file in pbf format.


    Instruments


    For further work, we will need the osmconvert and osmfilter tools . Using the first one, you can convert data from different formats and crop, leaving only the areas of interest, thereby reducing the volume and, as a result, the processing speed. The second is designed to filter objects by their properties.


    Circumcisionhmm ... Cutting an area


    As agreed, we need to localize data only for our locality. With osmconvert, this can be done clumsily by defining a bounding rectangle with two points. The parameter is set for this by the southwestern point and northeast point. If the settlement has a complex shape and a rectangular cutout is not suitable, you can create a polygon of cropping from broken lines. The parameter for specifying such a file will be . Its format is quite simple: the first line is the name; then “1” circuit number; then we list the coordinates of the points that would completely cover our NP and where the last point closes with the first; end of contour; end of file. More information about the format and how to get it .-b=,,,-B=file.poly


    And here is an example file:


    kursk
    1
       36.035249   51.838105
       35.991534   51.562810
       36.125976   51.563141
       36.317305   51.681037
       36.333813   51.780274
       36.159021   51.837612
       36.035249   51.838105
    END
    END

    The main thing is that houses from neighboring NPs do not get into our cut-out area. Also, to simplify, we turn all the houses into points, for this we use the key --all-to-nodes. We ask you to make the output file in o5m format (just specify the file extension), since another utility can only work with it.


    As a result, the first command we will have is this:


    osmconvert.exe -B=city.poly --all-to-nodes RU-Region.pbf -o=1_to-node.o5m

    Now we have point data only from the given area. But there is a lot of things that we ultimately do not need, such as roads, parks, fences, etc.


    Filtration


    Therefore, the next step is to filter out only houses containing addresses from the whole variety. Houses in OSM are indicated by the building tag , and address information in tags starting with addr . We also drop the information about the author and the version of the object; we simply do not need it.


    osmfilter.exe 1_to-node.o5m --keep="building AND addr*" --drop-author --drop-version -o=2.building-addr.o5m

    Well, the file has again decreased in size and now the time has come to see what is left inside. It's time to turn it into something human-readable. As promised, this will be CSV.


    Result


    We will use the same osmconvert, which provides output to CSV. From the parameters it is worth focusing on the columns and from which tags information is inserted into them.


    osmconvert.exe 2.building-addr.o5m -o=3.addr.csv --csv-headline --csv-separator=; --csv="@id addr:street addr:housenumber @lat @lon"

    @idaddr: streetaddr: housenumber@lat@lon
    1000000147959515Masalova street25A51.652250936.0337820
    1000000147960436School Street7151.654653636.0139438
    1000000147965426Kotova Gora street151.733738336.1837660

    Well, this is already some kind of geodata and you can insert it into the GIS and somehow analyze it, as you can see in the picture presented at the beginning.


    But the topic is not limited to addresses. At the second step, you can leave for example public transport stops and visualize transport accessibility. However, this is already from a completely different article ...

    Read Next