lidario

package module
v0.0.0-...-dcaaf6b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 12 Imported by: 9

README

lidario

Description

lidario is a simple library for reading and writing LiDAR files stored in LAS format. The library is written using the Go programing language. Use the build.py file to build/install the source code. The script can also be used to run the tests.

Example Usage

import "github.com/jblindsay/lidario"

func main() {
    // Reading a LAS file
    fileName := "testdata/sample.las"
    var lf *lidario.LasFile
    var err error
    lf, err = lidario.NewLasFile(fileName, "r")
    if err != nil {
        fmt.Println(err)
    }
    defer lf.Close()

    // Print the data contained in the LAS Header
    fmt.Printf("%v\n", lf.Header)

    // Print the VLR data
    fmt.Println("VLRs:")
    for _, vlr := range lf.VlrData {
        fmt.Println(vlr)
    }

    // Get the X,Y,Z data for a single point
    x, y, z, err := lf.GetXYZ(1000)
    fmt.Printf("Point %v: (%f, %f, %f) Error: %v\n", j, x, y, z, err)
	
    // Get an entire point, including all parts
    var p lidario.LasPointer
    p, err = lf.LasPoint(1000)
    if err != nil {
        fmt.Println(err)
        t.Fatal()
    }
    fmt.Println("Point format:", p.Format())

    // Read all the points
    oldProgress := -1
    progress := 0
    for i := 0; i < int(lf.Header.NumberPoints); i++ {
        if p, err := lf.LasPoint(i); err != nil {
            fmt.Println(err)
            t.Fatal()
        } else {
            if i < 10 {
                pd := p.PointData()
                fmt.Printf("Point %v: (%f, %f, %f, %v, %v, %f)\n", i, pd.X, pd.Y, pd.X, pd.Intensity, pd.ClassBitField.ClassificationString(), p.GpsTimeData())
            }
            progress = int(100.0 * float64(i) / float64(lf.Header.NumberPoints))
            if progress != oldProgress {
                oldProgress = progress
                if progress%10 == 0 {
                    fmt.Printf("Progress: %v\n", progress)
                }
            }
        }
    }

    // Create a new LAS file
    newFileName := "testdata/newFile.las"
    newLf, err := lidario.InitializeUsingFile(newFileName, lf)
    if err != nil {
        fmt.Println(err)
        t.Fail()
    }
    defer newLf.Close()

    progress = 0
    oldProgress = -1
    for i := 0; i < int(lf.Header.NumberPoints); i++ {
        if p, err := lf.LasPoint(i); err != nil {
            fmt.Println(err)
            t.Fatal()
        } else {
            if p.PointData().Z < 100.0 { // only output the point if the elevation is less than 100.0 m
                newLf.AddLasPoint(p)
            }
        }
        progress = int(100.0 * float64(i) / float64(lf.Header.NumberPoints))
        if progress != oldProgress {
            oldProgress = progress
            if progress%10 == 0 {
                fmt.Printf("Progress: %v\n", progress)
            }
        }
    }
}

Documentation

Index

Constants

View Source
const (
	DTByte      = 1
	DTASCII     = 2
	DTShort     = 3
	DTLong      = 4
	DTRational  = 5
	DTSbyte     = 6
	DTUndefined = 7
	DTSshort    = 8
	DTSlong     = 9
	DTSrational = 10
	DTFloat     = 11
	DTDouble    = 12
)

Data types (p. 14-16 of the spec).

View Source
const (
	PIWhiteIsZero = 0
	PIBlackIsZero = 1
	PIRGB         = 2
	PIPaletted    = 3
	PITransMask   = 4
	PICMYK        = 5
	PIYCbCr       = 6
	PICIELab      = 8
)

Photometric interpretation values (see p. 37 of the spec).

View Source
const (
	SFUnsignedInteger = 1
	SFSignedInteger   = 2
	SFFloatingPoint   = 3
	SFUknown          = 4
)

Sample formats (page 80 of the spec).

View Source
const (
	// SatelliteGpsTime represents Satellite GPS time
	SatelliteGpsTime = iota + 1
	// GpsWeekTime represents GPS week time
	GpsWeekTime
)
View Source
const (
	// WellKnownText coordinate system reference method
	WellKnownText = iota + 1
	// GeoTiff coordinate system reference method
	GeoTiff
)

Variables

View Source
var NoData = math.Inf(-1)

NoData value used when indexing point outside of allowable range.

Functions

This section is empty.

Types

type ClassificationBitField

type ClassificationBitField struct {
	Value byte
}

ClassificationBitField is a point record classification bit field

func (*ClassificationBitField) Classification

func (c *ClassificationBitField) Classification() byte

Classification of LAS point record

func (*ClassificationBitField) ClassificationString

func (c *ClassificationBitField) ClassificationString() string

ClassificationString returns a string represenation of the classiciation type.

func (*ClassificationBitField) Keypoint

func (c *ClassificationBitField) Keypoint() bool

Keypoint returns `true` if the point is a keypoint, `false` otherwise

func (*ClassificationBitField) SetClassification

func (c *ClassificationBitField) SetClassification(value uint8)

SetClassification sets the class value for a LAS point record

func (*ClassificationBitField) SetKeypoint

func (c *ClassificationBitField) SetKeypoint(val bool)

SetKeypoint sets the value of the keypoint field for this point

func (*ClassificationBitField) SetSynthetic

func (c *ClassificationBitField) SetSynthetic(val bool)

SetSynthetic sets the value of synthetic for the point

func (*ClassificationBitField) SetWithheld

func (c *ClassificationBitField) SetWithheld(val bool)

SetWithheld sets the value of the withheld field for this point

func (*ClassificationBitField) Synthetic

func (c *ClassificationBitField) Synthetic() bool

Synthetic returns `true` if the point is synthetic, `false` otherwise

type CoordinateReferenceSystemMethod

type CoordinateReferenceSystemMethod uint

CoordinateReferenceSystemMethod is the type of coordiante reference system used in the file, either Well-Known Text (WKT) or GeoTiff.

func (CoordinateReferenceSystemMethod) String

type FRSResultList

type FRSResultList struct {
	// contains filtered or unexported fields
}

FRSResultList list return from a fixed-radius search

func (*FRSResultList) First

func (l *FRSResultList) First() *FRSResultNode

First returns the head of the list

func (*FRSResultList) Len

func (l *FRSResultList) Len() int

Len return the list's length

func (*FRSResultList) Pop

func (l *FRSResultList) Pop() (value FixedRadiusSearchResult, err error)

Pop last item from list

func (*FRSResultList) Push

Push Create new node with value

type FRSResultNode

type FRSResultNode struct {
	FixedRadiusSearchResult // Embedded struct
	// contains filtered or unexported fields
}

FRSResultNode list node

func (*FRSResultNode) Next

func (n *FRSResultNode) Next() *FRSResultNode

Next returns the next node to the current

func (*FRSResultNode) Prev

func (n *FRSResultNode) Prev() *FRSResultNode

Prev returns the previous node to the current

type FixedRadiusSearchResult

type FixedRadiusSearchResult struct {
	Index       int
	SquaredDist float64
}

FixedRadiusSearchResult is used to store return values from searches

type GeoKeys

type GeoKeys struct {
	GeoKeyDirectory []uint16
	GeoDoubleParams []float64
	GeoASCIIParams  string
	Tags            []GeoTiffTag
}

GeoKeys structure

type GeoTiffTag

type GeoTiffTag struct {
	Name string
	Code int
}

GeoTiffTag data structure

func (GeoTiffTag) String

func (g GeoTiffTag) String() string

type GeotiffDataType

type GeotiffDataType int

GeotiffDataType geoTIFF data type

func (GeotiffDataType) GetBitLength

func (g GeotiffDataType) GetBitLength() uint32

GetBitLength returns the bit length

func (GeotiffDataType) String

func (g GeotiffDataType) String() string

String returns the English name of the DataType ("Byte", "ASCII", ...).

type GlobalEncodingField

type GlobalEncodingField struct {
	Value uint16
}

GlobalEncodingField contains the global encoding information in a LAS header

func (GlobalEncodingField) CoordinateReferenceSystemMethod

func (gef GlobalEncodingField) CoordinateReferenceSystemMethod() CoordinateReferenceSystemMethod

CoordinateReferenceSystemMethod returns the co-ordinate reference system method used within the file.

func (GlobalEncodingField) GpsTime

func (gef GlobalEncodingField) GpsTime() GpsTimeType

GpsTime returns the type of time format used in this file

func (GlobalEncodingField) ReturnDataSynthetic

func (gef GlobalEncodingField) ReturnDataSynthetic() bool

ReturnDataSynthetic returns a boolean indicating whether the return numbers have been generated synthetically.

func (GlobalEncodingField) String

func (gef GlobalEncodingField) String() string

func (GlobalEncodingField) WaveformDataExternal

func (gef GlobalEncodingField) WaveformDataExternal() bool

WaveformDataExternal returns a boolean indicating whether waveform packet data is stored internally to the file.

func (GlobalEncodingField) WaveformDataInternal

func (gef GlobalEncodingField) WaveformDataInternal() bool

WaveformDataInternal returns a boolean indicating whether waveform packet data is stored internally to the file.

type GpsTimeType

type GpsTimeType uint

GpsTimeType is a uint describing the type of time format used in in the file to store point GPS time.

func (GpsTimeType) String

func (gtt GpsTimeType) String() string

type IfdEntry

type IfdEntry struct {
	// contains filtered or unexported fields
}

