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

Add geocode.xyz service #158

Merged
merged 3 commits into from
Jan 29, 2022
Merged

Add geocode.xyz service #158

merged 3 commits into from
Jan 29, 2022

Conversation

dieghernan
Copy link
Contributor

@dieghernan dieghernan commented Jan 23, 2022

Closes #151

Hi @jessecambon ,this would add geocode.xyz to the list of new geocoders, although I am not completely of this API:

  • First of all, it throttles constantly, even honoring the rate limit. If you run the test line by line it works, but I am not sure if it would be a good fit for geocoding more than 5 lines at once.
  • Second: The output format is not consistent, I had to perform some modifications on the format_address() function trying to guess a suitable output:
  • Third: Batch geocoding is not implemented on the PR. The API mentiones it, but I am not familiar with this language:
#!/bin/bash
while IFS='' read -r line || [[ -n "$line" ]]; do
    echo $line,`curl -X POST -d locate="$line" -d geoit="csv" https://geocode.xyz`;
done < "$1"

I have to say that it looks to me as a simple loop, pretty much the same we do using the single option.

  • I didn't update the README so far

Again, feel free to test this or even reject it, as I say I am not convinced at all. Regards

@dieghernan
Copy link
Contributor Author

dieghernan commented Jan 23, 2022

Additional comments (1)

  • Error testing is hard. The api entry url doesn’t return errors if the required parameter is not present: check https://geocode.xyz/?geoit=json, that returns: 200, OK.
  • Result parsing is also weird. On null value it returns a list of lenght(0) instead of NULL, as the rest of services. That’s why I needed to tibble::as_tibble_row(unlist())

@jessecambon jessecambon changed the base branch from main to geocode.xyz January 29, 2022 19:30
@jessecambon jessecambon merged commit fe9f9af into jessecambon:geocode.xyz Jan 29, 2022
@jessecambon
Copy link
Owner

jessecambon commented Jan 29, 2022

@dieghernan thanks! I'll play around with it a bit. I do see what you mean about the error handling. I ran the same query twice in short succession and the first time it gave errors while the second time it worked fine:

> geo(sample_addresses$addr, method = 'geocode.xyz', full_results = TRUE)
Passing 9 addresses to the Geocode.xyz single address geocoder
[-------------------------------------------------------------] 0/9 (  0%) Elapsed:  0s Remaining:  ?sError: 
[=============>-----------------------------------------------] 2/9 ( 22%) Elapsed:  6s Remaining: 19sError: 
[==========================>----------------------------------] 4/9 ( 44%) Elapsed:  9s Remaining: 11sError: 
[=============================================================] 9/9 (100%) Elapsed: 14s Remaining:  0s
# A tibble: 9 × 13
  address       lat   long frmt_address      stnumber addresst postal region zip   prov  geocode.xyz_city countryname 
  <chr>       <dbl>  <dbl> <chr>             <chr>    <chr>    <chr>  <chr>  <chr> <chr> <chr>            <chr>       
1 1600 Penns… NA      NA   NA                NA       NA       NA     NA     NA    NA    NA               NA          
2 600 Montgo… 37.8  -122.  600, Montgomery … 600      Montgom… 94111  CA     94111 US    San Francisco    United Stat…
3 11 Wall St… NA      NA   NA                NA       NA       NA     NA     NA    NA    NA               NA          
4 233 S Wack… 41.9   -87.6 233, S Wacker Dr… 233      S Wacke… 60606  IL     60606 US    Chicago          United Stat…
5 1 Rue des … NA      NA   NA                NA       NA       NA     NA     NA    NA    NA               NA          
6 Nashville,… NA      NA   NA                NA       NA       NA     NA     NA    NA    NA               NA          
7 Nairobi, K… -1.27   36.8 Nairobi, KE, Ken… NA       NA       NA     NA     NA    KE    Nairobi          Kenya       
8 Istanbul, … 41.0    29.0 Istanbul, TR, Tu… NA       NA       NA     NA     NA    TR    Istanbul         Turkey      
9 Tokyo, Jap… 35.7   140.  Tokyo, JP, Japan  NA       NA       NA     NA     NA    JP    Tokyo            Japan       
# … with 1 more variable: confidence <chr>
Warning messages:
1: In query_api(api_url, api_query_parameters, method = method) :
  Forbidden (HTTP 403).
2: In query_api(api_url, api_query_parameters, method = method) :
  Forbidden (HTTP 403).
3: In query_api(api_url, api_query_parameters, method = method) :
  Forbidden (HTTP 403).
> geo(sample_addresses$addr, method = 'geocode.xyz', full_results = TRUE)
Passing 9 addresses to the Geocode.xyz single address geocoder
[===========================================================================] 9/9 (100%) Elapsed: 17s Remaining:  0s
# A tibble: 9 × 15
  address      lat   long frmt_address       stnumber addresst postal region latt  geocode.xyz_city  zip   longt prov 
  <chr>      <dbl>  <dbl> <chr>              <chr>    <chr>    <chr>  <chr>  <chr> <chr>             <chr> <chr> <chr>
1 1600 Penn… 38.9   -77.0 1600, Nw Pennsylv… 1600     Nw Penn… 20500  DC     38.8… 1600 Pennsylvani… 20500 -76.… US   
2 600 Montg… 37.8  -122.  600, Montgomery S… 600      Montgom… 94111  CA     NA    San Francisco     94111 NA    US   
3 11 Wall S… 40.7   -74.0 11, Wall St, 1000… 11       Wall St  10005  NY     NA    New York          10005 NA    US   
4 233 S Wac… 41.9   -87.6 233, S Wacker Dr,… 233      S Wacke… 60606  IL     NA    Chicago           60606 NA    US   
5 1 Rue des… 46.8   -71.2 1, des Carrieres,… 1        des Car… G1R4P5 QC     NA    Quebec            G1R4… NA    CA   
6 Nashville… NA      NA   NA                 NA       NA       NA     NA     NA    NA                NA    NA    NA   
7 Nairobi, … -1.27   36.8 Nairobi, KE, Kenya NA       NA       NA     NA     NA    Nairobi           NA    NA    KE   
8 Istanbul,… 41.0    29.0 Istanbul, TR, Tur… NA       NA       NA     NA     NA    Istanbul          NA    NA    TR   
9 Tokyo, Ja… 35.7   140.  Tokyo, JP, Japan   NA       NA       NA     NA     NA    Tokyo             NA    NA    JP   
# … with 2 more variables: countryname <chr>, confidence <chr>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for the geocode xyz service
2 participants