# Empty cloropeth map with geojson file

**URL:** <https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279>\
**Category:** 📊 Plotly Python\
**Created:** [December 14, 2021, 2:30pm UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279 "2021-12-14T14:30:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![thijmen](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@thijmen](https://community.plotly.com/u/thijmen)\
**Post date:** [December 14, 2021, 2:30pm UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279/1 "2021-12-14T14:30:11Z")

</div>

I am trying to create a cloropleth map of provinces in the Netherlands, using a JSON file I download through an API ([https://geodata.nationaalgeoregister.nl/](https://geodata.nationaalgeoregister.nl/)).

The following code just gives me an empty map. I’ve been going through the documentation and some threads on here, but I cant seem to work it out. Does anyone know what the problem is?

After I get the map to draw I also want to fill it data from a dataframe, but first things first.

```auto
import urllib.request
import json
import plotly.express as px

geo_url = 'https://geodata.nationaalgeoregister.nl/cbsgebiedsindelingen/wfs?request=GetFeature&service=WFS&version=2.0.0&typeName=cbs_provincie_2017_gegeneraliseerd&outputFormat=json'

def read_geojson(url):
    with urllib.request.urlopen(url) as url:
        jdata = json.loads(url.read().decode())
    return jdata

jdata = read_geojson(geo_url) # keys are: dict_keys(['type', 'id', 'geometry', 'geometry_name', 'properties'])

fig = px.choropleth(geojson=jdata)
fig.show()

```

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [December 14, 2021, 10:04pm UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279/2 "2021-12-14T22:04:34Z")

</div>

@thijmen

Mapbox cannot process your geojson data because its CRS (Coordinate Reference System) is different from that used at Mapbox.  
For a geojson file that can be read by Mapbox, it should look like this one:

```auto
jdata['crs']={'type': 'name', 'properties': {'name': 'urn:ogc:def:crs:OGC:1.3:CRS84'}}

```

while your file has:

```auto
jdata['crs']={"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::28992"}}

```

These CRS codes do not say too much at the first sight, but there is another way to realise why your file does not encode mapbox readable data: the geographical coordinates in its geometry description are very big numbers, not just lon, and lat that take values in the interval (-180, 180], respectively in [-90, 90].

Hence you should find an online tool to convert the geojson file to one readable by Mapbox.

---

<div class="post-metadata">

**Author:** ![thijmen](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@thijmen](https://community.plotly.com/u/thijmen)\
**Post date:** [December 15, 2021, 11:13am UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279/3 "2021-12-15T11:13:33Z")

</div>

Thanks so much @empet. I’ve converted the file to the appropriate CRS encoding and now the map is not empty anymore, but still not showing up correctly. Could there still be something wrong with the file or could there be some error in my code?

```auto
import json
import urllib.request
import plotly.express as px
import pandas as pd

# I converted above file (at https://mygeodata.cloud/converter/) and saved it on my github 
geo_url = 'https://raw.githubusercontent.com/Thijmen-data/geojson-data/main/web_provincie_geodata.geojson'

def read_geojson(url):
    with urllib.request.urlopen(url) as url:
        jdata = json.loads(url.read().decode())
    return jdata 

jdata = read_geojson(geo_url)

jdata['crs'] # {'type': 'name', 'properties': {'name': 'urn:ogc:def:crs:OGC:1.3:CRS84'}}: exactly as you said it should be
jdata['features'][0].keys() # dict_keys(['type', 'geometry_name', 'id', 'properties', 'geometry'])

# making a dataset where provincie will be the location key (corresponding to properties.statnaam) and counts the value used to fill
df = pd.DataFrame.from_dict({'provincie': ['Drenthe', 'Flevoland', 'Friesland', 'Gelderland', 'Groningen', 'Limburg', 'Noord-Brabant', 'Noord-Holland', 'Overijssel', 'Utrecht', 'Zeeland', 'Zuid-Holland'],
 'counts': [2, 20, 28, 154, 12, 71, 355, 125, 189, 58, 5, 123]})

fig = px.choropleth(df, geojson=jdata, color="counts",
                    locations="provincie", featureidkey="properties.statnaam",
                    projection="mercator"
                   )
fig.update_geos(fitbounds="locations", visible=False)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

```

As you can see it is not showing up correctly. Only one province shows up and the rest is purple. The funny thing is the plotly hover functionality is working for the other provinces too. I’ve been spending so much time on this. Really appreciate your help.

 ![badmap](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/9/3/93a3d6b92ab6b4db262dfb464d875482adef6710.png)

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [December 15, 2021, 11:43am UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279/4 "2021-12-15T11:43:15Z")

</div>

Could you provide a link to the new geojson file?

---

<div class="post-metadata">

**Author:** ![thijmen](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@thijmen](https://community.plotly.com/u/thijmen)\
**Post date:** [December 15, 2021, 12:05pm UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279/5 "2021-12-15T12:05:59Z")

</div>

Sorry, just uploaded it to my Github. I have edited my above post with code that downloads it from there.

Link is: [https://raw.githubusercontent.com/Thijmen-data/geojson-data/main/web\_provincie\_geodata.geojson](https://raw.githubusercontent.com/Thijmen-data/geojson-data/main/web_provincie_geodata.geojson)

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [December 15, 2021, 1:30pm UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279/6 "2021-12-15T13:30:40Z")

</div>

Your code is good, but geojson file is corrupted (the coordinates of its geometry have been saved in a wrong format during conversion). I found out this geojson [https://www.webuildinternet.com/articles/2015-07-19-geojson-data-of-the-netherlands/provinces.geojson](https://www.webuildinternet.com/articles/2015-07-19-geojson-data-of-the-netherlands/provinces.geojson) that works.

You have only to change the DataFrame definition to:

```auto
df = pd.DataFrame.from_dict({'provincie': ['Drenthe', 'Flevoland', 'Friesland (FryslÃ¢n)', 'Gelderland', 'Groningen', 'Limburg', 'Noord-Brabant', 'Noord-Holland', 'Overijssel', 'Utrecht', 'Zeeland', 'Zuid-Holland'],
 'counts': [2, 20, 28, 154, 12, 71, 355, 125, 189, 58, 5, 123]})

```

because Friesland has two names.  
One more change:

```auto
featureidkey="properties.name"

```

---

<div class="post-metadata">

**Author:** ![thijmen](https://avatars.discourse-cdn.com/v4/letter/t/e79b87/32.png) [@thijmen](https://community.plotly.com/u/thijmen)\
**Post date:** [December 15, 2021, 2:59pm UTC](https://community.plotly.com/t/empty-cloropeth-map-with-geojson-file/59279/7 "2021-12-15T14:59:56Z")

</div>

The link you’ve send works, but doesn’t show the internal borders correctly. I’ve converted the data with QGIS program and now i’ve got a working multipolyon GEOJSON file. Graph is looking sick.

Thanks for your help and showing me the problem was with the data file / conversion.
