Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output raster data #13

Open
ShenliangXue92 opened this issue Apr 3, 2023 · 1 comment
Open

Output raster data #13

ShenliangXue92 opened this issue Apr 3, 2023 · 1 comment

Comments

@ShenliangXue92
Copy link

Thank you so much for your package in the calculations of LST and NDVI! These really help me a lot in my coursework.

However, as a student and newbie in Python and handling raster data, do you have any recommendations on how to output the raster data of LST and NDVI? I have searched it online, and there is no effective method I can apply in my research. Do you have any recommended codes or solutions that can be connected to this package? Thank you so much!

One of those solutions in the output raster data is like this one:
ndviImage = rasterio.open('ndviImage.tiff','w',driver='Gtiff',
width = redband.width,
height = redband.height,
count=1, crs=redband.crs,
transform=redband.transform,
dtype='float64')

ndviImage.write(ndvi,1)
ndviImage.close()

However, it doesn't work and reports errors in VS Code.

@dimejimudele
Copy link
Collaborator

dimejimudele commented Apr 19, 2023

Hello @ShenliangXue92, what error(s) are you getting specifically? Would be useful to know so I can be specifically helpful.

Here is how to do what you are trying to do, from the rasterio documentation: https:https://rasterio.readthedocs.io/en/stable/topics/writing.html

with rasterio.Env():

    # Write an array as a raster band to a new 8-bit file. For
    # the new file's profile, we start with the profile of the source
    profile = src.profile

    # And then change the band count to 1, set the
    # dtype to uint8, and specify LZW compression.
    profile.update(
        dtype=rasterio.uint8,
        count=1,
        compress='lzw')

    with rasterio.open('example.tif', 'w', **profile) as dst:
        dst.write(array.astype(rasterio.uint8), 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants