-
Notifications
You must be signed in to change notification settings - Fork 0
/
prj2epsg.py
executable file
·38 lines (33 loc) · 1016 Bytes
/
prj2epsg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python3.6
import sys
try:
import requests
except ImportError as err_import:
print("Erreur à l'import de requests")
print(err_import)
sys.exit(1)
def main():
print(prj2epsg(sys.argv[1]))
def prj2epsg(prjfile):
try:
with open(prjfile, mode="r", encoding="utf-8") as prj:
r = requests.get(
"http://prj2epsg.org/search.json",
params={"mode": "wkt", "terms": prj.read()}
)
if r.status_code == 200:
resp = r.json()
if resp["exact"]:
epsg = resp["codes"][0]["code"]
return epsg
else:
print("prj2epsg() pas de match exact")
return None
else:
print("prj2epsg() ERREUR : status_code", r.status_code)
return None
except Exception as e:
print("prj2epsg() ERREUR: ", e)
return None
if __name__ == "__main__":
main()