Loading CSV with geometry

To ensure that a table (address data from OpenAddresses in this case) with latitude and longitude columns is imported as a geospatial dataset, we have to use the Shapely library's Point class. Each Point geometry is generated from the LON and LAT fields of the address dataset which has been imported:

import geopandas as gdp
import cartoframes
import pandas as pd
from shapely.geometry import Point
APIKEY = "{API KEY}"
cc = cartoframes.CartoContext(base_url='https://{username}.carto.com/',
api_key=APIKEY)
address_df = pd.read_csv(r'data/city_of_juneau.csv')
geometry = [Point(xy) for xy in zip(address_df.LON, address_df.LAT)]
address_df = address_df.drop(['LON', 'LAT'], axis=1)
crs = {'init': 'epsg:4326'}
geo_df = gdp.GeoDataFrame(address_df, crs=crs, geometry=geometry)
cc.write(geo_df, 'juneau_addresses')
Ensure that the GeoPandas library is imported before CARTOframes to avoid import errors from the Fiona library.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset