Date
1 - 6 of 6
Problem creating
Luca Delucchi
Hi everyone,
I'm trying to create a raster from a numpy array but I get this error "TypeError: Integer width and height are required." in rasterio/_io.pyx in rasterio._io.DatasetWriterBase.__init__() I'm printing width and height and I'm sure they are integers so I cannot understand why I get that error. Does anyone have an idea what I should check to solve this problem? I can share my code if needed. Thanks -- ciao Luca www.lucadelu.org |
|
Denis Rykov
Yes please share your code. |
|
Luca Delucchi
On Fri, 18 Feb 2022 at 23:49, Denis Rykov <rykovd@...> wrote:
The code is here https://pastebin.com/YSAqsuN2 I have my input array, I mask it with mask_raster_with_geometry function (it works properly) and after I need to create the tif. It print the dimensions (line 65) as (1, 7, 4, 1) These are the input data of create_temporary_dataset function - input array array([[[ nan, nan, nan, nan], [0.51981352, 0.56658679, 0.56957087, nan], [0.53405018, 0.5880829 , 0.52095808, nan], [0.56747695, 0.53271028, 0.41140838, nan], [ nan, 0.601892 , 0.53434226, nan], [ nan, 0.6013363 , 0.57550452, nan], [ nan, nan, 0.5495251 , nan]]]) - Affine(10.0, 0.0, 663270.0, 0.0, -10.0, 5112470.0) - epsg:32632 -- ciao Luca www.lucadelu.org |
|
Luke
Instead of `band_number = np.arange(count) + 1` on line 21, try `band_number = range(1, count + 1)`
I didn't test your code specifically, but rasterio won't read a dataset when passed the band indexes as a numpy array, but will if you pass the indexes as a list, tuple or range generator. E.g. src.read(range(1, 4)) array([[[...]]], dtype=float32)
src.read(np.arange(1, 4))
Traceback (most recent call last):
...
File "rasterio/_io.pyx", line 239, in rasterio._io.DatasetReaderBase.read ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() |
|
Denis Rykov
File you write to must be open in writing mode: >>> rasterio.open('example.tif', 'w', **profile) |
|
Luca Delucchi
On Sat, 19 Feb 2022 at 11:01, Denis Rykov <rykovd@...> wrote:
this was the problem, thanks a lot. The error message brings me to check in the wrong place. -- ciao Luca www.lucadelu.org |
|