2

I have a list of some districts in the city of Tehran which are saved in Persian in a CSV file. My first goal is to find these districts lat-lon. In order to load them correctly, I should set the system's locale to "Persian"

Sys.setlocale(locale = "persian")

but, I have found that when I try to use them as arguments in functions like geocode() from ggmap library, it doesn't work!

>geocode(c[1])
Information from URL : http://maps.googleapis.com/maps/api/geocode/json? 
address=%C2%CC%E6%CF%C7%E4%ED%E5&sensor=false
lon lat
1  NA  NA
Warning messages:
1: In readLines(connect, warn = FALSE) :
  cannot open URL 'http://maps.googleapis.com/maps/api/geocode/json? 
address=%C2%CC%E6%CF%C7%E4%ED%E5&sensor=false': HTTP status was '400 Bad 
Request'
2: In geocode(c[1]) :   geocoding failed for "آجودانيه".
  if accompanied by 500 Internal Server Error with using dsk, try google.

here c is my vector of Persian districts.

on the other hand, when I change system locale to English and type the district in Persian in geocode(), it works correctly.

>geocode("آجودانیه")
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=%D8%A2%D8%AC%D9%88%D8%AF%D8%A7%D9%86%DB%8C%D9%87&sensor=false


      lon      lat
1 51.4861 35.80742

how can I find these districts lat-lon?

as a summary, when system locale is in Persian I receive NAs and when I return locale to English it works correctly.

mjoudy
  • 149
  • 1
  • 1
  • 10
  • @SymbolixAU: I changed it, but still doesn't work. As I have written, when system locale is in Persian I receive NAs and when I return locale to English it works correctly – mjoudy May 06 '18 at 09:30
  • @SymbolixAU: yes, I meant I tried it in R. but now I have edited the post. thank you for your attention. – mjoudy May 06 '18 at 10:12

1 Answers1

4

I've built a worldwide geocoding api and I'm happy to notice it works either way in your case:

https://geocode.xyz/%D8%A2%D8%AC%D9%88%D8%AF%D8%A7%D9%86%D9%8A%D9%87

- Iran x,y z: 35.79860,51.47870  
- Ajwdnyh, IR Iran » Confidence Score: 0.90

http://geocode.xyz/%D8%A2%D8%AC%D9%88%D8%AF%D8%A7%D9%86%DB%8C%D9%87

- 
- آجودانیه, IR Iran » Confidence Score: 0.90

Or if you prefer XML output : http://geocode.xyz/%D8%A2%D8%AC%D9%88%D8%AF%D8%A7%D9%86%DB%8C%D9%87?geoit=xml

<geodata>
<latt>35.79860</latt>
<longt>51.47870</longt>
<elevation/>
<standard>
<addresst/>
<postal/>
<prov>IR</prov>
<city>ajwdnyh</city>
<countryname>Iran</countryname>
<confidence>0.90</confidence>
</standard>
<alt></alt>
</geodata>

.. and json : http://geocode.xyz/%D8%A2%D8%AC%D9%88%D8%AF%D8%A7%D9%86%DB%8C%D9%87?geoit=json

{   
  "standard" : { 
    "addresst" : {},
    "city" : "ajwdnyh",
    "prov" : "IR",
    "countryname" : "Iran",
    "postal" : {},
     "confidence" : "0.90"   
  },   
  "longt" : "51.47870",   
  "alt" : {},   
  "elevation" : {},   
  "latt" : "35.79860"
}

PS. You may also upload your CSV file for batch geocoding here: https://geocode.xyz/batch

SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
Ervin Ruci
  • 829
  • 6
  • 10
  • thank you so much. I will use it at last. but, in order to reproducibility, I should write a code which takes districts names from my csv file and find their lat-lon. this can't be done because of system locale contradiction !!! – mjoudy May 06 '18 at 14:01
  • 1
    If you have bash in your terminal you can use the following bash script: #!/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" Save as geocode.sh then chmod a+x geocode.sh then run it as: ./geocode.sh input.csv>output.csv – Ervin Ruci May 06 '18 at 14:58
  • great! although I'm not good to bash scripting, I will start with this. thank you so much – mjoudy May 06 '18 at 22:44