Comments (8)
I would recommend using rioxarray.open_rasterio
. It has the masked
and mask_and_scale
kwargs that should address your issue.
See: https://corteva.github.io/rioxarray/stable/rioxarray.html#rioxarray-open-rasterio
You can see it in action in the clip example in the docs.
from rioxarray.
Also, I would recommend upgrading to version 0.0.19
.
from rioxarray.
Ah, re-reading the issue I see what you are saying. The drop=True
kwarg in xarray.where
should do the trick.
terrain_no_border= terrain_WGS84_to_UTM.where(terrain_WGS84_to_UTM!=terrain_WGS84_to_UTM.rio.nodata, drop=True)
Also, you will need to make sure that you copy the attributes from the old data array to the new one. See: https://corteva.github.io/rioxarray/stable/examples/convert_to_raster.html#Managing-Information-Loss-with-xarray-operations
from rioxarray.
Thanks for the tips. Using the drop
keyword gets close to the expected result but the shape is still off because some rows have both true values and no data values and are therefore not removed by the drop keyword. I'd expect the result to be the same shape as the original, (band: 1, y: 1367, x: 1697)
terrain_model_HARV_xarr_UTM18.where(terrain_model_HARV_xarr_UTM18!=terrain_model_HARV_xarr_UTM18.rio.nodata, drop=True)
<xarray.DataArray (band: 1, y: 1379, x: 1711)>
array([[[ nan, nan, nan, ..., nan,
nan, nan],
[ nan, 389.3999939 , 389.54998779, ..., nan,
345.13000488, nan],
[ nan, 389.3999939 , 389.44998169, ..., 344.97000122,
345.13000488, nan],
...,
[ nan, 344.42999268, 344.47000122, ..., 309.25 ,
309.29998779, nan],
[ nan, 344.41000366, 344.47000122, ..., nan,
309.3500061 , nan],
[ nan, nan, nan, ..., nan,
309.3500061 , nan]]])
Coordinates:
* x (x) float64 7.315e+05 7.315e+05 ... 7.331e+05 7.332e+05
* y (y) float64 4.714e+06 4.714e+06 ... 4.712e+06 4.712e+06
* band (band) int64 1
spatial_ref int64 0
Attributes:
transform: (0.9928066390441307, 0.0, 731407.5575529601, 0.0, -0...
scales: (1.0,)
offsets: (0.0,)
AREA_OR_POINT: Area
grid_mapping: spatial_ref
STATISTICS_MAXIMUM: 389.81997680664
STATISTICS_MEAN: 344.8979433625
STATISTICS_MINIMUM: 304.55999755859
STATISTICS_STDDEV: 15.861471000978
_FillValue: -9999.0
I ran this with version .19
from rioxarray.
I ran this process on QGIS and it looks like these artifacts might be unavoidable without adding extra arguments to the reproject function to control the output extent of the result, so I think it's probably best to just clip after the second reprojection.
from rioxarray.
If you need the grid to be the same as it was originally, I think what you are looking for is reproject_match
(https://corteva.github.io/rioxarray/stable/examples/reproject_match.html):
import rioxarray
terrain = rioxarray.open_rasterio("data/NEON-DS-Airborne-Remote-Sensing/HARV/DTM/HARV_dtmCrop.tif")
terrain_WGS84 = terrain.rio.reproject("EPSG:4326")
terrain_WGS84_to_UTM = terrain_WGS84.rio.reproject_match(terrain)
from rioxarray.
terrain = rioxarray.open_rasterio(
"NEON-DS-Airborne-Remote-Sensing/HARV/DTM/HARV_dtmCrop.tif",
masked=True,
)
terrain_WGS84 = terrain.rio.reproject("EPSG:4326")
Notice how reprojecting the grid the first time introduces white space on the endges when reprojecting to WGS84:
When using that same grid and allowing GDAL to auto-decide on the grid you want, you don't always get the effects you want as shown with the added nodata-border. I assume it is just propagating the grid expansion from the WGS84 grid due to the rotation.
But, if you want it to match the original grid, it will happily do that for you:
terrain_WGS84_to_UTM = terrain_WGS84.rio.reproject_match(terrain)
from rioxarray.
Thanks a bunch for the help @snowman2 I'll go with reproject_match
, I found that clip_box
doesn't actually result in arrays of the same shape probably due to how border pixels are handled (I assume I'm misusing that func and that reproject_match is the way to go).
from rioxarray.
Related Issues (20)
- rioxarray.open_rasterio(file) doesn't work HOT 1
- Support GCPs without known z coordinate HOT 3
- `spatial_ref` coordinate not accessible after saving dataset HOT 2
- Add a rio.fill.fillnodata-based nodata interpolation in addition to existing scipy-based HOT 1
- write somewhere in the documentation that extentions are not respecting F401
- Rename bands as variables using long_name attribute HOT 8
- typo in docs
- `rio.transform()` does not retrieve exact transform stored in `rio.write_transform()` HOT 2
- Document difference between `set_crs` and `write_crs` HOT 4
- Typo in docs: longitute
- Fail to reproject and reproject_match a dataset with rotation affine. HOT 3
- reproject_match renames dims HOT 2
- Xarray padding with mode='reflect'
- Padding and Croping doesn't end up same result HOT 2
- overview_level failing in xarray with engine='rasterio' due to missing doc? HOT 2
- Rio array merge missing HOT 3
- Delayed/chunked opening (sentinel) SAFE data with bands as variables fails HOT 1
- `reproject_match` raises `MissingSpatialDimensionError` with spatial dims set HOT 1
- Save larger raster with zstd compression writes dirty block HOT 3
- Memory leak when looping through data variables of a dataset loaded from a VRT HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rioxarray.