hrbrmstr / nominatim

:earth_asia: Tools for Working with the 'Nominatim' API in R
Other
75 stars 20 forks source link

Allow geocoding from "http://nominatim.openstreetmap.org/search" #16

Open Pierre-Andre opened 6 years ago

Pierre-Andre commented 6 years ago

Is it possible to allow geocoding from "http://nominatim.openstreetmap.org/search" in osm_geocode ?

As the option NOMINATIM.search_base allow to change the base url for search it could be done. Below a proposition: 1) Allow search without API key when NOMINATIM.search is not the default: change the following piece of code (in osm_geocode function)

if (nchar(key) == 0) {
        stop("Please provide a openstreet API key")
    }

with

if ((getOption("NOMINATIM.search_base")=="http://open.mapquestapi.com/nominatim/v1/search.php")&(nchar(key) == 0)) {
        stop("Please provide a MapQuest API key")
    }

2) Change " " with "%20" (and not "+") I suppose that this change does not break anything in mapquest search (not tested in mapquest !) change the following piece of code (in osm_geocode function)

        param_base <- sprintf("%s/%s", getOption("NOMINATIM.search_base"), 
            gsub(" ", "+", query[i]))

with

        param_base <- sprintf("%s/%s", getOption("NOMINATIM.search_base"), 
            gsub(" ", "\\%20", query[i]))

3) Add the key only when needed change the following line params <- sprintf("%s&key=%s", params, key) with if (key!="") params <- sprintf("%s&key=%s", params, key)

As I do not use other function in nominatim I don't know if other changes are needed...

Thanks Pierre-Andre