I am trying to use Python to create a simple solution.
I have latitude and longitude of various areas, alongside their ID number and a code. The code is used to define regions. Say three locations (near to each other) have the same code, so they form region_1 and so on. I am trying to show this on map (basically show different regions) but don't understand how to approach the problem.
I tried using Folium Choropleth but it didn't work.
I think that is because I am not looking for how a value varies across regions. I am just interested in seeing how I can use different points to represent a region on a map.
Any help to what I can look into would be appreciated!
Edit: So turns out I have to make use of Voronoi regions. Now I tried creating those regions in Python.
Firstly I got the area shape using:
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
area = world[world.name == 'Pakistan']
area = area.to_crs(epsg=3395) # convert to World Mercator CRS
area_shape = area.iloc[0].geometry # get the Polygon
This gave the correct output. Next I had two lists, lat
and long
.
I combined the two lists into a 2D array and passed it to:
from geovoronoi import voronoi_regions_from_coords
region_polys, region_pts = voronoi_regions_from_coords(arr, area_shape)
This is the error I am getting now:
RuntimeError: ridge line must intersect with surrounding geometry from `geom`; this error often arises when there are points outside of the surrounding geometries; first check if all your points are inside the surrounding geometries
I googled a bit but don't know how fix the error. The points are fine I think since I did map it in Mapinfo first.
Would appreciate any help on this!