hello guys i have some shapefiles that i want to visualize on plotly so i converted it to geojson
but for some reason i doesnât show any thing and i donât know why
my shapefile data is from GADM i tried a lot of countries (U.K, china, France, Qatar)
and i tried a lot of ways to convert them to geojson but none of them showed anything
the code works it doesnât return any error but the countrys arenât showing up on the map
i use Jupiter notebook
here is what i did
first i downloaded the shapefile from GADM GADM
second i converted it by this website https://mapshaper.org/
and i also tried this website Online GIS/CAD Data Converter | SHP, KML, KMZ, TAB, CSV, ...
and finally i tried this this code
import geopandas as gpd
geodf = gpd.read_file(âpath_to_your_shapefile/your_shapefile.shpâ)
geodf = geodf.to_crs({âinitâ: âepsg:4326â})
geodf.to_file(âpath_to_my_geojson_file/my_geojson_fileâ, driver = âGeoJSONâ)
all o these methods successfully created geojson file for me but when i try to visualize it
doesnât work
this is my code
import pandas as pd
import numpy as np
import plotly.graph_objects as go
import plotly as py
import shapefile as shp
import geopandas as gpd
import json
#in this code i tried to read Qatar shapefile and i converted it using https://mapshaper.org/
with open("json_geo_data/mygeodata_merged.json") as geofile:
geojson_layer = json.load(geofile)
fig = go.Figure(go.Choroplethmapbox(geojson=geojson_layer, locations=df.Name, z=df.Value,
colorscale="Viridis", zmin=0, zmax=1000,
marker_opacity=1, marker_line_width=0))
fig.update_layout(mapbox_style="white-bg",
mapbox_zoom=3)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()
but it just shows white empty map
while this similarly code works just fine
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})
import plotly.graph_objects as go
fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=df.fips, z=df.unemp,
colorscale="Viridis", zmin=0, zmax=12,
marker_opacity=0.5, marker_line_width=0))
fig.update_layout(mapbox_style="white-bg",
mapbox_zoom=3, mapbox_center = {"lat": 37.0902, "lon": -95.7129})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()