Plotting Geospatial Data with Python
This time we will learn about plotting geospatial data with Python
Importing data (shapefile) On this example we import geospatial data with shapefile format for area of Semarang City. Shp data that I already uploaded can be downloaded with this command
!gdown https://drive.google.com/u/2/uc?id=1XcPEdwSWysU5PWy2NnFca7QWqQkoMBPC&export=download
!unzip KOTA_SMG.zip
To import the data you can run this command
smg = gpd.read_file("KOTA_SMG/ADM_AREA.shp")
smg.head()
Next it will show the attribute table from that data
Plotting Shp Data
To plot shp data you can use this command
gplt.polyplot(smg) #your data
plt.title('Semarang City') #map title
plt.axis('on') #on/off axis
The plotting result will show map title as written in plt.title and show x and y axis with turning on plt.axis
Plotting Certain Area
The steps above you can plot the whole area from the data. But what if you only want to plot certain data, like only a district from a city?. In this example we will try to plot Gajahmungkur district only. We can make example Gajahmungkur district as gjh, so we can type:
gjh=smg[smg.WADMKC=="Gajah Mungkur"].plot() #WADMKC is column from the table that contains district names
gjh.plot
It will show only Gajah Mungkur district.
Happy plotting :)