visr / LasIO.jl

Julia package for reading and writing the LAS lidar format.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UndefVarError accessing LasIO.epsg_code (with 'import LasIO')

0joshuaolson1 opened this issue · comments

It's buried in src/srs.jl, but it's used in a test like LasIO.epsg_code (and the readme points to the tests for usage).

I ended up copying epsg_code and the constants it uses into my code.

The epsg_code function is not exported, thus it is only available as LasIO.epsg_code if you do using LasIO. This will work just as well. If you prefer not having to prepend LasIO., you can also add using LasIO.epsg_code, this will make it available directly:

julia> using FileIO, LasIO

julia> header, points = load("srs.las")
(LasHeader with 10 points.
, Array{LasIO.LasPoint1,1} with 10 points.
)

julia> LasIO.epsg_code(header)
Nullable{Int64}(32617)

julia> using LasIO.epsg_code

julia> epsg_code(header)
Nullable{Int64}(32617)

See also the summary of module usage in the julia docs, where the example p is also not exported.

Note to others who come across this issue:

Julia doesn't have import aliases at this time, and unfortunately it's in style to pollute one's script's namespace with using...

If you don't want anything in your namespace, you could use

import LasIO

And if you want an alias for LasIO, you could follow that by

const L = LasIO

I really need to read the Modules docs better. One can use using without pollution, I guess?

One can use using without pollution, I guess?

Nope, you can use import for that.

Nope, you can use import for that.

It seems I wasn't clear; the following doesn't work for me:

import FileIO, LasIO
header, points = FileIO.load("srs.las")
LasIO.epsg_code(header) // error

Huh strange. Can you reproduce that in a clean Julia v0.6 session?

julia> import FileIO, LasIO

julia> header, points = FileIO.load("srs.las")
(LasHeader with 10 points.
, Array{LasIO.LasPoint1,1} with 10 points.
)

julia> LasIO.epsg_code(header)
Nullable{Int64}(32617)
$ julia
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: https://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.6.2 (2017-12-13 18:08 UTC)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |  x86_64-pc-linux-gnu

julia> import FileIO, LasIO
      
julia> header, points = FileIO.load("2726-17-15.las") # the LAS file I have
(LasHeader with 449138 points.
, LasIO.LasPoint1[LasPoint(z=408460, classification=2)
, LasPoint(z=410290, classification=7)
, LasPoint(z=408510, classification=2)
, LasPoint(z=408500, classification=8)
, LasPoint(z=411340, classification=5)
, LasPoint(z=409540, classification=4)
, LasPoint(z=408420, classification=8)
, LasPoint(z=408480, classification=2)
, LasPoint(z=408480, classification=2)
, LasPoint(z=408570, classification=2)
  …  LasPoint(z=403920, classification=8)
, LasPoint(z=403640, classification=8)
, LasPoint(z=403880, classification=8)
, LasPoint(z=403660, classification=2)
, LasPoint(z=403780, classification=2)
, LasPoint(z=403640, classification=8)
, LasPoint(z=403850, classification=8)
, LasPoint(z=403560, classification=8)
, LasPoint(z=403760, classification=8)
, LasPoint(z=403970, classification=8)
])

julia> LasIO.epsg_code(header)
ERROR: UndefVarError: epsg_code not defined
Stacktrace:
 [1] macro expansion at ./REPL.jl:97 [inlined]
 [2] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

Oh sorry, this has nothing to do with import/using, this is just a function that is not released yet:
v0.0.1...master

To get it right now, you can do Pkg.checkout("LasIO") to get the master branch. We should probably tag another release soon.

facepalm

Sorry to waste your time.