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]:
{'datum': 'NAD83',
 'lat_0': 40,
 'lat_1': 50,
 'lat_2': 70,
 'lon_0': -96,
 'no_defs': True,
 'proj': 'aea',
 'units': 'm',
 'x_0': 0,
 'y_0': 0}

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]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f27c3920c88>

In [39]:
D_loc = pd.read_pickle(LOC_PKL_FILE)
D_loc.head()


Out[39]:
Name WBAN lat lon first_year last_year time_correction WBAN_file
0 CALGARY INT'L. A 25110 51.10 114.02 1953 2005 07:00:00 /home/ryan/Documents/academics/research/grange...
1 COLD LAKE A 25129 54.42 110.28 1954 2005 07:00:00 /home/ryan/Documents/academics/research/grange...
2 CORONATION 25113 52.10 111.45 1953 1994 07:00:00 /home/ryan/Documents/academics/research/grange...
3 COWLEY A CAN43 49.63 114.08 1953 1959 07:00:00 /home/ryan/Documents/academics/research/grange...
4 EDMONTON INT'L. A 25142 53.32 113.58 1961 2005 07:00:00 /home/ryan/Documents/academics/research/grange...

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]:
NAME geometry
0 CALGARY INT'L. A POINT (-1244045.288702108 1386275.684583135)
1 COLD LAKE A POINT (-911868.5052106386 1687317.050181715)
2 CORONATION POINT (-1044573.911117709 1450721.522283968)
3 COWLEY A POINT (-1291604.008476555 1229626.623984152)
4 EDMONTON INT'L. A POINT (-1150156.227511135 1617983.975859029)

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]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f27c321e1d0>

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]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f27c1f0ad30>

In [ ]: