Giter Site home page Giter Site logo

Support GeoTIFF? about pysheds HOT 9 CLOSED

mdbartos avatar mdbartos commented on July 16, 2024
Support GeoTIFF?

from pysheds.

Comments (9)

mdbartos avatar mdbartos commented on July 16, 2024

Rasterio supports geotiff, which means that they should be supported: https://rasterio.readthedocs.io/en/latest/

Did you try using grid.read_raster or grid.from_raster on your geotiff? It seems to work for me.

from pysheds.

mdbartos avatar mdbartos commented on July 16, 2024

@lz80521: Were you able to resolve this problem?

from pysheds.

ShashankBice avatar ShashankBice commented on July 16, 2024

Hi @mdbartos ! What if I do not have grid defined from beforehand and want to read the tiff file and define the grid file based on the properties of the tiff file?
Is there a way to define the grid geospatial properties manually?
Please let me know..
I tried grid = Grid(['affine=dataset.transform','shape=(219,564)','nodata=-1.79769313486231571e+308','crs=dataset.crs'])
but it fails!
Please let me know.....

from pysheds.

mdbartos avatar mdbartos commented on July 16, 2024

Greetings,

If you call:

grid = Grid.from_raster('/path/to/file.tiff', 'dataset_name')

It should populate the affine transform, shape, and other metadata of grid automatically.

Alternatively, read_raster will populate the metadata if it is the first dataset in the grid:

grid = Grid()
grid.read_raster('/path/to/file.tiff', 'dataset_name')

These are probably the most preferred ways of doing it.

If you need to set attributes manually, you can also do so after instantiating a grid:

grid.affine = dataset.transform
grid.shape = dataset.shape
grid.crs = dataset.crs
grid.nodata = -1.79769313486231571e+308

There are some other ways that may be easier or harder depending on your situation, but see if any of those help.

from pysheds.

ShashankBice avatar ShashankBice commented on July 16, 2024

Hi @mdbartos !
Thanks for the quick reply. After going through other issues with pysheds, I found the problem to be in version of rasterio. I use anaconda's rasterio and the latest release on anaconda does not play well with gdal. I did a pip install of rasterio and it works. And thankfully, it does not messes my other gdal related packages :)
Thanks for the help, I think I can now get my assignment done tomorrow morning!

from pysheds.

mdbartos avatar mdbartos commented on July 16, 2024

lol, no problem

from pysheds.

ShashankBice avatar ShashankBice commented on July 16, 2024

1 issue though, grid.view('dem') instead of plotting a raster gives this:-

Raster([[-1.79769313e+308, -1.79769313e+308, -1.79769313e+308, ...,
-1.79769313e+308, -1.79769313e+308, -1.79769313e+308],
[-1.79769313e+308, -1.79769313e+308, -1.79769313e+308, ...,
-1.79769313e+308, -1.79769313e+308, -1.79769313e+308],
[-1.79769313e+308, -1.79769313e+308, -1.79769313e+308, ...,
-1.79769313e+308, -1.79769313e+308, -1.79769313e+308],
...,
[-1.79769313e+308, -1.79769313e+308, -1.79769313e+308, ...,
-1.79769313e+308, -1.79769313e+308, -1.79769313e+308],
[-1.79769313e+308, -1.79769313e+308, -1.79769313e+308, ...,
-1.79769313e+308, -1.79769313e+308, -1.79769313e+308],
[-1.79769313e+308, -1.79769313e+308, -1.79769313e+308, ...,
-1.79769313e+308, -1.79769313e+308, -1.79769313e+308]])
Any workaround for this?

from pysheds.

mdbartos avatar mdbartos commented on July 16, 2024

To plot, it just call:

from matplotlib import pyplot as plt

plt.imshow(grid.view('dem'))

This was omitted in the readme for brevity, but can be seen in the quickstart:
https://github.com/mdbartos/pysheds/blob/master/examples/quickstart.ipynb

grid.view returns a Raster object (essentially an ndarray with metadata) that represents a "view" of the data at the grid's current affine transform, shape, crs, and nodata value.

from pysheds.

bmalbusca avatar bmalbusca commented on July 16, 2024

issue closed? @mdbartos

from pysheds.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.