plotly polyline map

Solutions on MaxInterview for plotly polyline map by the best coders in the world

showing results for - "plotly polyline map"
Samuel
12 May 2019
1import plotly.express as px
2import geopandas as gpd
3import shapely.geometry
4import numpy as np
5import wget
6
7# download a zipped shapefile
8wget.download("https://plotly.github.io/datasets/ne_50m_rivers_lake_centerlines.zip")
9
10# open a zipped shapefile with the zip:// pseudo-protocol
11geo_df = gpd.read_file("zip://ne_50m_rivers_lake_centerlines.zip")
12
13lats = []
14lons = []
15names = []
16
17for feature, name in zip(geo_df.geometry, geo_df.name):
18    if isinstance(feature, shapely.geometry.linestring.LineString):
19        linestrings = [feature]
20    elif isinstance(feature, shapely.geometry.multilinestring.MultiLineString):
21        linestrings = feature.geoms
22    else:
23        continue
24    for linestring in linestrings:
25        x, y = linestring.xy
26        lats = np.append(lats, y)
27        lons = np.append(lons, x)
28        names = np.append(names, [name]*len(y))
29        lats = np.append(lats, None)
30        lons = np.append(lons, None)
31        names = np.append(names, None)
32
33fig = px.line_mapbox(lat=lats, lon=lons, hover_name=names,
34                     mapbox_style="stamen-terrain", zoom=1)
35fig.show()
36
queries leading to this page
plotly polyline mapplotly polyline map