Giter VIP home page Giter VIP logo

nominatim's Introduction

nominatim is an R package to interface to the OpenStreeMap Nominatim API.

From the wiki:

Nominatim (from the Latin, 'by name') is a tool to search OSM data by name and address and to generate synthetic addresses of OSM points (reverse geocoding). It can be found at nominatim.openstreetmap.org.

Nominatim is also used as one of the sources for the search box on the OpenStreetMap home page. Several companies provide hosted instances of Nominatim that you can query via an API, for example see MapQuest Open Initiative, PickPoint or the OpenCage Geocoder.

Most functions hit the MapQuest Nominatim API as recommended by OpenStreetMap.

The following functions are implemented:

  • address_lookup: Lookup the address of one or multiple OSM objects like node, way or relation.
  • osm_geocode: Search for places by address
  • osm_search: Search for places
  • osm_search_spatial: Search for places, returning a list of 'SpatialPointsDataFrame', 'SpatialLinesDataFrame' or a 'SpatialPolygonsDataFrame'
  • reverse_geocode_coords: Reverse geocode based on lat/lon
  • reverse_geocode_osm: Reverse geocode based on OSM Type & Id
  • bb_lookup: Bounding box (and other metadata) lookup

News

  • Version 0.2.1.9000 released : bb_lookup can also take an sp::bbox-like matrix as value to viewbox
  • Version 0.2.0.9000 released : bb_lookup
  • Version 0.1.1.9000 released : address lookup, switch API server, API timeout watch
  • Version 0.1.0.9000 released : "spatial" stuff
  • Version 0.0.0.9000 released

NOTE

TODO

  • Enable configuration of timeout
  • Enable switching Nominatim API server providers
  • Better spatial support

Installation

devtools::install_github("hrbrmstr/nominatim")

Usage

library(nominatim)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#> Nominatim Usage Policy: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
#> MapQuest Nominatim Terms of Use: http://info.mapquest.com/terms-of-use/

# current verison
packageVersion("nominatim")
#> [1] '0.2.1.9000'

# Reverse geocode Canadian embassies
# complete list of Canadian embassies here:
# http://open.canada.ca/data/en/dataset/6661f0f8-2fb2-46fa-9394-c033d581d531

embassies <- data.frame(
  lat=c("34.53311", "41.327546", "41.91534", "36.76148", "-13.83282",
        "40.479094", "-17.820705", "13.09511", "13.09511"),
  lon=c("69.1835", "19.818698", "12.50891", "3.0166", "-171.76462",
        "-3.686115", "31.043559", "-59.59998", "-59.59998"),
  osm_type=c("R", "W", "R", "N", "N", "W", "R", "N", "N"),
  osm_id=c("3836233", "267586999", "3718093", "501522082", "305640297",
           "309487691", "2793217", "501458399", "501458399"),
  stringsAsFactors=FALSE)

emb_coded_coords <- reverse_geocode_coords(embassies$lat, embassies$lon)
head(emb_coded_coords)
#> Source: local data frame [6 x 24]
#> 
#>     place_id                                                                             licence osm_type     osm_id
#> 1  141554854 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way  251884280
#> 2  140380416 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way  248349387
#> 3   17419117 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 1690405094
#> 4   23022786 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 2261850466
#> 5    6676195 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node  687791952
#> 6 2657152894 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way   98280735
#> Variables not shown: lat (dbl), lon (dbl), display_name (chr), address29 (chr), road (chr), city (chr), state (chr),
#>   country (chr), country_code (chr), monument (chr), village_green (chr), county (chr), postcode (chr), bus_stop (chr),
#>   neighbourhood (chr), suburb (chr), city_district (chr), house_number (chr), pub (chr), house (chr)

emb_coded_osm <- reverse_geocode_osm(embassies$osm_type, embassies$osm_id)
head(emb_coded_osm)
#> Source: local data frame [6 x 16]
#> 
#>     place_id                                                                             licence osm_type    osm_id
#> 1  194135434 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright relation   3836233
#> 2  146632013 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way 267586999
#> 3  151591965 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright relation   3718093
#> 4 2636487072 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 501522082
#> 5    1372733 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 305640297
#> 6 2612043014 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way 309487691
#> Variables not shown: lat (dbl), lon (dbl), display_name (chr), city (chr), county (chr), state (chr), country (chr),
#>   country_code (chr), road (chr), village (chr), town (chr), locality (chr)

