4

I would like to have openstreetmap with offline capabilities. Specifically, I would like to know if it is possible (which I think it is) to geocode a certain adress without using an API. The reason for this is simple, if I have hundreds of thousands of addresses to geocode, it will take forever. I already have the shapefiles, and I know you can download the OSM backend, but I don't know how to "make" R call the offline version of OSM...

Any help would be appreciated.

  • 1
    Remember that "OSM" is just about the plain data. If you need a geocoder then you don't need an "offline version of OSM" but instead an offline OSM-based geocoder. Try to understand the difference. OSM is raw map data whereas a geocoder, a router and so on are a piece of software. There is lots of OSM-based software available but OSM is still just the data and no software itself. – scai Jun 01 '17 at 06:44

2 Answers2

2

For an offline OSM geocoder you can install Nominatim or one of the other OSM-based search engines depending on which geocoder your R package uses.

scai
  • 20,297
  • 4
  • 56
  • 72
  • Thanks for the help, I am very new to this, so if I download nominatim, how do I "connect" R and Nominatim? – Charl Francois Marais May 31 '17 at 09:21
  • Also, if I have Nominatim installed, how do I "link" the shape files I have downloaded to Nominatim? – Charl Francois Marais May 31 '17 at 09:25
  • Theoretically you just have to change the URL to point to your local Nominatim instace. I don't know where to set this configuration since I'm not an R user. Nominatim doesn't work with shape files, it needs OSM data which is usually XML or PBF. See https://wiki.openstreetmap.org/wiki/Nominatim/Installation#Import_and_index_OSM_data – scai May 31 '17 at 09:59
  • Alright, thanks for the help then! I also don't know how to set the configuration... But I think this at least sets me on a path to the right solution. thanks! – Charl Francois Marais May 31 '17 at 10:05
1

I found a solution to my problem, working mainly in R:

First, you will need to clone https://github.com/Project-OSRM/osrm-backend. Then you will need to install and launch docker https://www.docker.com/community-edition

country <- "germany"
# Download new maps - NOTE, this is a large download (more than 3GB)
download.file(url      = paste0("http://download.geofabrik.de/europe/", country, "-latest.osm.pbf"),
          destfile = paste0("./Data/POIs/", country, "/latest.osm.pbf"))
# Download dictionary
download.file(url      = "https://raw.githubusercontent.com/MorbZ/OsmPoisPbf/master/doc/poi_types.csv",
          destfile = paste0("./Data/POIs/", country, "/poi_types_dict.csv"))
pois_dict <- read.csv(paste0("./Data/POIs/", country, "/poi_types_dict.csv", sep = ","))
pois_dict <- pois_dict[!is.na(pois_dict$CODE), ]

# Create local version of search engine car + foot
cmd1 <- paste0("cd ",getwd(),"/Data/POIs/", country)
cmd2 <- paste0("docker run -t -v $(pwd):/data osrm/osrm-backend osrm-extract -p /opt/car.lua /data/latest.osm.pbf")
cmd3 <- paste0("docker run -t -v $(pwd):/data osrm/osrm-backend osrm-contract /data/latest.osrm")
cmd4 <- paste0("docker run -t -i -p 5000:5000 -v $(pwd):/data osrm/osrm-backend osrm-routed /data/latest.osrm")

system(paste(cmd1, cmd2, cmd3, cmd4, sep = "; "))

Then you are able to call the following line (update the longitude latitudes as needed)

txt <- getURL("http://127.0.0.1:5000/route/v1/driving/13.388860,53.517037;13.385983,52.496891?overview=false")

A few extra notes:

1) This is obviously for OSRM, but similar techniques can be used for OSM as well.

2) The file size might be to big, docker only allocates 1000Mb as default, you will need to change this depending on your requirements.

3) The final result obtained needs to be formated (with regular expressions) to get what you need.