In [34]:
%matplotlib inline
import pandas as pd
import geopandas as gpd
import datetime
import os
import shapely
from matplotlib import pyplot as plt; plt.rcParams['figure.figsize'] = 15, 5
CAN_SHP = '../reports/shapefiles/Canada/Canada.shp' #Canada geography shape file
LOC_PKL_FILE = '../data/interim/locations.pkl' #Location pickle file
In [35]:
canada = gpd.read_file(CAN_SHP)
del canada['NOM'] #Drop the french name
canada.crs #Coordinate Reference System
Out[35]:
NAD83 (North American Datum, 1983) is the "datum", as in, where the coordinates are centered. I believe...
'aea' is the 'Albers Equal Area' conic projection, the standard projection for north america, and a seemingly reasonable one to use for this project.
In [38]:
fig, ax = plt.subplots(1,1)
ax.set_title('Canada')
ax.axes.get_yaxis().set_ticks([]) #Remove x/y ticks
ax.axes.get_xaxis().set_ticks([])
canada.plot(ax = ax) #Specify color = 'white' to plot without colour
Out[38]:
In [39]:
D_loc = pd.read_pickle(LOC_PKL_FILE)
D_loc.head()
Out[39]:
In [40]:
#WARN: Pay attention that point takes (x, y) arguments, hence give it (long, lat), NOT (lat, long)!
#WARN: The longitude values are provided as deg E, but should be deg W, so we add the negative sign.
Point = shapely.geometry.Point
station_geometry = [Point(latlon) for latlon in zip(-D_loc['lon'], D_loc['lat'])]
stations = gpd.GeoDataFrame(pd.DataFrame(D_loc['Name'].values, columns = ['NAME']),
geometry = station_geometry,
crs = {'init': 'epsg:4326'})
stations.to_crs(crs = canada.crs, inplace = True)
In [41]:
stations.head()
Out[41]:
In [42]:
fig, ax = plt.subplots(1,1)
ax.set_title('Canada')
ax.axes.get_yaxis().set_ticks([]) #Remove x/y ticks
ax.axes.get_xaxis().set_ticks([])
stations.plot(ax = ax, marker = 'X', markersize = 6, color = 'red')
canada.plot(ax = ax, color = 'white')
Out[42]:
In [45]:
LineString = shapely.geometry.LineString
ls1 = LineString((station_geometry[0], station_geometry[1]))
In [48]:
lines = gpd.GeoDataFrame(pd.DataFrame(['line1']), geometry=[ls1], crs={'init': 'epsg:4326'})
lines.to_crs(crs=canada.crs, inplace=True)
In [50]:
lines.plot?
In [49]:
fig, ax = plt.subplots(1,1)
ax.set_title('Canada')
ax.axes.get_yaxis().set_ticks([]) #Remove x/y ticks
ax.axes.get_xaxis().set_ticks([])
stations.plot(ax = ax, marker = 'X', markersize = 6, color = 'red')
canada.plot(ax = ax, color = 'white')
lines.plot(ax=ax)
Out[49]:
In [ ]: