Re: Problem with passing CRS to warpedVRT


Sean Gillies
 

Hi,

If I read your code correctly, you are misusing the WarpedVRT constructor. You are passing a dict as the second positional argument to WarpedVRT(). This ends up being bound to the name src_crs in https://github.com/rasterio/rasterio/blob/master/rasterio/_warp.pyx#L820 and then can't be understood by PROJ as a CRS. That is invalid usage. Instead, try

with WarpedVRT(mr, **output_params) as vrt:

This unpacks the dict into the separate keyword arguments that the constructor expects.

On Sun, Jan 2, 2022 at 2:25 PM <stefan.jozefowicz@...> wrote:
I am getting the folllowing error when I am trying pass a crs object to WarpedVRT

```
rasterio.errors.CRSError: The PROJ4 dict could not be understood. OGR Error code 5
```
my code:

```
import rasterio
from rasterio.enums import Resampling
from rasterio.vrt import WarpedVRT
from rasterio import shutil as rio_shutil
from rasterio.crs import CRS


def match_raster(master_raster, matched_raster, output_matched_raster, resampling_method=Resampling.bilinear):
"""
https://rasterio.readthedocs.io/en/latest/topics/virtual-warping.html
"""


# get info of master raster
with rasterio.open(master_raster) as src:
# bounds = src.bounds
crs = src.crs
shape = src.shape
transform = src.transform
# resample (and reproject)

output_params = {
'resampling': Resampling.cubic,
'crs': crs,
'transform': transform,
'height': shape[0],
'width': shape[1],
}

# write to file
with rasterio.open(matched_raster) as mr:
with WarpedVRT(mr,output_params) as vrt:
data = vrt.read()
rio_shutil.copy(vrt,output_matched_raster,driver='GTiff')
```
My setup - Ubuntu 20, rasterio 1.2.10, GDAL 3.3.2. Any help will be greatly appreciated
_._,_._,

--
Sean Gillies

Join main@rasterio.groups.io to automatically receive all group messages.