Use this tool to convert a list of addresses into a LineString or Polygon in WKT format.
{ address_text : Addresses ? Place each address on a separate line }
# CrossCompute
target_folder = '/tmp'
address_text_path = 'addresses.txt'
addresses = open(address_text_path).read().splitlines()
addresses
from geopy import GoogleV3
def get_lonlat(address):
# Convert address to latitude and longitude
geocode = GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
location = geocode(address)
return location.longitude, location.latitude
xys = [get_lonlat(_) for _ in addresses]
xys
from shapely.geometry import LineString
line = LineString(xys)
line
from shapely.geometry import Polygon
polygon = Polygon(xys + [xys[0]])
polygon
wkts = [
line.wkt,
polygon.wkt,
]
target_path = target_folder + '/wkts.txt'
open(target_path, 'wt').write('\n'.join(wkts))
print('geometry_text_path = %s' % target_path)
import pandas as pd
target_path = target_folder + '/map.csv'
pd.DataFrame(wkts, columns=['wkt']).to_csv(target_path, index=False)
print('geometry_geotable_path = %s' % target_path)
{ geometry_text : Generated LineString and Polygon in WKT Format }
{ geometry_geotable : Map of Generated LineString and Polygon }