Last active
February 13, 2018 06:41
-
-
Save jackparmer/ab8511fc502e3dc73f3322f0ec24b59a to your computer and use it in GitHub Desktop.
polygon.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Functions converting coastline/country polygons to lon/lat traces | |
def polygons_to_traces(poly_paths, N_poly): | |
''' | |
pos arg 1. (poly_paths): paths to polygons | |
pos arg 2. (N_poly): number of polygon to convert | |
''' | |
# init. plotting list | |
data = dict( | |
x=[], | |
y=[], | |
mode='lines', | |
line=Line(color="black"), | |
name=' ' | |
) | |
for i_poly in range(N_poly): | |
poly_path = poly_paths[i_poly] | |
# get the Basemap coordinates of each segment | |
coords_cc = np.array( | |
[(vertex[0],vertex[1]) | |
for (vertex,code) in poly_path.iter_segments(simplify=False)] | |
) | |
# convert coordinates to lon/lat by 'inverting' the Basemap projection | |
lon_cc, lat_cc = m(coords_cc[:,0],coords_cc[:,1], inverse=True) | |
# add plot.ly plotting options | |
data['x'] = data['x'] + lon_cc.to_list() + [np.nan] | |
data['y'] = data['y'] + lat_cc.to_list() + [np.nan] | |
# traces.append(make_scatter(lon_cc,lat_cc)) | |
return [data] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment