# Reading Satellite Data

**URL:** <https://discourse.julialang.org/t/reading-satellite-data/20231>\
**Category:** Geo\
**Tags:** io\
**Created:** [January 29, 2019, 12:19pm UTC](https://discourse.julialang.org/t/reading-satellite-data/20231 "2019-01-29T12:19:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [January 29, 2019, 12:19pm UTC](https://discourse.julialang.org/t/reading-satellite-data/20231/1 "2019-01-29T12:19:09Z")

</div>

Anybody please tell me how to read Geotiff format files?  
These are satellite data.  
I bet there is already a Julia package for this!

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [January 29, 2019, 12:21pm UTC](https://discourse.julialang.org/t/reading-satellite-data/20231/2 "2019-01-29T12:21:11Z")

</div>

ArchGDAL should do what you want:  
[http://yeesian.com/ArchGDAL.jl/latest/rasters.html](http://yeesian.com/ArchGDAL.jl/latest/rasters.html)

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 29, 2019, 12:31pm UTC](https://discourse.julialang.org/t/reading-satellite-data/20231/3 "2019-01-29T12:31:12Z")

</div>

Using this PR might make it easier: [Provide Interactive Datasets for REPL usage by yeesian · Pull Request #76 · yeesian/ArchGDAL.jl · GitHub](https://github.com/yeesian/ArchGDAL.jl/pull/76)

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [January 29, 2019, 1:26pm UTC](https://discourse.julialang.org/t/reading-satellite-data/20231/4 "2019-01-29T13:26:08Z")

</div>

Also, it takes a bit of time to put it all together (which I think above PR resolves). Something like this should work:

```julia
    AG = ArchGDAL
    out = AG.registerdrivers() do
        AG.read(filepath) do dataset
            band = AG.getband(dataset, bandnr)
            w, h = AG.width(band), AG.height(band)
            # scale, off = AG.getscale(band), AG.getoffset(band)
            na = AG.getnodatavalue(band)
            mat = convert(Matrix{T}, AG.read(band))
            gt = AG.getgeotransform(dataset)
            dx, dy = gt[2], -gt[end]
            x0 = gt[1] + dx/2
            x1 = x0 + (w-1) * dx
            y1 = gt[4] - dy/2
            y0 = y1 - (h-1)*dy

            proj4 = strip(AG.toPROJ4(AG.importWKT(AG.getproj(dataset))))
            (x0:dx:x1, y0:dy:y1, mat, proj4) # x-range, y-range, values, projection
        end
    end

```

see [How to extract longitude and latitude from a geoTIFF? · Issue #68 · yeesian/ArchGDAL.jl · GitHub](https://github.com/yeesian/ArchGDAL.jl/issues/68)

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [January 29, 2019, 6:51pm UTC](https://discourse.julialang.org/t/reading-satellite-data/20231/5 "2019-01-29T18:51:40Z")

</div>

Note that geotiff files can hold both images (multi-band images) or grids. In the second case each node stores a 4 bytes float, which is often used to store DEM (Digital Elevation Model) values.

[GMT.jl](https://github.com/GenericMappingTools/GMT.jl) reads geotiff files _nativelly_ (well, actually via GDAL too). If your case is a simple RGB image, something like this will get you the data (and metadata) in Julia

```julia
I = gmtread("the_file_name.tif", img=true);

```

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [January 30, 2019, 3:30pm UTC](https://discourse.julialang.org/t/reading-satellite-data/20231/6 "2019-01-30T15:30:12Z")

</div>

> [@joa-quim](#):
>
> I = gmtread(“the\_file\_name.tif”, img=true);

I am afraid that the gmtread fails quite spectacularly. Julia version 1.1.0 running on Windows 64  
Can someone advise where I should file a bug?

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.

> Blockquote  
> Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.

Exception: EXCEPTION\_ACCESS\_VIOLATION at 0xb36e4c0 – getindex at .\array.jl:730 [inlined] macro expansion at .\multidimensional.jl:671 [inlined] macro expansion at .\cartesian.jl:64 [inlined] macro expansion at .\multidimensional.jl:666 [inlined] \_unsafe\_getindex! at .\multidimensional.jl:662 [inlined] \_unsafe\_getindex at .\multidimensional.jl:656 in expression starting at C:\Users\hearn\Documents\Satellite\Crawley\gmtread.jl:3 macro expansion at .\multidimensional.jl:669 [inlined] macro expansion at .\cartesian.jl:64 [inlined] macro expansion at .\multidimensional.jl:666 [inlined] \_unsafe\_getindex! at .\multidimensional.jl:662 [inlined] \_unsafe\_getindex at .\multidimensional.jl:656 \_getindex at .\multidimensional.jl:642 [inlined] getindex at .\abstractarray.jl:927 unknown function (ip: 000000000B36E1CA) jl\_fptr\_trampoline at /home/Administrator/buildbot/worker/package\_win64/build/src\gf.c:1864 jl\_apply\_generic at /home/Administrator/buildbot/worker/package\_win64/build/src\gf.c:2219 get\_image at C:\Users\hearn.julia\packages\GMT\v32Hn\src\gmt\_main.jl:519 GMTJL\_Get\_Object at C:\Users\hearn.julia\packages\GMT\v32Hn\src\gmt\_main.jl:850 gmt at C:\Users\hearn.julia\packages\GMT\v32Hn\src\gmt\_main.jl:264

> Blockquote

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [February 1, 2019, 11:17am UTC](https://discourse.julialang.org/t/reading-satellite-data/20231/7 "2019-02-01T11:17:12Z")

</div>

Reading data with GMT.jl is now working!!  
Note- you must install Ghostscript [https://www.ghostscript.com/download/gsdnld.html](https://www.ghostscript.com/download/gsdnld.html)  
and the GMT software [http://w3.ualg.pt/~jluis/mirone/downloads/gmt.html](http://w3.ualg.pt/~jluis/mirone/downloads/gmt.html)  
before adding the GMT package.  
In the GMT installer at the Choose Components stage check the DCW component also.

Huge thanks to @joa-quim for all the help.