# lookup some places from the wiki example

places <- c("R146656", "W104393803", "N240109189")
places_found <- address_lookup(places)
head(places_found)
#> Source: local data frame [3 x 22]
#> 
#>     place_id                                                                             licence osm_type    osm_id
#> 1  127761056 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright relation    146656
#> 2   77769706 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way 104393803
#> 3 2570600569 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 240109189
#> Variables not shown: lat (chr), lon (chr), display_name (chr), class (chr), type (chr), importance (chr), city (chr),
#>   county (chr), state_district (chr), state (chr), country (chr), country_code (chr), address29 (chr), house_number
#>   (chr), pedestrian (chr), suburb (chr), city_district (chr), postcode (chr)

# more general search

osm_search("[bakery]+berlin+wedding", limit=5)
#> Source: local data frame [5 x 15]
#> 
#>     place_id                                                                             licence osm_type     osm_id
#> 1    2520528 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node  346137917
#> 2    6887729 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node  707409445
#> 3   29179742 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 2661679367
#> 4    7161987 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node  762607353
#> 5 2659941153 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 3655549445
#> Variables not shown: lat (dbl), lon (dbl), display_name (chr), class (chr), type (chr), importance (dbl), icon (chr),
#>   bbox_left (dbl), bbox_top (dbl), bbox_right (dbl), bbox_bottom (dbl)

# address search

osm_geocode(c("1600 Pennsylvania Ave, Washington, DC.",
              "1600 Amphitheatre Parkway, Mountain View, CA",
              "Seattle, Washington"))
#> Source: local data frame [3 x 15]
#> 
#>     place_id                                                                             licence osm_type   osm_id
#> 1 2661769953 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright relation  5396194
#> 2   47189532 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way 13367984
#> 3  151183715 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright relation   237385
#> Variables not shown: lat (dbl), lon (dbl), display_name (chr), class (chr), type (chr), importance (dbl), icon (chr),
#>   bbox_left (dbl), bbox_top (dbl), bbox_right (dbl), bbox_bottom (dbl)

# spatial
library(sp)
plot(osm_search_spatial("[bakery]+berlin+wedding", limit=5)[[1]])

# bounding box (et. al.)
bb_lookup("West Yorkshire", c(-4.37, 54.88, 2.04, 52.96))
#>    place_id                                                                             licence osm_type   osm_id
#> 1 127642488 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright relation    88079
#> 2  53947051 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way 15199284
#>           lat               lon
#> 1 53.74152525 -1.72024765303197
#> 2    33.24139       -96.7825009
#>                                                                                            display_name    class
#> 1                                                                        West Yorkshire, United Kingdom boundary
#> 2 West Yorkshire, Crestview at Prosper, Rockhill, Collin County, Texas, 75078, United States of America  highway
#>          type importance        top       left      bottom       right
#> 1  ceremonial  0.5199873 53.5197297 53.9632249  -2.1739695  -1.1988144
#> 2 residential  0.2562500  33.239815  33.242393 -96.7825009 -96.7824669

bb_lookup("United States")
#>     place_id                                                                             licence osm_type     osm_id
#> 1  127658196 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright relation     148838
#> 2   60476969 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way   27423181
#> 3  114115020 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way  250575475
#> 4  125647735 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way  315105902
#> 5  126468268 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright      way  315105903
#> 6 2574545131 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 3381768346
#> 7   18767684 Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright     node 1865902396
#>           lat               lon
#> 1  39.7837304      -100.4458825
#> 2  14.4858002       121.0218547
#> 3  40.7372329 -73.8624768947891
#> 4 38.96692885 -77.1376750544799
#> 5  38.9408694 -77.1185943162839
#> 6  39.2242033       -94.5858773
#> 7  36.2983916       -84.2179138
#>                                                                                                             display_name
#> 1                                                                                               United States of America
#> 2 United States, Better Living Subdivision, Don Bosco, Parañaque, Manila Fővárosi Régió, Metro Manila, 1006, Philippines
#> 3               United States, 97-30, 57th Avenue, Corona, Queens County, NYC, New York, 11368, United States of America
#> 4                                                                                United States, United States of America
#> 5                                                                                United States, United States of America
#> 6  Gladstone Post Office, 7170, North Broadway Avenue, Gladstone, Clay County, Missouri, 64118, United States of America
#> 7             Caryville Post Office, Hill Street, Caryville, Campbell County, Tennessee, 37714, United States of America
#>      class           type importance
#> 1 boundary administrative   1.144692
#> 2  highway    residential   0.300000
#> 3 building            yes   0.201000
#> 4 boundary  national_park   0.201000
#> 5 boundary protected_area   0.201000
#> 6  amenity    post_office   0.201000
#> 7  amenity    post_office   0.201000
#>                                                                                       icon         top       left
#> 1 https://nominatim.openstreetmap.org/images/mapicons/poi_boundary_administrative.p.20.png -14.7608357 71.6048217
#> 2                                                                                     <NA>  14.4830636 14.4882325
#> 3                                                                                     <NA>  40.7369018  40.737504
#> 4                                                                                     <NA>  38.9661524 38.9679981
#> 5                                                                                     <NA>  38.9404777 38.9412879
#> 6         https://nominatim.openstreetmap.org/images/mapicons/amenity_post_office.p.20.png  39.2241533 39.2242533
#> 7         https://nominatim.openstreetmap.org/images/mapicons/amenity_post_office.p.20.png  36.2983416 36.2984416
#>         bottom       right
#> 1 -179.9999999         180
#> 2  121.0206884 121.0222591
#> 3  -73.8627531 -73.8622348
#> 4  -77.1380857 -77.1373315
#> 5  -77.1188673 -77.1183216
#> 6  -94.5859273 -94.5858273
#> 7  -84.2179638 -84.2178638

Test Results

library(nominatim)
library(testthat)

date()
#> [1] "Tue Aug 11 13:27:22 2015"

test_dir("tests/")
#> testthat results ========================================================================================================
#> OK: 0 SKIPPED: 0 FAILED: 0
#> 
#> DONE

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

nominatim's People

Contributors

calligross avatar hrbrmstr avatar leeper avatar robinlovelace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nominatim's Issues

Package returns data.frames of the incorrect number of rows

Looks like when the search fails it returns a data.frame with 0 rows and rbinds the results, resulting in a data.frame that has fewer rows that the inputs. I'd recommend changing this so the function yields a
data.frame with a single row of NAs (and the same names).

geocode existing house

It is not possible to geocode this adress: "Marburger Straße 15, Bischoffen, Germany". It gets the same lat/long as all other houses in that street.
but if I
"coords<-reverse_geocode_coords(50.7257519, 8.51595342001864, key = "Mykey") I get the detailed Data of this existing adress. Why not by geocode?

osm_search_spatial returns invalid and inaccurate lon/lat data for a UK admin area

I asked a question about this on Stack Overflow but haven't got to the bottom of it.

I want to use nominatim to return a valid spatial object that I can plot as a polygon.

Here's a reprex of my problem with osm_search_spatial :

library(nominatim)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#> Nominatim Usage Policy: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
#> MapQuest Nominatim Terms of Use: http://info.mapquest.com/terms-of-use/
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(tmap)
library(tibble)

# get OSM search results for Ashfield district (UK)
ashfield <- nominatim::osm_search_spatial("Ashfield", limit = 1, key = "KtacQGOTApeFbfDhKaq5cGk8T16V4ioP")
class(ashfield)
#> [1] "list"

# extract SPDF from list
ashfield <- ashfield[[1]]
class(ashfield)
#> [1] "SpatialPolygonsDataFrame"
#> attr(,"package")
#> [1] "sp"

tmap::qtm(ashfield)
#> Warning: The shape ashfield is invalid. See sf::st_is_valid
#> Warning: Currect projection of shape ashfield unknown. Long-lat (WGS84) is
#> assumed.

glimpse(ashfield@data)
#> Observations: 1
#> Variables: 15
#> $ place_id     <chr> "186877616"
#> $ licence      <chr> "Data © OpenStreetMap contributors, ODbL 1.0. https://...
#> $ osm_type     <chr> "relation"
#> $ osm_id       <chr> "154043"
#> $ lat          <dbl> 53.08977
#> $ lon          <dbl> -1.251877
#> $ display_name <chr> "Ashfield, Nottinghamshire, East Midlands, England, Un...
#> $ class        <chr> "boundary"
#> $ type         <chr> "administrative"
#> $ importance   <dbl> 0.2116014
#> $ icon         <chr> "http://ip-10-98-171-248.mq-us-east-1.ec2.aolcloud.net...
#> $ bbox_left    <fct> 53.0080617
#> $ bbox_top     <fct> 53.1714343
#> $ bbox_right   <fct> -1.3445928
#> $ bbox_bottom  <fct> -1.1642542

head(ashfield@polygons[[1]]@Polygons[[1]]@coords)
#>           [,1]      [,2]
#> [1,] -1.344593 -1.344409
#> [2,] 53.063537 53.063260
#> [3,] 53.064985 53.063764
#> [4,] 53.065520 53.065521
#> [5,] 53.065553 53.065526
#> [6,] 53.065725 53.065656

# Convert to an SF object and try again
ashfield_sf <- sf::st_as_sf(ashfield)
class(ashfield_sf)
#> [1] "sf"         "data.frame"

# set CRS
st_crs(ashfield_sf) <- 4326
ashfield_sf$geometry
#> Geometry set for 1 feature 
#> geometry type:  POLYGON
#> dimension:      XY
#> bbox:           xmin: -1.344593 ymin: -1.344593 xmax: 53.17143 ymax: 53.17142
#> epsg (SRID):    4326
#> proj4string:    +proj=longlat +datum=WGS84 +no_defs
#> POLYGON ((-1.344593 -1.344409, 53.06354 53.0632...
tmap::qtm(ashfield_sf)
#> Warning: The shape ashfield_sf is invalid. See sf::st_is_valid

Created on 2020-02-26 by the reprex package (v0.3.0)

Notice how the bbox section of the geometry is incorrect (below): the bbox_left number (a longitude) is using the latitude number for my area, and the bbox_bottom number (a latitude) is using a longitude number for my area. Hence the polygon plotted stretches from west Africa to Russia!

#> $ bbox_left    <fct> 53.0080617
#> $ bbox_top     <fct> 53.1714343
#> $ bbox_right   <fct> -1.3445928
#> $ bbox_bottom  <fct> -1.1642542

Here's a second reprex showing the result of the equivalent "direct" query to the API for comparison:
I have not managed to get the result of this to be a plottable/mappable spatial object though (would appreciate some advice on this by the way!)

library(nominatim)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#> Nominatim Usage Policy: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
#> MapQuest Nominatim Terms of Use: http://info.mapquest.com/terms-of-use/
library(jsonlite)
library(purrr)
#> 
#> Attaching package: 'purrr'
#> The following object is masked from 'package:jsonlite':
#> 
#>     flatten

# try with direct query
ashfield_fromjson <- jsonlite::fromJSON("https://open.mapquestapi.com/nominatim/v1/search.php?key=KtacQGOTApeFbfDhKaq5cGk8T16V4ioP&format=json&q=ashfield&limit=1&polygon_geojson=1")
class(ashfield_fromjson)
#> [1] "data.frame"
# ^^^ I don't know how to turn this data frame into a plottable/tmappable spatial object.
# I have tried various things to try to use the geometry data in this result
# as a spatial object but I have not yet found the right way to do this

ashfield_coords <- ashfield_fromjson %>%
  pluck("geojson", "coordinates", 1) %>%
  matrix(., ncol = 2, dimnames = list(NULL, c("lon", "lat")))
# compare to the result from osm_search_spatial above
head(ashfield_coords)
#>            lon      lat
#> [1,] -1.344593 53.06326
#> [2,] -1.344409 53.06299
#> [3,] -1.344221 53.06276
#> [4,] -1.344161 53.06242
#> [5,] -1.344115 53.06231
#> [6,] -1.344068 53.06225

Created on 2020-02-26 by the reprex package (v0.3.0)

'reverse_base' variable not found

@hrbrmstr @Robinlovelace @rCarto @leeper @calligross

First of all this is a great alternative to Google revgeocode so thank you for working on this. Just have a few minor issues. See below:
I would appreciate you guys helping me on this.

I've encountered this issue when I ran the reverse_geocode function:

reverse_geocode <- function(params) {

tryCatch({

res <- GET(reverse_base, query=params, timeout(getOption("NOMINATIM.TIMEOUT")))
stop_for_status(res)

ret <- content(res)

if (length(ret) == 0) return(NULL)

ret_names <- intersect(names(ret),
                   c("place_id", "licence", "osm_type", "osm_id",
                     "lat", "lon", "display_name", "class", "type", "importance"))
tmp_df <- data.frame(t(sapply(ret_names, function(x) { ret[[x]] })), stringsAsFactors=FALSE)

if ("address" %in% names(ret)) {
  tmp_df <- cbind.data.frame(tmp_df,
                         data.frame(t(sapply(names(ret[["address"]]),
                                             function(x) { ret[["address"]][[x]]} )),
                                    stringsAsFactors=FALSE),
                         stringsAsFactors=FALSE)
}

tmp_df$lat <- as.numeric(tmp_df$lat)
tmp_df$lon <- as.numeric(tmp_df$lon)

return(tmp_df)

}, error=function(e) { message("Error connecting to geocode service", e)})

return(NULL)

}

RESPONSE

 |                                                  | 0 % ~calculating Error connecting to geocode serviceError in GET(reverse_base, query = 
params, timeout(getOption("NOMINATIM.TIMEOUT"))): object 'reverse_base' not 
found
|++++++                                            | 11% ~00s          Error connecting to geocode serviceError in 
GET(reverse_base, query = params, timeout(getOption("NOMINATIM.TIMEOUT"))): object 
'reverse_base' not found

|++++++++++++                                      | 22% ~00s          Error connecting to geocode serviceError 
in GET(reverse_base, query = params, timeout(getOption("NOMINATIM.TIMEOUT"))): object 
reverse_base' not found

|+++++++++++++++++                                 | 33% ~00s          Error connecting to geocode 
 serviceError in GET(reverse_base, query = params, timeout(getOption("NOMINATIM.TIMEOUT"))): 
object ' reverse_base' not found

|+++++++++++++++++++++++                           | 44% ~00s          Error connecting to geocode 
serviceError in GET(reverse_base, query = params, timeout(getOption("NOMINATIM.TIMEOUT"))): 
object 'reverse_base' not found

|++++++++++++++++++++++++++++                      | 56% ~00s          Error connecting to 
geocode serviceError in GET(reverse_base, query = params, 
timeout(getOption("NOMINATIM.TIMEOUT"))): object 'reverse_base' not found

|++++++++++++++++++++++++++++++++++                | 67% ~00s          Error connecting to 
geocode serviceError in GET(reverse_base, query = params, 
timeout(getOption("NOMINATIM.TIMEOUT"))): object 'reverse_base' not found

|+++++++++++++++++++++++++++++++++++++++           | 78% ~00s          Error connecting 
to geocode serviceError in GET(reverse_base, query = params, 
timeout(getOption("NOMINATIM.TIMEOUT"))): object 'reverse_base' not found

|+++++++++++++++++++++++++++++++++++++++++++++     | 89% ~00s          Error 
connecting to geocode serviceError in GET(reverse_base, query = params, 
timeout(getOption("NOMINATIM.TIMEOUT"))): object 'reverse_base' not found

|++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed = 00s

It's looking for the reverse_base variable definition in the GET statement and I can't seem to find it. Please assist. Thanks.

about updating nominatim...

Hi,
I wanted to know how can I update nominatim without setting this line in settings/local.php :

@define('CONST_Replication_Url', 'https://planet.openstreetmap.org/replication/minute');

I mean I don't want to sync with osm, I want to update nominatim whenever I would like.
for example I have a osm data for two months ago, now I want to update them. but I don't know if I set replicarion service with above value, all data are updated from two months ago until now ?
how can I sure that updating process is correct ?

better to use this address ?
http://download.geofabrik.de/europe-updates/

Thanks in Advance

osm_geocode() not returning results for some addresses

osm_geocode appears to only return results for cities, not addresses.

For example, these return results:

osm_geocode("Seattle, Washington", key = osm_api)

osm_geocode("Los Angeles, CA", key = osm_api)

This does not:
osm_geocode("1600 Pennsylvania Ave, Washington, DC.", key = osm_api)

Nor this:
osm_geocode(c("1600 Pennsylvania Ave, Washington, DC.", "1600 Amphitheatre Parkway, Mountain View, CA"), key = osm_api)

Nor does this:
osm_geocode(address_list, key = osm_api), where "address_list" is any list of specific addresses stored in a character vector.

Would there be a reason for this?

Special characters (Umlaut) not supported

