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

Import rasters to a julia array #45

Closed
rafaqz opened this issue Jun 9, 2018 · 6 comments
Closed

Import rasters to a julia array #45

rafaqz opened this issue Jun 9, 2018 · 6 comments

Comments

@rafaqz
Copy link
Collaborator

rafaqz commented Jun 9, 2018

Thanks for putting this package together.

I have a simple need of import tiff rasters with something better than imagemagic. It seems I can do that with this package but I'm not sure of the simplest way to just get a tiff into some kind of Julia Array. My GDAL experience is limited.

@yeesian
Copy link
Owner

yeesian commented Jun 9, 2018

Assuming you have a .tif file, e.g. by running

shell> wget https://github.com/yeesian/ArchGDALDatasets/blob/master/pyrasterio/RGB.byte.tif?raw=true

The following should work:

img = ArchGDAL.registerdrivers() do
    ArchGDAL.read("RGB.byte.tif") do dataset
        ArchGDAL.read(dataset)
    end
end

and yield

791×718×3 Array{UInt8,3}:
[:, :, 1] =
 0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00    0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00
 0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00     0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00
 0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00     0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00
 0x00
...

@rafaqz
Copy link
Collaborator Author

rafaqz commented Jun 9, 2018

Ok thanks somehow I missed that using read twice would return an array.

@rafaqz rafaqz closed this as completed Jun 9, 2018
@yeesian
Copy link
Owner

yeesian commented Jun 9, 2018

Yeah it's not particularly obvious, and It'll be nice to provide a better set of documentation for working with rasters (issue #40).

The first read is for file IO and gives you a handle to the dataset (that contains metadata) without reading in all the values. The second read is for reading in raster values. They are decoupled for out-of-core processing on enormous rasters (often but not exclusively from satellite data) where you'll process raster blocks a chunk at a time.

@rafaqz
Copy link
Collaborator Author

rafaqz commented Jun 10, 2018

Decoupling that makes sense. But it might be useful to have another package that further wraps ArchGDAL for these simple cases, so people doing basic IOcan totally avoid GDAL and just get a raster array with one command.

@yeesian
Copy link
Owner

yeesian commented Jun 10, 2018

But it might be useful to have another package that further wraps ArchGDAL for these simple cases

Yeah, ArchGDAL is not meant to be end-user facing. It's meant for other packages to build on top of, see e.g. GeoDataFrames.jl

so people doing basic IOcan totally avoid GDAL and just get a raster array with one command.

I agree with you. Does Images.jl not achieve this in the interim?

@rafaqz
Copy link
Collaborator Author

rafaqz commented Jun 10, 2018

Sure. I was thinking about writing something simple but I'm really not knowledgeable enough about raster data.

Unfortunately Imagemagic mangles some non-standard raster inputs on import, so its not really ok for production work.

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