Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upgeocode(): 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 KbSee 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.35866I 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.35866To check, install the development version from GitHub: |
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
vec2could 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_colsthat defaults to FALSE, or something of that nature.