0

I'm using data from the submarinecablemap.com Github repo to make an orthographic projection map in Plotly. I can plot the lines based on a Plotly documentation example for lines on maps, but I'm failing when trying to individually color or style the lines.

Ideally I'd like to use the color present in the GeoJson/GeoPandas file to add color, but I'm just not getting there. Here's what I've got:

# https://github.com/telegeography/www.submarinecablemap.com
resp = session.get('https://raw.githubusercontent.com/telegeography/www.submarinecablemap.com/master/public/api/v2/cable/cable-geo.json')

gdf_sub_cables = gpd.read_file(resp.text)
gdf_sub_cables['color_hex'] =  [f'#{x}' for x in gdf_sub_cables['color']]

lats = []
lons = []
names = []
colors = []

for feature, name, color in zip(gdf_sub_cables.geometry, gdf_sub_cables.slug, gdf_sub_cables.color_hex):
    if isinstance(feature, shapely.geometry.linestring.LineString):
        linestrings = [feature]
    elif isinstance(feature, shapely.geometry.multilinestring.MultiLineString):
        linestrings = feature.geoms
    else:
        continue
    for linestring in linestrings:
        x, y = linestring.xy
        lats = np.append(lats, y)
        lons = np.append(lons, x)
        names = np.append(names, [name]*len(y))
        colors = np.append(colors, [color]*len(y))

        lats = np.append(lats, None)
        lons = np.append(lons, None)
        names = np.append(names, None)
        colors = np.append(colors, None)

fig = px.line_geo(lat=lats, lon=lons, hover_name=names, 
                  projection="orthographic")
fig.show()

The approach to even plotting the lines seems overly complicated as well - if there is a better way to plot the lines, that would be even better.

Thank you for your help!

0 Answers0