Plotly Choropleth 不显示 geojson 文件的边界

Plotly Choropleth not showing boundaries of geojson file

我正在尝试通过以下 geojson 文件显示英国境内的区域:https://data.nationalgrideso.com/system/gis-boundaries-for-gb-dno-license-areas

但是,除了比例尺和地图框框架之外,我似乎无法显示任何结果。下面是我的测试代码:

import os, json
import numpy as np
import pandas as pd
import plotly.express as px

#dataframe
d = {'Value': np.random.randint(1000,size=14),
    'geojson_id':[17,22,21,12,19,10,20,18,13,16,15,23,11,14]}
df= pd.DataFrame(data=d)

#geojson file
basedir = os.path.abspath(os.path.dirname(__file__))
filename= os.path.join(basedir, 'dno_license_areas_20200506.geojson')
with open(filename) as response:
    dno_zones = json.load(response)

#Choropleth PLOT
fig = px.choropleth_mapbox(df, geojson=dno_zones,color='Value',
                           locations='geojson_id', featureidkey="properties.ID",
                           center={"lat": 54.3, "lon": 0.0},
                           mapbox_style="carto-positron", zoom=4)

fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

我错过了什么?

  • 当你查看 geojson 时,你会发现它有这个 CRS
<Derived Projected CRS: EPSG:27700>
Name: OSGB36 / British National Grid
Axis Info [cartesian]:
- E[east]: Easting (metre)
- N[north]: Northing (metre)
Area of Use:
- name: United Kingdom (UK) - offshore to boundary of UKCS within 49°45'N to 61°N and 9°W to 2°E; onshore Great Britain (England, Wales and Scotland). Isle of Man onshore.
- bounds: (-9.0, 49.75, 2.01, 61.01)
Coordinate Operation:
- name: British National Grid
- method: Transverse Mercator
Datum: Ordnance Survey of Great Britain 1936
- Ellipsoid: Airy 1830
- Prime Meridian: Greenwich
  • 这意味着您需要将其投影mapbox使用
  • 的CRS
  • 我为此使用了 geopandas
import os, json, requests
import numpy as np
import pandas as pd
import plotly.express as px
import geopandas as gpd

# dataframe
d = {
    "Value": np.random.randint(1000, size=14),
    "geojson_id": [17, 22, 21, 12, 19, 10, 20, 18, 13, 16, 15, 23, 11, 14],
}
df = pd.DataFrame(data=d)

# #geojson file
# basedir = os.path.abspath(os.path.dirname(__file__))
# filename= os.path.join(basedir, 'dno_license_areas_20200506.geojson')
# with open(filename) as response:
#     dno_zones = json.load(response)
dno_zones = requests.get(
    "https://data.nationalgrideso.com/backend/dataset/0e377f16-95e9-4c15-a1fc-49e06a39cfa0/resource/e96db306-aaa8-45be-aecd-65b34d38923a/download/dno_license_areas_20200506.geojson"
).json()
dno_zones = (
    gpd.GeoDataFrame.from_features(
        dno_zones, crs=dno_zones["crs"]["properties"]["name"]
    )
    .to_crs("epsg:4326")
    .__geo_interface__
)

# Choropleth PLOT
fig = px.choropleth_mapbox(
    df,
    geojson=dno_zones,
    color="Value",
    locations="geojson_id",
    featureidkey="properties.ID",
    center={"lat": 54.3, "lon": 0.0},
    mapbox_style="carto-positron",
    zoom=4,
)

fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.show()