Choropleth map for Saudi Arabia

Hello. I have been trying lately to make a Choropleth map but I’ve reached a dead end by now and I need some help or suggestions. I’ve checked my GeoJSON file online and it’s working, and I’ve made IDs for the states of my country with the same ID of GeoJSON file and followed Plotly Guide, but still it has not worked yet…

I get this result, which is wrong:

This is my code on Colab (last 4 cells). Thanks and I really appreciate it.

@MahouTsukai0,
Welcome to Plotly forum!

It seems that your geojson file is corrupted. I tried with another geojson file derived from a shapefile
and with a dataframe with synthetic data I got the following map:

To restrict the map to SAU you can update the layout as follows:

fig.update_geos(center ={'lon': 45.0792, 'lat': 23.9959},
               lataxis_range= [15, 32], lonaxis_range=[33, 57])  

With the same dataframe (synthetic data), but your geojson file it was displayed a map like in your posted image.

The geojsonfile I derived from a shapefile, can be downloaded
here: https://github.com/empet/Datasets/blob/master/SAU-geo.zip

This file already has an id key.
file['features'][0]['properties'] is the dict:

{'GID_0': 'SAU',
 'NAME_0': 'Saudi Arabia',
 'GID_1': 'SAU.1_1',
 'NAME_1': '`Asir',
 'VARNAME_1': 'Asir|Aseer|Assyear',
 'NL_NAME_1': None,
 'TYPE_1': 'Emirate|Mintaqah',
 'ENGTYPE_1': 'Region',
 'CC_1': None,
 'HASC_1': 'SA.AS',
 'id': 0}

The region name is the value associated to the key ‘NAME_1’.

The list of all regions contains some longer names:

region=[]
for feat in file['features']:
    region.append(feat['properties']['NAME_1'])

and the regions are:

['Asir',
 'Al Bahah',
 'Al Hudud ash Shamaliyah',
 'Al Jawf',
 'Al Madinah',
 'Al Quassim',
 'Ar Riyad',
 'Ash Sharqiyah',
 "Ha'il",
 'Jizan',
 'Makkah',
 'Najran',
 'Tabuk']
​```

I hope it helps.
1 Like

Thanks @empet, this is an excellent explanation. I got it working now!

Hi @empet and @MahouTsukai0

It seems like I am running into the same problem and I am not finding a well-crafted GeoJSON file.

@empet would it be possible to share the blob again pls.

@sajjadk
During last year’s quarantine I answered hundreds of questions and did not keep all the data files I downloaded from the web or created myself. Maybe @MahouTsukai0 can help.

good morning
@empet
I really need your assistance in plotting the map of Saudi Arabia , the geojson file you provided a link to is no longer available
please help me
with best regards

Hey @Bahageel88 , did you try googling for geojson files of Saudi Arabia?

One of the first results: https://nbviewer.org/github/wjdanalharthi/GeoJSON-of-Saudi-Arabia-Regions/blob/master/example/SA_regions_vis.ipynb

1 Like

Thank you very much indeed @AIMPED
I will have a look at it