Giter Club home page Giter Club logo

Comments (8)

snowman2 avatar snowman2 commented on May 28, 2024

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.

snowman2 avatar snowman2 commented on May 28, 2024

Also, I would recommend upgrading to version 0.0.19.

from rioxarray.

snowman2 avatar snowman2 commented on May 28, 2024

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.

rbavery avatar rbavery commented on May 28, 2024

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.

rbavery avatar rbavery commented on May 28, 2024

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.

snowman2 avatar snowman2 commented on May 28, 2024

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.

snowman2 avatar snowman2 commented on May 28, 2024
terrain = rioxarray.open_rasterio(
    "NEON-DS-Airborne-Remote-Sensing/HARV/DTM/HARV_dtmCrop.tif",
    masked=True,
)

image

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:
image

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.
image

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)

image

from rioxarray.

rbavery avatar rbavery commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.