#!/usr/bin/env python # coding: utf-8 # In[1]: import geopandas as gpd import pandas as pd import matplotlib.pyplot as plt # In[4]: # set path to shapefiles path = ('C:/Users/jtrum/world_bank/luanda_angola/') # In[20]: # read shapefiles angola0 = gpd.read_file(path + 'gadm41_AGO_0.shp') angola1 = gpd.read_file(path + 'gadm41_AGO_1.shp') angola2 = gpd.read_file(path + 'gadm41_AGO_2.shp') angola3 = gpd.read_file(path + 'gadm41_AGO_3.shp') # In[21]: # plot shapefiles as a 2 by 2 grid fig, ax = plt.subplots(2, 2, figsize=(10, 10)) angola0.plot(ax=ax[0, 0], color='white', edgecolor='black') angola1.plot(ax=ax[0, 1], color='orange', edgecolor='black') angola2.plot(ax=ax[1, 0], color='green', edgecolor='black') angola3.plot(ax=ax[1, 1], color='teal', edgecolor='black') plt.show() # In[22]: angola0 # In[23]: angola1 # In[24]: angola2 # In[25]: angola3 # In[26]: # extract Luanda, Angola from luanda1 luanda1 = angola1[angola1['NAME_1'] == 'Luanda'] luanda1 # In[29]: # extract Luanda, Angola from luanda2 luanda2 = angola2[angola2['NAME_1'] == 'Luanda'] luanda2 # In[31]: # extract Luanda, Angola from luanda3 luanda3 = angola3[angola3['NAME_1'] == 'Luanda'] luanda3 # In[32]: # plot luanda2 luanda2.plot(color='orange', edgecolor='black') plt.show() # In[33]: # merge luanda2 to be one polygon luanda2clean = luanda2.dissolve(by='NAME_1') # plot luanda2clean luanda2clean.plot(color='orange', edgecolor='black') plt.show() # In[34]: # export data folder path export = (path + 'exports/') # In[35]: # export as geojson luanda2clean.to_file(export + 'luanda2clean.geojson', driver='GeoJSON') # In[ ]: