-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetlocations.py
More file actions
25 lines (23 loc) · 766 Bytes
/
getlocations.py
File metadata and controls
25 lines (23 loc) · 766 Bytes
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
import numpy as np
import geopy
from geopy.geocoders import Nominatim
import psycopg2
from config import config
def getlocations(ARRAY, File_Id):
location = Nominatim(user_agent="GetLoc")
params = config()
conn = psycopg2.connect(**params)
cur = conn.cursor()
for Temp_location in ARRAY:
print(Temp_location)
try:
getLocation = location.geocode(Temp_location)
lat = getLocation.latitude
lon = getLocation.longitude
cur.execute(f'''insert
into
location_geom(latitude, longitude, movement_geom,upload_id)
values({lat}, {lon}, st_setsrid(st_makepoint({lon},{lat}),4326), {File_Id})''')
conn.commit()
except:
return