Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assign_country.py hexagon duplication #17

Open
scotiow opened this issue Jul 11, 2024 · 0 comments
Open

assign_country.py hexagon duplication #17

scotiow opened this issue Jul 11, 2024 · 0 comments

Comments

@scotiow
Copy link
Contributor

scotiow commented Jul 11, 2024

The current method of assigning country names by doing a spatial join using the intersects operation in the following line
hexagons_with_country = gpd.sjoin(hexagons, countries, op='intersects') # changed from "within"
will lead to duplicated hexagons at borders where a hexagon intersects more than one country.

Perhaps the behaviour is intentional but if user is not aware may cause an issue when plotting data as a choropleth with fill alpha <1 as the duplicated hexagons that overlap increase apparent alpha or change the color.

Instead, I use the hexagon centroid to assign country names using within join operation which will give a 1-1 relationship in almost all cases (unless the centroid is exactly on a country border) along the lines of the code below:
hexagon_centroids = gpd.GeoDataFrame(geometry=hexagons.centroid, index=hexagons.index, crs=hexagons.crs)
hexagons["country"] = gpd.sjoin(hexagon_centroids, countries, predicate='within').country

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant