0

I'm using Python in my research and how I don't have large experience in this language, I need Help to understand this error that occur when I`ll write a array as raster file.

data_res_b1_corrected = [np.zeros((col1, row1), np.float32)]

data_res_b1_corrected = (data_res_b1 - (coef_red_nir * (subt_nir_nir_med)))
print(data_res_b1_corrected.shape)
output1 = res_b1.GetDriver().Create('D:/CESAR_PHD/10.Lyzenga/output/Reservoir_RED_corrected.tif', col1, row1, 1, gdal.GDT_Float32)
output1.SetGeoTransform(geoT)
output1.SetProjection(proj.ExportToWkt())
output1.GetRasterBand(1).WriteArray(data_res_b1_corrected)
output1.FlushCache()

The error occur when I`ll run this line: "output1.GetRasterBand(1).WriteArray(data_res_b1_corrected)"

The console returns: ValueError: expected array of dim 2

  • 1
    Sounds like your numpy Array have more dimension than 2. What is Printing with print(data_res_b1_corrected.shape)? – BERA Feb 20 '19 at 14:06
  • print(data_res_b1_corrected.shape) (1, 8619, 5975) – César de Paula Feb 20 '19 at 14:09
  • 1
    Try changing first line to data_res_b1_corrected = np.array(np.zeros((col1, row1), np.float32)) otherwise you are creating a list – BERA Feb 20 '19 at 14:14
  • Still the same error. – César de Paula Feb 20 '19 at 14:19
  • 1
    Ok...I'll check the shape from all calculation steps. Thank you for help me!! – César de Paula Feb 20 '19 at 14:48

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.