pip install geopandas
sudo apt-get install libproj-dev proj-data proj-bin
sudo apt-get install libgeos-dev
pip install cython cartopy
pip install Cartopy Cython
pip install geoplot
import geopandas as gpd
import geoplot as gpt
ePATH = './Electoral_Divisions_-_OSi_National_Statutory_Boundaries.geojson'
df_places = gpd.read_file(ePATH)
df_places.plot() # plot the whole map defined by geojson
df_places['geometry'][0] # only plot one polygon
df_places['Count_Placeholder'] = np.random.randint(10,size=df_places.shape[0])
gpt.choropleth(df_places,hue=df_places['Count_Placeholder'],cmap='Greens') # plot each polygon with a color under colormap
To only read coordinates from geojson,
import json
with open('a.geojson') as f:
data = json.load(f)
coors = data['features'][0]['geometry']['coordinates']
This method works with provided vertices' coordinates, in a format of lists [[[x1,y1],[x1,y2],[x2,y2],[x2,y1],...]]
,
import geojson
import matplotlib.pyplot as plt
from descartes import PolygonPatch
BLUE = '#6699cc'
fig = plt.figure()
ax = fig.gca()
ax.add_patch(PolygonPatch(geojson.Polygon(coors)
,fc=BLUE, ec=BLUE,alpha=0.5,zorder=2 ))
ax.add_patch(PolygonPatch(\
geojson.Polygon([[[xmin,ymin],[xmin,ymax],
[xmax,ymax],[xmax,ymin]]])
,fc=BLUE, ec=BLUE,alpha=0.5,zorder=2 ))
ax.axis('scaled')
plt.show()