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

Clipping with 2D Lat/Lon Coordinates #135

Closed
colinharkins opened this issue Jun 20, 2020 · 2 comments
Closed

Clipping with 2D Lat/Lon Coordinates #135

colinharkins opened this issue Jun 20, 2020 · 2 comments
Labels
question Further information is requested

Comments

@colinharkins
Copy link

Hi, I've been trying to figure out if it is possible to generate a mask for a region using rioxarrays clip functionality. The issue is that I have 2D lat/long coordinates and I get an error " DimensionMissingCoordinateError: x missing coordinates." because my x and y dimensions don't have coordinates.

This is the file that I'm trying to make a mask with, which is currently just an array of 1's on the grid that I'm interested in.

Dimensions: (x: 953, y: 834)
Coordinates:
lat (y, x) float32 -10.590603 -10.5368185 ... 46.668922 46.591976
lon (y, x) float32 -139.08585 -139.02963 ... 22.654575 22.661009
spatial_ref int64 0
Dimensions without coordinates: x, y
Data variables:
CONUS_mask (y, x) float64 1.0 1.0 1.0 1.0 1.0 1.0 ... 1.0 1.0 1.0 1.0 1.0

Below is the code I am using.

mask.rio.write_crs("+proj=latlong +R=6371229", inplace=True)
CONUS_shp = geopandas.read_file('/path/to/file.shp', crs="+proj=latlong +R=6371229")
clipped = mask.rio.clip(CONUS_shp.geometry.apply(mapping), crs="+proj=latlong +R=6371229")

I also saw #114, where it was recommended to filter with xr.where for a similar 2D coordinate case, but that solution won't work with a shape file.

Thanks for your help!

@colinharkins colinharkins added the question Further information is requested label Jun 20, 2020
@snowman2
Copy link
Member

For a shapefile, I recommend https://github.com/geopandas/geopandas to read it in. Then use total_bounds with the solution in #114.

@snowman2
Copy link
Member

snowman2 commented Jan 6, 2021

Closing for preference to: #202

@snowman2 snowman2 closed this as completed Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants