Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geocode: optionally return DisplayPosition #53

Closed
dpprdan opened this issue Aug 18, 2020 · 3 comments
Closed

geocode: optionally return DisplayPosition #53

dpprdan opened this issue Aug 18, 2020 · 3 comments
Assignees
Labels
bug

Comments

@dpprdan
Copy link
Contributor

@dpprdan dpprdan commented Aug 18, 2020

geocode() currently returns the latitude/longitude values of the NavigationPosition.

A navigation position contains the coordinates of a potential route waypoint. It is used for routes that pass through the given location.

From https://developer.here.com/documentation/geocoder/dev_guide/topics/resource-type-response-geocode.html#resource-type-response-geocode__location

Depending on the use case, e.g. mapping, the alternative DisplayPosition may be better suited:

The display position contains the coordinates at which to place a marker indicating the given location on the map.

Would you consider optionally returning the DisplayPosition lat/lng pair? I have been bitten by this, namely that two or more distinct addresse have the same NavigationPosition (i.e. access from the road), but different DisplayPositions.

NavigationPosition and DisplayPosition are respectively called access and position in the v7 API (Navigate to Geocode > Responses > 200 > items).

@dpprdan
Copy link
Contributor Author

@dpprdan dpprdan commented Aug 18, 2020

Not sure what the best way forward would be. I.e. return only one of the two, depending on an additional function argument. Or just return both? Seeing that access is an array of objects and position just an object it might be best to return position as lat/lng columns and access as a list column?

@munterfinger munterfinger self-assigned this Aug 19, 2020
@munterfinger munterfinger added the bug label Aug 19, 2020
@munterfinger
Copy link
Owner

@munterfinger munterfinger commented Aug 19, 2020

Thank you very much for pointing out the difference between the two types of latitude/longitude.

To be honest the choice of the navigation position was not on purpose. As you suggest it seems to make more sense to return the position as default and deliver the navigational optionally via an additional function argument or as an additional simple feature geometry list column (sfc).

When the Geocoding API is updated to v7 as mentioned in #52 the display position (position) instead of the navigational position (access) will be set as default lat/lng in the returned sf, data.frame.

@munterfinger
Copy link
Owner

@munterfinger munterfinger commented Aug 23, 2020

The position and access coordinates are now returned by default:

library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
library(hereR)
set_verbose(TRUE)

(geocoded <- geocode(
  c("Schweighofstrasse 190, Zürich", "Zürich"), sf = FALSE
))
#> Sending 2 request(s) to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 2 response(s) with total size: 1.7 Kb
#>   id                                            address        type
#> 1  1 Schweighofstrasse 190, 8045 Zürich Zürich, Schweiz houseNumber
#> 2  2                                    Zürich, Schweiz    locality
#>              street house_number postal_code district   city county  state
#> 1 Schweighofstrasse          190        8045  Kreis 3 Zürich Zürich Zürich
#> 2              <NA>         <NA>        8001     <NA> Zürich Zürich Zürich
#>   country lng_access lat_access lng_position lat_position
#> 1 Schweiz    8.50752   47.35948      8.50769     47.35955
#> 2 Schweiz       NULL       NULL      8.53977     47.37700

If the returned value should be a sf, data.frame, the coordinates are parsed as geometry list columns. The position coordinates are then set as the default geometry column, which can be accessed by st_geometry():

(geocoded <- geocode(
  c("Schweighofstrasse 190, Zürich", "Zürich"), sf = TRUE
))
#> Sending 2 request(s) to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 2 response(s) with total size: 1.7 Kb
#> Simple feature collection with 2 features and 11 fields
#> Active geometry column: geometry
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 8.50769 ymin: 47.35955 xmax: 8.53977 ymax: 47.377
#> geographic CRS: WGS 84
#>   id                                            address        type
#> 1  1 Schweighofstrasse 190, 8045 Zürich Zürich, Schweiz houseNumber
#> 2  2                                    Zürich, Schweiz    locality
#>              street house_number postal_code district   city county  state
#> 1 Schweighofstrasse          190        8045  Kreis 3 Zürich Zürich Zürich
#> 2              <NA>         <NA>        8001     <NA> Zürich Zürich Zürich
#>   country                   access                 geometry
#> 1 Schweiz POINT (8.50752 47.35948) POINT (8.50769 47.35955)
#> 2 Schweiz              POINT EMPTY   POINT (8.53977 47.377)

st_geometry(geocoded)
#> Geometry set for 2 features 
#> geometry type:  POINT
#> dimension:      XY
#> bbox:           xmin: 8.50769 ymin: 47.35955 xmax: 8.53977 ymax: 47.377
#> geographic CRS: WGS 84
#> POINT (8.50769 47.35955)
#> POINT (8.53977 47.377)

The only downside of this solution is a warning when plotting the geocoded addresses with the {mapview} package:

library(mapview)
#> GDAL version >= 3.1.0 | setting mapviewOptions(fgb = TRUE)

mapview(geocoded)
#> Warning in clean_columns(as.data.frame(obj), factorsAsCharacter): Dropping
#> column(s) access of class(es) sfc_POINT;sfc
Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       macOS Catalina 10.15.6      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2020-08-23                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package           * version    date       lib
#>  assertthat          0.2.1      2019-03-21 [1]
#>  backports           1.1.8      2020-06-17 [1]
#>  base64enc           0.1-3      2015-07-28 [1]
#>  callr               3.4.3      2020-03-28 [1]
#>  class               7.3-17     2020-04-26 [1]
#>  classInt            0.4-3      2020-04-07 [1]
#>  cli                 2.0.2      2020-02-28 [1]
#>  codetools           0.2-16     2018-12-24 [1]
#>  colorspace          1.4-1      2019-03-18 [1]
#>  crayon              1.3.4      2017-09-16 [1]
#>  crosstalk           1.1.0.1    2020-03-13 [1]
#>  curl                4.3        2019-12-02 [1]
#>  data.table          1.13.0     2020-07-24 [1]
#>  DBI                 1.1.0      2019-12-15 [1]
#>  desc                1.2.0      2018-05-01 [1]
#>  devtools            2.3.1      2020-07-21 [1]
#>  digest              0.6.25     2020-02-23 [1]
#>  dplyr               1.0.2      2020-08-18 [1]
#>  e1071               1.7-3      2019-11-26 [1]
#>  ellipsis            0.3.1      2020-05-15 [1]
#>  evaluate            0.14       2019-05-28 [1]
#>  fansi               0.4.1      2020-01-08 [1]
#>  fs                  1.5.0      2020-07-31 [1]
#>  generics            0.0.2      2018-11-29 [1]
#>  glue                1.4.1      2020-05-13 [1]
#>  hereR             * 0.4.1.9000 2020-08-23 [1]
#>  htmltools           0.5.0      2020-06-16 [1]
#>  htmlwidgets         1.5.1      2019-10-08 [1]
#>  jsonlite            1.7.0      2020-06-25 [1]
#>  KernSmooth          2.23-17    2020-04-26 [1]
#>  knitr               1.29       2020-06-23 [1]
#>  lattice             0.20-41    2020-04-02 [1]
#>  leafem              0.1.3      2020-07-26 [1]
#>  leaflet             2.0.3      2019-11-16 [1]
#>  leaflet.providers   1.9.0      2019-11-09 [1]
#>  lifecycle           0.2.0      2020-03-06 [1]
#>  magrittr            1.5        2014-11-22 [1]
#>  mapview           * 2.9.0      2020-08-19 [1]
#>  memoise             1.1.0      2017-04-21 [1]
#>  munsell             0.5.0      2018-06-12 [1]
#>  pillar              1.4.6      2020-07-10 [1]
#>  pkgbuild            1.1.0      2020-07-13 [1]
#>  pkgconfig           2.0.3      2019-09-22 [1]
#>  pkgload             1.1.0      2020-05-29 [1]
#>  png                 0.1-7      2013-12-03 [1]
#>  prettyunits         1.1.1      2020-01-24 [1]
#>  processx            3.4.3      2020-07-05 [1]
#>  ps                  1.3.4      2020-08-11 [1]
#>  purrr               0.3.4      2020-04-17 [1]
#>  R6                  2.4.1      2019-11-12 [1]
#>  raster              3.3-13     2020-07-17 [1]
#>  RColorBrewer        1.1-2      2014-12-07 [1]
#>  Rcpp                1.0.5      2020-07-06 [1]
#>  remotes             2.2.0      2020-07-21 [1]
#>  rlang               0.4.7      2020-07-09 [1]
#>  rmarkdown           2.3        2020-06-18 [1]
#>  rprojroot           1.3-2      2018-01-03 [1]
#>  satellite           1.0.2      2019-12-09 [1]
#>  scales              1.1.1      2020-05-11 [1]
#>  sessioninfo         1.1.1      2018-11-05 [1]
#>  sf                * 0.9-5      2020-07-14 [1]
#>  sp                  1.4-2      2020-05-20 [1]
#>  stringi             1.4.6      2020-02-17 [1]
#>  stringr             1.4.0      2019-02-10 [1]
#>  testthat            2.3.2      2020-03-02 [1]
#>  tibble              3.0.3      2020-07-10 [1]
#>  tidyselect          1.1.0      2020-05-11 [1]
#>  units               0.6-7      2020-06-13 [1]
#>  usethis             1.6.1      2020-04-29 [1]
#>  vctrs               0.3.2      2020-07-15 [1]
#>  webshot             0.5.2      2019-11-22 [1]
#>  withr               2.2.0      2020-04-20 [1]
#>  xfun                0.16       2020-07-24 [1]
#>  yaml                2.2.1      2020-02-01 [1]
#>  
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.