1

I have used rasterio to open netcdf files and by defining a WarpedVRT extract a subarea that can be read with the vrt.read() command.

It works like a charm except when the longitude grid is 0:360 instead of -180:180.

How do you deal with this in rasterio? As soon as I try to extract data from -180 to 0 I get empty values.

I have tried to set the environment like this :

with rasterio.Env(CENTER_LONG=0):
    with rasterio.open(netcdfFilePath, mode='r') as src:
        with WarpedVRT(src, **vrt_options) as vrt:
               vrt.read()

trying to use the --config CENTER_LONG 0 gdal option.

or is it something you can account for in the vrt options?

 dst_transform = affine.Affine(xres, 0.0, left,
                                      0.0, -yres, top)

vrt_options = {
            'resampling': Resampling.bilinear,
            'crs': CRS.from_epsg(4326),
            'transform': dst_transform,
            'height': dst_height,
            'width': dst_width,
            'source_extra' : 1
        } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.