Currently, not all query input is accepted — probably due to how the query is formed (on the website, Umlaute are accepted.

You need to replace umlaute to their equivalents first:

library(nominatim)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
#> Nominatim Usage Policy: http://wiki.openstreetmap.org/wiki/Nominatim_usage_policy
#> MapQuest Nominatim Terms of Use: http://info.mapquest.com/terms-of-use/
osm_search("Zurich", key = nominatim_api_key)
#>    place_id
#> 1 187335240
#>                                                                                licence
#> 1 Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
#>   osm_type  osm_id     lat      lon
#> 1 relation 1682248 47.3724 8.542322
#>                                   display_name class type importance
#> 1 Zurich, District Zurich, Zurich, Switzerland place city  0.2858481
#>                                                                                                     icon
#> 1 http://ip-10-98-168-68.mq-us-east-1.ec2.aolcloud.net/nominatim/images/mapicons/poi_place_city.p.20.png
#>   bbox_left bbox_top bbox_right bbox_bottom
#> 1  47.32022 47.43467   8.448006    8.625441
osm_search("Zürich", key = nominatim_api_key)
#> # A tibble: 0 x 0
osm_search("Köln", key = nominatim_api_key)
#> # A tibble: 0 x 0
osm_search("Koln", key = nominatim_api_key)
#>    place_id
#> 1 187156246
#>                                                                                licence
#> 1 Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
#>   osm_type osm_id      lat      lon
#> 1 relation  62578 50.93836 6.959974
#>                                                          display_name
#> 1 Cologne, Cologne Government Region, North Rhine-Westphalia, Germany
#>   class type importance
#> 1 place city  0.1780843
#>                                                                                                     icon
#> 1 http://ip-10-98-176-55.mq-us-east-1.ec2.aolcloud.net/nominatim/images/mapicons/poi_place_city.p.20.png
#>   bbox_left bbox_top bbox_right bbox_bottom
#> 1  50.83045 51.08497    6.77253    7.162028

Created on 2019-08-27 by the reprex package (v0.3.0)

This t

Please provide a openstreet API key

Hello,
The function osm_geocode always return me an error with this messages: "Please provide a openstreet API key".
Where can I get a openstreet API key?
Thanks,

Errors with osm_geocode()

Reproducible example:

osm_geocode(c("1600 Pennsylvania Ave, Washington, DC.",
+     "1600 Amphitheatre Parkway, Mountain View, CA",
+     "Seattle, Washington"))
  |                                                  |   0%
Error connecting to geocode serviceError in doTryCatch(return(expr), name, parentenv, handler): client error: (403) Forbidden

Just tried on two separate computers. Any ideas?

local nominatim

Hi,

I read the osm_geocode method, as far as I understand, you adopted mapquest service in the middle of your client and OSM nominatim. But if somebody has their own open source geocoding server, it is impossible to send request to. Do you have any plan to add a URL modifiable feature to this project?

bb_lookup function

Nominatim allows you to ask for the bounding box of any text string, e.g. (see here):

https://nominatim.openstreetmap.org/search?q=United+Kingdom&format=xml

can we create a function called bb_lookup() that returns a bbox class object for any country/city/region.

It can even find the bb of quite complex regions, such as Yorkshire and the Humber
https://nominatim.openstreetmap.org/search.php?q=Yorkshire+and+the+Humber&viewbox=-78.53%2C42.55%2C-78.42%2C42.51

And West Yorkshire
https://nominatim.openstreetmap.org/search.php?q=West+Yorkshire&viewbox=-4.37%2C54.88%2C2.04%2C52.96

Started looking at this but not sure how best to start - any pointers and I can try. Otherwise more than happy to just test your code!

That would be sooooo useful for many applications, not least our overpass package :-)

match inputs in osm_geocode()

Wondering if there's a way to match or include the input query in the output when using osm_geocode(). I have a list of locations which include some junk entries which won't return a result from osm_geocode(), so when I try geocoding the output just removes all the empty returns and I have no way to figure out which output geocode matches which input query.

See an example here:
I have 6 queries, but osm_geocode() only returns 4 results. That's fine, but then I have no way to match the output with the input.

library(nominatim)
 
locations <- c("Paris-Nice", "Toronto, Ontario", "Philadelphia, PA", " Canada much of the time", "Houston, TX", "Grand Rapids, MI ")
geocodes <- osm_geocode(locations, key = "my_key")

osm_search vs. osm_geocode

Hello,
Can you develop on the difference between these two functions? Is that the parameters order in the searched query?

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

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")
    }
  1. 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]))
  1. 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.