plot GADM shapefile in Python
Question:
I want to plot GADM shape file from https://gadm.org/data.html. The file is sth like "gadm36_CHN_1_sp.rds". Can I plot this in Python and also add my data on this map please? Or is there other way to plot provincial boundaries for countries like China and others? Thanks.
Update to this question: now I understand that ".rds" files are designed for use in R programming. I am now using Geopandas
Python package to process shapefiles with traditional format (.shp).
Answers:
I found the GeoPandas library to be most useful for getting started with this:-
It will load in shapefiles easily and allow you to plot them.
Read up and see if it will do what you want. You could also add your own data to the GeoPandas dataframe so it can be plotted.
For something a bit more powerful and permanent, I’ve got on well using a PostGIS extension on a PostGreSQL database. It’s not too hard to load a shapefile into that, use python to script it and then visualise it in a page or notebook like Jupyter.
Happy to describe in more detail if this sounds useful.
Phil
For anyone falling here, I used a GeoPandas script to create a GeoDataFrame from GADM data for a long time and instead of copy/pasting it everywhere I turned it into a public lib: pygadm
For your use case I would do:
import pygadm
# both lines works
gdf = pygadm.get_items(name="Anhui")
gdf = pygadm.get_items(admin="CHN.1_1")
gdf.plot()
I want to plot GADM shape file from https://gadm.org/data.html. The file is sth like "gadm36_CHN_1_sp.rds". Can I plot this in Python and also add my data on this map please? Or is there other way to plot provincial boundaries for countries like China and others? Thanks.
Update to this question: now I understand that ".rds" files are designed for use in R programming. I am now using Geopandas
Python package to process shapefiles with traditional format (.shp).
I found the GeoPandas library to be most useful for getting started with this:-
It will load in shapefiles easily and allow you to plot them.
Read up and see if it will do what you want. You could also add your own data to the GeoPandas dataframe so it can be plotted.
For something a bit more powerful and permanent, I’ve got on well using a PostGIS extension on a PostGreSQL database. It’s not too hard to load a shapefile into that, use python to script it and then visualise it in a page or notebook like Jupyter.
Happy to describe in more detail if this sounds useful.
Phil
For anyone falling here, I used a GeoPandas script to create a GeoDataFrame from GADM data for a long time and instead of copy/pasting it everywhere I turned it into a public lib: pygadm
For your use case I would do:
import pygadm
# both lines works
gdf = pygadm.get_items(name="Anhui")
gdf = pygadm.get_items(admin="CHN.1_1")
gdf.plot()