1

I was wondering if someone could help me with an error message I am getting. First allow me to brief my workflow

  1. imported raster image via rasterio.open
  2. converted raster to array via raster.read(band number)
  3. did some calculations on the array
  4. trying to convert the final results into geotiff

But when I am trying to execute my codes I am getting the followin error message:

**AttributeError: 'DatasetReader' object has no attribute 'open'

here are my codes

# Get necessary information
driver = "GTiff"
nlines = raster.height
ncols = raster.width
nbands = raster.count
data_type = "float32"
crs = raster.crs
transform = raster.transform
count = raster.count
file_name = "C:/file_path/file_name.tif"
 


#Writing the GeoTiff
with raster.open("C:/file_path/file_name.tif", "w",
                             driver = driver,
                             height = height,
                             width = width,
                             count = count,
                             dtype = dtype,
                             crs = crs,
                             transform = transform) as dst:
    dst.write(raster_array)

Trying to write numpy array as GeoTiff

Even checked is my data is a numpy array, and the answer was TRUE

1 Answer 1

0

Your issue looks like a typo. Writing the GeoTiff you should refer to rasterio rather then raster, which seems to be you source data indeed.

#Writing the GeoTiff
with rasterio.open("C:/file_path/file_name.tif", "w",
                         driver = driver,
                         height = height,
                         width = width,
                         count = count,
                         dtype = dtype,
                         crs = crs,
                         transform = transform) as dst:
dst.write(raster_array)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.