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

Getting metadata on single band geotiff? #89

Closed
rafaqz opened this issue Aug 26, 2019 · 5 comments
Closed

Getting metadata on single band geotiff? #89

rafaqz opened this issue Aug 26, 2019 · 5 comments

Comments

@rafaqz
Copy link
Collaborator

rafaqz commented Aug 26, 2019

Trying to get the band of single band datasets with ArchGDAL.getband(dataset, 1) is giving me a ReadOnlyMemoryError()` (is that expected?)

Without the band object there are no methods like getnodatavalue, how else can I get that information? (as separate values, not gdalinfo text)

@yeesian
Copy link
Owner

yeesian commented Aug 26, 2019

That's strange, since the REPL display is based on calling it with ArchGDAL.getband(dataset, i). Do you have an example to produce the ReadOnlyMemoryError()?

@rafaqz
Copy link
Collaborator Author

rafaqz commented Aug 26, 2019

Oops I was passing the band outside of the closure.

@rafaqz rafaqz closed this as completed Aug 26, 2019
@AmebaBrain
Copy link

AmebaBrain commented Oct 16, 2019

Same error for me. Sometimes I get ReadOnlyMemoryError(). In other case it is Segmentation fault

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.1.0 (2019-01-21)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> import GDAL

julia> import ArchGDAL; const AG = ArchGDAL
ArchGDAL

julia> filepath = "../data/geo/world.tif"
"../data/geo/world.tif"

julia> AG.registerdrivers() do
           AG.read(filepath) do dataset
               println(dataset)
               #println(typeof(dataset))
               #println(AG.filelist(dataset))
               #println(AG.nraster(dataset))
               #println(AG.width(dataset))
               #println(AG.height(dataset))
       
               ds = AG.getband(dataset, 1)
           end
       end
GDAL Dataset (Driver: GTiff/GeoTIFF)
File(s): 
  ../data/geo/world.tif

Dataset (width x height): 2048 x 1024 (pixels)
Number of raster bands: 3
  [GA_ReadOnly] Band 1 (Red): 2048 x 1024 (UInt8)
  [GA_ReadOnly] Band 2 (Green): 2048 x 1024 (UInt8)
  [GA_ReadOnly] Band 3 (Blue): 2048 x 1024 (UInt8)


signal (11): Segmentation fault
in expression starting at no file:0
unknown function (ip: 0xfffffffffffffff7)
show at /home/toleg/.julia/packages/ArchGDAL/RCmkd/src/base/display.jl:62
show at ./sysimg.jl:194
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
display at /home/toleg/.julia/packages/OhMyREPL/GFHgr/src/output_prompt_overwrite.jl:6
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
display at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:135
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
display at ./multimedia.jl:287
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1571 [inlined]
jl_f__apply at /buildworker/worker/package_linux64/build/src/builtins.c:556
jl_f__apply_latest at /buildworker/worker/package_linux64/build/src/builtins.c:594
#invokelatest#1 at ./essentials.jl:742 [inlined]
invokelatest at ./essentials.jl:741 [inlined]
print_response at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:155
print_response at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:140
jfptr_print_response_13372.clone_1 at /home/toleg/Install/julia-1.1.0/lib/julia/sys.so (unknown line)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
do_respond at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:714
unknown function (ip: 0x7fe9fa3a2ea4)
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1864
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1571 [inlined]
jl_f__apply at /buildworker/worker/package_linux64/build/src/builtins.c:556
jl_f__apply_latest at /buildworker/worker/package_linux64/build/src/builtins.c:594
#invokelatest#1 at ./essentials.jl:742 [inlined]
invokelatest at ./essentials.jl:741 [inlined]
run_interface at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/LineEdit.jl:2273
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
run_frontend at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:1035
run_repl at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/REPL/src/REPL.jl:192
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
#734 at ./client.jl:362
jfptr_#734_6031.clone_1 at /home/toleg/Install/julia-1.1.0/lib/julia/sys.so (unknown line)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1571 [inlined]
jl_f__apply at /buildworker/worker/package_linux64/build/src/builtins.c:556
jl_f__apply_latest at /buildworker/worker/package_linux64/build/src/builtins.c:594
#invokelatest#1 at ./essentials.jl:742 [inlined]
invokelatest at ./essentials.jl:741 [inlined]
run_main_repl at ./client.jl:346
exec_options at ./client.jl:284
_start at ./client.jl:436
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2219
unknown function (ip: 0x40191d)
unknown function (ip: 0x401523)
__libc_start_main at /lib64/libc.so.6 (unknown line)
unknown function (ip: 0x4015c4)
Allocations: 15081790 (Pool: 15078623; Big: 3167); GC: 33
Segmentation fault (Speicherabzug geschrieben)

@visr
Copy link
Collaborator

visr commented Oct 16, 2019

@AmebaBrain this happens because the band ds that you take out of the do block relies on the parent dataset existing. As soon as the AG.read(filepath) do dataset block finishes, it is cleaned up, making the band unusable. So you have to basically do what you want inside the do block. Of course if you load the band into a julia array that does not rely on a GDAL object existing you can use that afterward.

Note that in #76 interactive datasets are added that make it easier to do this in the repl without having to worry about issues like this.

@AmebaBrain
Copy link

@visr
Got it, thanks. Did as you suggested

AG.registerdrivers() do
    AG.read(filepath) do dataset
        # raster band is linked to dataset. we have to read raster data into array
        global data = AG.read(dataset, 1)
    end
end

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

4 participants