IfdEntry IFD entry

func CreateIfdEntry

func CreateIfdEntry(code int, dataType GeotiffDataType, count uint32, data interface{}, byteOrder binary.ByteOrder) IfdEntry

CreateIfdEntry returns a new IFD entry

func (*IfdEntry) AddData

func (ifd *IfdEntry) AddData(data []byte)

AddData adds data to the IFD entry

func (*IfdEntry) InterpretDataAsASCII

func (ifd *IfdEntry) InterpretDataAsASCII() (u []string, err error)

InterpretDataAsASCII decodes the IFD entry in p, which must be of the ASCII type, and returns the decoded uint values.

func (*IfdEntry) InterpretDataAsFloat

func (ifd *IfdEntry) InterpretDataAsFloat() (u []float64, err error)

InterpretDataAsFloat interprets the data as a float

func (*IfdEntry) InterpretDataAsInt

func (ifd *IfdEntry) InterpretDataAsInt() (u []uint, err error)

InterpretDataAsInt interprets the data as an integer

func (*IfdEntry) InterpretDataAsRational

func (ifd *IfdEntry) InterpretDataAsRational() (u []float64, err error)

InterpretDataAsRational interprets the data as a rational number

func (IfdEntry) String

func (ifd IfdEntry) String() string

type LasFile

type LasFile struct {
	Header  LasHeader
	VlrData []VLR

	sync.RWMutex
	// contains filtered or unexported fields
}

LasFile is a structure for manipulating LAS files.

func InitializeUsingFile

func InitializeUsingFile(fileName string, other *LasFile) (*LasFile, error)

InitializeUsingFile initializes a new LAS file based on another existing file. The function transfers values from the header and the VLRs to the new file.

func NewLasFile

func NewLasFile(fileName, fileMode string) (*LasFile, error)

NewLasFile creates a new LasFile structure.

func (*LasFile) AddHeader

func (las *LasFile) AddHeader(header LasHeader) error

AddHeader adds a header to a LasFile created in 'w' (write) mode. The method is thread-safe.

func (*LasFile) AddLasPoint

func (las *LasFile) AddLasPoint(p LasPointer) error

AddLasPoint adds a point record to a Las file created in 'w' (write) mode. The method is thread-safe.

func (*LasFile) AddLasPoints

func (las *LasFile) AddLasPoints(points []LasPointer) error

AddLasPoints adds a slice of point record to a Las file created in 'w' (write) mode. The method is thread-safe.

func (*LasFile) AddVLR

func (las *LasFile) AddVLR(vlr VLR) error

AddVLR adds a variable length record (VLR) to a LAS file created in 'w' (write) mode. The method is thread-safe.

func (*LasFile) Close

func (las *LasFile) Close() error

Close closes a LasFile

func (*LasFile) FixedRadiusSearch2D

func (las *LasFile) FixedRadiusSearch2D(x, y float64) *FRSResultList

FixedRadiusSearch2D performs a 2D fixed radius search

func (*LasFile) FixedRadiusSearch3D

func (las *LasFile) FixedRadiusSearch3D(x, y, z float64) *FRSResultList

FixedRadiusSearch3D performs a 3D fixed radius search

func (*LasFile) GetXYZ

func (las *LasFile) GetXYZ(index int) (float64, float64, float64, error)

GetXYZ returns the x, y, z data for a specified point

func (*LasFile) LasPoint

func (las *LasFile) LasPoint(index int) (LasPointer, error)

LasPoint returns a LAS point.

func (*LasFile) PrintGeokeys

func (las *LasFile) PrintGeokeys() string

PrintGeokeys interprets the Geokeys, if there are any.

func (*LasFile) SetFixedRadiusSearchDistance

func (las *LasFile) SetFixedRadiusSearchDistance(radius float64, threeDimensionalSearch bool) error

SetFixedRadiusSearchDistance sets the fixed radius search

type LasHeader

type LasHeader struct {
	FileSignature        string
	FileSourceID         int
	GlobalEncoding       GlobalEncodingField
	ProjectID1           int
	ProjectID2           int
	ProjectID3           int
	ProjectID4           [8]byte
	VersionMajor         byte
	VersionMinor         byte
	SystemID             string // 32 characters
	GeneratingSoftware   string // 32 characters
	FileCreationDay      int
	FileCreationYear     int
	HeaderSize           int
	OffsetToPoints       int
	NumberOfVLRs         int
	PointFormatID        byte
	PointRecordLength    int
	NumberPoints         int
	NumberPointsByReturn [5]int
	XScaleFactor         float64
	YScaleFactor         float64
	ZScaleFactor         float64
	XOffset              float64
	YOffset              float64
	ZOffset              float64
	MaxX                 float64
	MinX                 float64
	MaxY                 float64
	MinY                 float64
	MaxZ                 float64
	MinZ                 float64
	WaveformDataStart    uint64
	// contains filtered or unexported fields
}

LasHeader is a LAS file header structure.

func (LasHeader) String

func (h LasHeader) String() string

type LasPointer

type LasPointer interface {
	Format() uint8
	PointData() *PointRecord0
	IsLateReturn() bool
	IsFirstReturn() bool
	IsIntermediateReturn() bool
	GpsTimeData() float64
	RgbData() *RgbData
}

LasPointer interface for all point record types

type PointBitField

type PointBitField struct {
	Value byte
}

PointBitField is a point record bit field

func (*PointBitField) EdgeOfFlightlineFlag

func (p *PointBitField) EdgeOfFlightlineFlag() bool

EdgeOfFlightlineFlag Edge of flightline flag

func (*PointBitField) NumberOfReturns

func (p *PointBitField) NumberOfReturns() byte

NumberOfReturns returns the number of returns of the point

func (*PointBitField) ReturnNumber

func (p *PointBitField) ReturnNumber() byte

ReturnNumber returns the return number of the point

func (*PointBitField) ScanDirectionFlag

func (p *PointBitField) ScanDirectionFlag() bool

ScanDirectionFlag scan direction flag, `true` if moving from the left side of the in-track direction to the right side and false the opposite.

type PointRecord0

type PointRecord0 struct {
	X             float64
	Y             float64
	Z             float64
	Intensity     uint16
	BitField      PointBitField
	ClassBitField ClassificationBitField
	ScanAngle     int8
	UserData      uint8
	PointSourceID uint16
}

PointRecord0 is a LAS point record type 0.

func (*PointRecord0) Format

func (p *PointRecord0) Format() uint8

Format returns the point format number.

func (*PointRecord0) GpsTimeData

func (p *PointRecord0) GpsTimeData() float64

GpsTimeData returns the GPS time data for the LAS point.

func (*PointRecord0) IsFirstReturn

func (p *PointRecord0) IsFirstReturn() bool

IsFirstReturn returns true if the point is a first return.

func (*PointRecord0) IsIntermediateReturn

func (p *PointRecord0) IsIntermediateReturn() bool

IsIntermediateReturn returns true if the point is an intermediate return.

func (*PointRecord0) IsLateReturn

func (p *PointRecord0) IsLateReturn() bool

IsLateReturn returns true if the point is a last return.

func (*PointRecord0) PointData

func (p *PointRecord0) PointData() *PointRecord0

PointData returns the point data (PointRecord0) for the LAS point.

func (*PointRecord0) RgbData

func (p *PointRecord0) RgbData() *RgbData

RgbData returns the RGB colour data for the LAS point.

type PointRecord1

type PointRecord1 struct {
	*PointRecord0
	GPSTime float64
}

PointRecord1 is a LAS point record type 1

func (*PointRecord1) Format

func (p *PointRecord1) Format() uint8

Format returns the point format number.

func (*PointRecord1) GpsTimeData

func (p *PointRecord1) GpsTimeData() float64

GpsTimeData returns the point data (PointRecord0) for the LAS point.

func (*PointRecord1) RgbData

func (p *PointRecord1) RgbData() *RgbData

RgbData returns the RGB colour data for the LAS point.

type PointRecord2

type PointRecord2 struct {
	*PointRecord0
	RGB *RgbData
}

PointRecord2 is a LAS point record type 2

func (*PointRecord2) Format

func (p *PointRecord2) Format() uint8

Format returns the point format number.

func (*PointRecord2) GpsTimeData

func (p *PointRecord2) GpsTimeData() float64

GpsTimeData returns the point data (PointRecord0) for the LAS point.

func (*PointRecord2) RgbData

func (p *PointRecord2) RgbData() *RgbData

RgbData returns the RGB colour data for the LAS point.

type PointRecord3

type PointRecord3 struct {
	*PointRecord0
	GPSTime float64
	RGB     *RgbData
}

PointRecord3 is a LAS point record type 3

func (*PointRecord3) Format

func (p *PointRecord3) Format() uint8

Format returns the point format number.

func (*PointRecord3) GpsTimeData

func (p *PointRecord3) GpsTimeData() float64

GpsTimeData returns the point data (PointRecord0) for the LAS point.

func (*PointRecord3) RgbData

func (p *PointRecord3) RgbData() *RgbData

RgbData returns the RGB colour data for the LAS point.

type RgbData

type RgbData struct {
	Red   uint16
	Green uint16
	Blue  uint16
}

RgbData holds LAS point red-green-blue colour data

type VLR

type VLR struct {
	Reserved                int
	UserID                  string // 16 characters
	RecordID                int
	RecordLengthAfterHeader int
	Description             string // 32 characters
	BinaryData              []uint8
}

VLR is a variable length record data structure

func (VLR) String

func (vlr VLR) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL