module datainc.data_geo_streets
#
Short summary#
module ensae_projects.datainc.data_geo_streets
Data related to a challenge, streets in Seattle
Functions#
function |
truncated documentation |
---|---|
Extends a set of edges to have less extermities into the graph composed by the sets of edges. |
|
Enumerates close streets from a starting point. |
|
Returns vertices and edges based on the subset of edges. |
|
Tells if streets st1, st2 are connected. |
|
Returns a folium map which represents the streets. |
|
Retrieves a dataframe which describes the meaning of the metadata. |
|
Retrieves processed data from Seattle Streets. … |
|
Plots the network based on cartopy. |
|
Returns the default projection for |
|
Returns a graph of streets. |
|
Returns a small graph of streets. |
|
Returns a small graph of streets. |
|
Returns a small graph of streets. |
|
Uses pyshp to return shapes and records from shapefiles. |
Documentation#
Data related to a challenge, streets in Seattle
- ensae_projects.datainc.data_geo_streets._complete_subset_streets(edges, shapes)#
Extends a set of edges to have less extermities into the graph composed by the sets of edges.
- Parameters:
edges – list of indices in shapes
shapes – streets
- Returns:
added edges (indices)
- ensae_projects.datainc.data_geo_streets._enumerate_close(lon, lat, shapes, th=None)#
Enumerates close streets from a starting point.
- Parameters:
lon – longitude
lat – latitude
shapes – list of streets
th – threshold or None for all
- Returns:
iterator on tuple(distance, i)
- ensae_projects.datainc.data_geo_streets.build_streets_vertices(edges, shapes)#
Returns vertices and edges based on the subset of edges.
- Parameters:
edges – indexes
shapes – streets
- Returns:
vertices, edges
vertices is a list of points. edges is a list of tuple(a, b) where a, b are indices refering to the array of vertices
- ensae_projects.datainc.data_geo_streets.connect_streets(st1, st2)#
Tells if streets st1, st2 are connected.
- Parameters:
st1 – street 1
st2 – street 2
- Returns:
tuple or tuple (0 or 1, 0 or 1)
Each tuple means:
0 or 1 mean first or last extremity or the first street
0 or 1 mean first or last extremity or the second street
((0, 1),)
means the first point of the first street is connected to the second extremity of the second street.
- ensae_projects.datainc.data_geo_streets.folium_html_street_map(subset, shapes, html_width=None, html_height=None, color_vertices=None, **kwargs)#
Returns a folium map which represents the streets.
- Parameters:
subset – list of streets index
shapes – list of shapes
kwargs – extra parameters for Map
html_width – sent to function folium_html_map
html_height –
sent to function folium_html_map
color_vertices – see below
- Returns:
see function folium_html_map
if color_vertices is equal to ‘odd’, the function computes the degree of each vertex and choose a different color for odd (yellow) and even degrees (black).
- ensae_projects.datainc.data_geo_streets.get_fields_description()#
Retrieves a dataframe which describes the meaning of the metadata.
- Returns:
dataframe
- ensae_projects.datainc.data_geo_streets.get_seattle_streets(filename=None, folder='.')#
Retrieves processed data from Seattle Streets.
- Parameters:
filename – local filename
folder – temporary folder where to download files
- Returns:
shapes, records
The function returns a filename.
- ensae_projects.datainc.data_geo_streets.plot_streets_network(edges_index, edges, vertices, shapes, order=None, color_vertices=None, color_edges=None, ax=None, **kwargs)#
Plots the network based on cartopy.
- Parameters:
edges_index – index of the edges in shapes
edges – list of tuple(v1, v2) in array of vertices
vertices – list of vertices coordinates
shapes – streets
order – list of edges composing a path (eulerian path)
color_vertices – dictionary
{ vertex_index: color }
, changes the color associated to each vertex (black by default)color_edges – dictionary
{ edges_index: color }
, changes the color associated to each edge (black by default)ax – axis or None
kwargs – parameter used to create the plot is ax is None
- Returns:
ax
kwargs may contain parameters: color_v, color_e, size_v, size_e, size_c, size_et.
If order is not None, the function replaces the edge index by its position in this array.
if color_vertices is equal to ‘odd’, the function computes the degree of each vertex and choose a different color for odd (yellow) and even degrees (black). If ax is predefined, it should contain the parameter:
import cartopy.crs as ccrs import matplotlib.pyplot as plt from ensae_projects.datainc.data_geo_streets import plot_streets_network_projection fig = plt.figure(figsize=(7,7)) ax = fig.add_subplot(1, 1, 1, projection=plot_streets_network_projection())
The default projection is given by
plot_streets_network_projection
. https://scitools.org.uk/cartopy/docs/v0.15/examples/hurricane_katrina.html
- ensae_projects.datainc.data_geo_streets.plot_streets_network_projection(central_longitude=0.0, min_latitude=-80.0, max_latitude=84.0, globe=None, latitude_true_scale=0.0)#
Returns the default projection for
plot_streets_network
. See projection.
- ensae_projects.datainc.data_geo_streets.seattle_streets_set_level(shapes, records, pos=(-122.3521425, 47.6219965), size=120)#
Returns a graph of streets.
- Parameters:
shapes – list of streets
records – description of each street
pos – center of the graphs
size – number of elements
- Returns:
indices of edges, edges, vertices, distances
The function uses the fields
SEGMENT_TY
to filter out train, rail ways.
- ensae_projects.datainc.data_geo_streets.seattle_streets_set_level2(shapes, records, size=120)#
Returns a small graph of streets.
- Parameters:
shapes – list of streets
records – description of each street
size – number of elements
- Returns:
indices of edges, edges, vertices, distances
- ensae_projects.datainc.data_geo_streets.seattle_streets_set_level3(shapes, records, size=1200)#
Returns a small graph of streets.
- Parameters:
shapes – list of streets
records – description of each street
size – number of elements
- Returns:
indices of edges, edges, vertices, distances
- ensae_projects.datainc.data_geo_streets.seattle_streets_set_small(shapes, records, size=20)#
Returns a small graph of streets.
- Parameters:
shapes – list of streets
records – description of each street
size – number of elements
- Returns:
indices of edges, edges, vertices, distances
- ensae_projects.datainc.data_geo_streets.shapely_records(filename, **kwargs)#
Uses pyshp to return shapes and records from shapefiles.
- Parameters:
filename – filename
kwargs – addition parameter for the shapefile reader, useful options car encoding and encodingErrors
- Returns:
shapes, records, fields
Fields in shapefiles
The following codes is usually used to retrieve shapefiles:
rshp = shapefile.Reader(filename) shapes = rshp.shapes() records = rshp.records()
records contains metadata about each shape. Fields and values are not stored in a dictionary. Here is a snippet of code to do so:
{k[0]: v for k, v in zip(rshp.fields[1:], records[0])}
Here is an example of the results:
{'ORD_PRE_DI': 'SW', 'ORD_STNAME': 'SW 149TH ST', 'ORD_STREET': '149TH', 'ORD_STRE_1': 'ST', 'ORD_SUF_DI': b' ', 'R_ADRS_FRO': 976, ...