Skip to content

Instantly share code, notes, and snippets.

@mango314
Last active April 18, 2022 00:39
Show Gist options
  • Save mango314/8228277 to your computer and use it in GitHub Desktop.
Save mango314/8228277 to your computer and use it in GitHub Desktop.
convex hulls + municipalities of Puerto Rico

Convex Municipalities of Puerto Rico

Today we will learn about convex hulls using GeoPandas.

The result is less dramatic when we apply to the map of PR. El resultado.


import simplejson as json
import numpy as np
import matplotlib.pyplot as plt
import geopandas, shapely
tiles = json.loads(file("atlaspr/geotiles/pueblos.json").read())
prTiles = [ {"shape": np.array(x['geometry']['coordinates']), "name": x['properties']['NAME'] } for x in tiles['pueblos']['features']]
prTileShapes = [shapely.geometry.shape({"type": "Polygon", "coordinates": tile['shape']}) for tile in prTiles]
g = geopandas.GeoSeries(prTileShapes)
g.convex_hull.plot()
plt.axis("Off")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment