public final class LasFileReader extends Object
Typical usage:
The method always returns a list ofLasFileReader reader = new LasFileReader(new File("/path/to/file.LAS")); List<LasFile> lasFiles = reader.read();
LasFile
instances in case the
disk file contains multiple logical files in sequence.
This class supports all versions of the LAS format.
Constructor and Description |
---|
LasFileReader(File file)
Create a LAS file reader for the specified disk file,
using default character encoding (ISO 8859-1).
|
LasFileReader(File file,
Charset characterEncoding)
Create a LAS file reader for the specified disk file.
|
LasFileReader(InputStream inputStream)
Create a LAS file reader for the specified stream,
using default character encoding (ISO 8859-1).
|
LasFileReader(InputStream inputStream,
Charset characterEncoding)
Create a LAS file reader for the specified stream.
|
Modifier and Type | Method and Description |
---|---|
List<LasMessage> |
getMessages()
Return messages related to the previous LAS file read operation.
|
static Charset |
guessEncoding(File file)
Guess text encoding of the specified file.
|
static double |
isLasFile(File file,
byte[] content)
Get the probability that the specified file is a LAS file.
|
List<LasFile> |
read()
Read the disk file and return the associated LasFile instances.
|
List<LasFile> |
read(boolean shouldReadCurveData)
Read the disk file and return the associated LasFile instances.
|
List<LasFile> |
read(boolean shouldReadCurveData,
boolean shouldCaptureStatistics)
Read the disk file and return the associated LasFile instances.
|
List<LasFile> |
read(boolean shouldReadCurveData,
boolean shouldCaptureStatistics,
LasDataListener dataListener)
Read the disk file and return the associated LasFile instances.
|
void |
readData(List<LasFile> lasFiles,
boolean shouldCaptureStatistics,
LasDataListener dataListener)
Read data from a set of LAS files where the metadata has
already been read.
|
public LasFileReader(InputStream inputStream, Charset characterEncoding)
inputStream
- Stream to read. Non-null.characterEncoding
- Character encoding to use during read.
Typically UTF-8, US_ASCII or ISO 8859-1. Non-null.IllegalArgumentException
- If inputStream or characterEncoding is null.guessEncoding(java.io.File)
public LasFileReader(File file, Charset characterEncoding)
file
- Disk file to read. Non-null.characterEncoding
- Character encoding to use during read.
Typically UTF-8, US_ASCII or ISO 8859-1. Non-null.IllegalArgumentException
- If file or characterEncoding is null.guessEncoding(java.io.File)
public LasFileReader(InputStream inputStream)
inputStream
- Input stream to read. Non-null.IllegalArgumentException
- If inputStream is null.public LasFileReader(File file)
file
- Disk file to read. Non-null.IllegalArgumentException
- If file is null.public static double isLasFile(File file, byte[] content)
The check can be done with or without considering the content of the file. In the latter case, only the file name (typically its extension) is considered. In the former case a portion from the start of the file is used to match for known patterns. By passing the portion as an argument, the client code can read this once and then pass it to different classifiers in order to determine its most likely type.
Getting a portion of a file can be done by:
File file = ...; BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file)); byte[] content = new byte[2000]; stream.read(content, 0, content.length); stream.close();
file
- File to check. Null to classify on content only.content
- A number of bytes from the start of the file.
Null to classify on file name only.public static Charset guessEncoding(File file)
LAS files are supposed to be encoded as US-ASCII (7 bit ASCII), but are commonly encoded differently to accommodate for meta-data using language specific characters. Such meta-data will end up wrong (typically containing replacement characters often rendered as "?" in output) if read by the standard encoding.
This method will distinguish between US-ASCII, UTF8 or 8-bit ASCII (ISO 8859-1) and does not detect more esoteric encodings like UTF16 etc.
file
- File to check. Non-null.IllegalArgumentException
- If file is null.public List<LasMessage> getMessages()
public List<LasFile> read(boolean shouldReadCurveData, boolean shouldCaptureStatistics) throws IOException
shouldReadCurveData
- True to indicates that bulk data should be read.
Otherwise curves will be created, but not populated.shouldCaptureStatistics
- True to capture statistics per curve.
Statistics capture will reduce read performance slightly,
so set this to false if the statistics are not needed.IOException
- If the read operation fails for some reason.IllegalStateException
- If a depth step has more or fewer values than the number of curves in wrapped mode.LasCurve.getStatistics()
public void readData(List<LasFile> lasFiles, boolean shouldCaptureStatistics, LasDataListener dataListener) throws IOException, InterruptedException
There is nothing to gain in performance with this approach so in case the result is not cached, the following will be equivalent:// Read metadata List<LasFile> lasFiles = reader.read(false, ...); // Read the curve data reader.readData(lasFiles, ...);
// Read metadata List<LasFile> lasFiles = reader.read(false, ...); // Read all the data lasFiles = reader.read(true, ...);
lasFiles
- The LAS files to populate. These must be the
exact same list as retrieved by calling the
#read(false,...) on the same LasFileReader instance.
Otherwise the behavior is unpredictable.shouldCaptureStatistics
- True to capture statistics per curve during read.
Statistics capture will reduce read performance slightly,
so set this to false if the statistics are not needed.dataListener
- Listener that will be notified when new data has been read.
Null if not used.IllegalArgumentException
- If lasFiles is null.IOException
- If the read operation fails for some reason.InterruptedException
- If the client returns false from
the LasDataListener.dataRead(no.petroware.logio.las.LasSection, no.petroware.logio.las.LasFile)
method.IllegalStateException
- If a depth step has more or fewer values than the number of curves in wrapped mode.public List<LasFile> read(boolean shouldReadCurveData, boolean shouldCaptureStatistics, LasDataListener dataListener) throws IOException, InterruptedException
shouldReadCurveData
- True to indicates that bulk data should be read.
Otherwise curves will be created, but not populated.shouldCaptureStatistics
- True to capture statistics per curve.
Statistics capture will reduce read performance slightly,
so set this to false if the statistics are not needed.dataListener
- Client data listener. Null if not used.IOException
- If the read operation fails for some reason.InterruptedException
- If the data listener cancels the operation.IllegalStateException
- If a depth step has more or fewer values than the number of curves in wrapped mode.LasCurve.getStatistics()
public List<LasFile> read(boolean shouldReadCurveData) throws IOException
shouldReadCurveData
- Indicate if curve data should be read.
False to read header data only.IOException
- If the read operation fails for some reason.IllegalStateException
- If a depth step has more or fewer values than the number of curves in wrapped mode.read(boolean,boolean)
public List<LasFile> read() throws IOException
IOException
- If the read operation fails for some reason.IllegalStateException
- If a depth step has more or fewer values than the number of curves in wrapped mode.read(boolean,boolean)
Copyright © 2024 Petroware AS - https://petroware.no