We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Assume I want to split a country/ region into two regions - how can I achieve this? E.g. define an eastern and western US.
The text was updated successfully, but these errors were encountered:
I don't think I will ever include something like this but let's add this here for reference:
import geopandas as gp import pandas as pd import regionmask import shapely countries = regionmask.defined_regions.natural_earth.countries_110 # convert regions to a gp.GeoDataFrame data = dict( numbers=countries.numbers, abbrevs=countries.abbrevs, names=countries.names, geometry=countries.polygons, ) df = gp.GeoDataFrame.from_dict(data) # create two polygons encompassing the eastern and western half of the US lon = -98.24 p1 = shapely.geometry.Polygon([[-180, 0], [lon, 0], [lon, 90], [-180, 90]]) p2 = shapely.geometry.Polygon([[0, 0], [lon, 0], [lon, 90], [0, 90]]) df_polys = gp.GeoDataFrame(geometry=[p1, p2]) # select US sel = df.abbrevs == "US" # split in half US_split = gp.overlay(df.loc[sel], df_polys, how='intersection') # update the names & abbrevs US_split.abbrevs = US_split.abbrevs.str.cat(["w", "e"]) US_split.names = US_split.names.str.cat(["west", "east"], sep=" ") US_split.numbers = [177, 178] df_full = pd.concat([df.loc[~sel], US_split]) # create new regions countries_us2 = regionmask.Regions( df_full["geometry"], numbers=df_full.numbers, names=df_full.names, abbrevs=df_full.abbrevs )
and a plot:
countries_us2.plot()
Sorry, something went wrong.
No branches or pull requests
Assume I want to split a country/ region into two regions - how can I achieve this? E.g. define an eastern and western US.
The text was updated successfully, but these errors were encountered: