-
Notifications
You must be signed in to change notification settings - Fork 11
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(): Toggle geographic columns returned #58
Comments
Thank you for reporting. The reason for this behavior of library(hereR)
set_verbose(TRUE)
addr_1 <- "boston, massachusetts"
addr_2 <- "massachusetts"
url_1 <- geocode(addr_1, url_only = TRUE)
url_2 <- geocode(addr_2, url_only = TRUE)
json_1 <- hereR:::.get_content(url_1)
#> Sending 1 request(s) to: 'https://geocoder.ls.hereapi.com/6.2/geocode.json?...'
#> Received 1 response(s) with total size: 1.2 Kb
json_2 <- hereR:::.get_content(url_2)
#> Sending 1 request(s) to: 'https://geocoder.ls.hereapi.com/6.2/geocode.json?...'
#> Received 1 response(s) with total size: 1.1 Kb See the First responsejsonlite::prettify(json_1)
#> {
#> "Response": {
#> "MetaInfo": {
#> "Timestamp": "2020-08-26T18:04:05.229+0000"
#> },
#> "View": [
#> {
#> "_type": "SearchResultsViewType",
#> "ViewId": 0,
#> "Result": [
#> {
#> "Relevance": 1.0,
#> "MatchLevel": "city",
#> "MatchQuality": {
#> "State": 1.0,
#> "City": 1.0
#> },
#> "Location": {
#> "LocationId": "NT_0iuf-KHj2X8GfdEYL.GQXD",
#> "LocationType": "point",
#> "DisplayPosition": {
#> "Latitude": 42.35866,
#> "Longitude": -71.05675
#> },
#> "NavigationPosition": [
#> {
#> "Latitude": 42.35866,
#> "Longitude": -71.05675
#> }
#> ],
#> "MapView": {
#> "TopLeft": {
#> "Latitude": 42.39726,
#> "Longitude": -71.19121
#> },
#> "BottomRight": {
#> "Latitude": 42.22786,
#> "Longitude": -70.80852
#> }
#> },
#> "Address": {
#> "Label": "Boston, MA, United States",
#> "Country": "USA",
#> "State": "MA",
#> "County": "Suffolk",
#> "City": "Boston",
#> "PostalCode": "02109",
#> "AdditionalData": [
#> {
#> "value": "United States",
#> "key": "CountryName"
#> },
#> {
#> "value": "Massachusetts",
#> "key": "StateName"
#> },
#> {
#> "value": "Suffolk",
#> "key": "CountyName"
#> },
#> {
#> "value": "N",
#> "key": "PostalCodeType"
#> }
#> ]
#> }
#> }
#> }
#> ]
#> }
#> ]
#> }
#> }
#> Second responsejsonlite::prettify(json_2)
#> {
#> "Response": {
#> "MetaInfo": {
#> "Timestamp": "2020-08-26T18:04:05.243+0000"
#> },
#> "View": [
#> {
#> "_type": "SearchResultsViewType",
#> "ViewId": 0,
#> "Result": [
#> {
#> "Relevance": 1.0,
#> "MatchLevel": "state",
#> "MatchQuality": {
#> "State": 1.0
#> },
#> "Location": {
#> "LocationId": "NT_xsuPM8XX3.ynKq8rCjhCcB",
#> "LocationType": "point",
#> "DisplayPosition": {
#> "Latitude": 42.35866,
#> "Longitude": -71.05675
#> },
#> "NavigationPosition": [
#> {
#> "Latitude": 42.35866,
#> "Longitude": -71.05675
#> }
#> ],
#> "MapView": {
#> "TopLeft": {
#> "Latitude": 42.88677,
#> "Longitude": -73.50814
#> },
#> "BottomRight": {
#> "Latitude": 41.13234,
#> "Longitude": -69.92823
#> }
#> },
#> "Address": {
#> "Label": "MA, United States",
#> "Country": "USA",
#> "State": "MA",
#> "AdditionalData": [
#> {
#> "value": "United States",
#> "key": "CountryName"
#> },
#> {
#> "value": "Massachusetts",
#> "key": "StateName"
#> }
#> ]
#> }
#> }
#> }
#> ]
#> }
#> ]
#> }
#> }
#> A quick fix for your automated workflow could be data.table::rbindlist(
list(
geocode(addr_1, sf = FALSE),
geocode(addr_2, sf = FALSE)
),
fill = TRUE
)
#> Sending 1 request(s) to: 'https://geocoder.ls.hereapi.com/6.2/geocode.json?...'
#> Received 1 response(s) with total size: 1.2 Kb
#> Sending 1 request(s) to: 'https://geocoder.ls.hereapi.com/6.2/geocode.json?...'
#> Received 1 response(s) with total size: 1.1 Kb
#> id address postalCode city county state country type
#> 1: 1 Boston, MA, United States 02109 Boston Suffolk MA USA point
#> 2: 1 MA, United States <NA> <NA> <NA> MA USA point
#> lng lat
#> 1: -71.05675 42.35866
#> 2: -71.05675 42.35866 I will consider adding consistent columns in the return value of Session info
|
Thank you for such a detailed response! I came across |
The columns are now consistently the same, regardless of the level of the input address. library(hereR)
set_verbose(TRUE)
geocode("boston, massachusetts", sf = FALSE)
#> Sending 1 request(s) to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 1 response(s) with total size: 896 bytes
#> id address type street house_number postal_code
#> 1 1 Boston, MA, United States locality <NA> <NA> 02109
#> district city county state country lng_access lat_access
#> 1 <NA> Boston Suffolk Massachusetts United States NA NA
#> lng_position lat_position
#> 1 -71.05674 42.35866
geocode("massachusetts", sf = FALSE)
#> Sending 1 request(s) to: 'https://geocode.search.hereapi.com/v1/geocode?...'
#> Received 1 response(s) with total size: 832 bytes
#> id address type street house_number postal_code
#> 1 1 MA, United States administrativeArea <NA> <NA> <NA>
#> district city county state country lng_access lat_access
#> 1 <NA> <NA> <NA> Massachusetts United States NA NA
#> lng_position lat_position
#> 1 -71.05674 42.35866 To check, install the development version from GitHub: |
@munterfinger thanks for adding this. I'm noticing that in the latest package release, the Is this a change that comes from hereR, or from the HERE API itself? Either way, do you know whether the country names returned are ISO standard names, or something else? This is a change that breaks some code I had written. That's okay--I'm updating my code accordingly. But I do need to convert those country names back to the ISO codes for consistency with my previous results, so I need to know what standards the names are following. EDIT: Actually, it seems like the names returned are not ISO standard names, and I can't tell what they are. In an example I just ran, I got "United States", but "Brasil" (not "Brazil"). I can't find a system of country names that would include both of those. If you know which country names are being used, that would be great. If not, is there a way to still return those country codes? |
I've noticed that depending on the specificity of the address sent to
hereR::geocode()
, different columns are returned in the resulting sf/data frame object.Here's a reproducible example (assuming you have the geocoding API set up):
Note that because
vec2
could not be geocoded more precisely than a US state, additional columns (city, county, postalCode) don't show up.I can understand why this behavior would be desired: it prevents the user from getting back a needlessly-large data frame with a huge number of NA values. But I'm trying to write an automated workflow where I'll be geocoding addresses at varying levels of specificity. I need to know ahead of time what columns will be present in my output data frame, so that I can write functions to operate on it without first checking whether the county/state/city columns exist.
Is there currently a way to toggle the inclusion of additional columns in
geocode()
? If not, would you consider adding this feature? Maybe an argumentshow_all_cols
that defaults to FALSE, or something of that nature.The text was updated successfully, but these errors were encountered: