Skip to content

Commit

Permalink
Add LASPoint.hasGPSTime()
Browse files Browse the repository at this point in the history
  • Loading branch information
mreutegg committed Aug 11, 2024
1 parent e79ef19 commit 23adc09
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/main/java/com/github/mreutegg/laszip4j/LASPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,20 @@ public char getPointSourceID() {
return p.getPoint_source_ID();
}

/**
* @return {@code true} if this point has "GPS Time"; {@code false} otherwise.
*/
public boolean hasGPSTime() {
return p.haveGpsTime();
}

/**
* @return "GPS Time" as a double.
* @throws IllegalStateException when called on a point without GPS Time.
* @see #hasGPSTime()
*/
public double getGPSTime() {
checkHasGPSTime();
return p.getGps_time();
}

Expand Down Expand Up @@ -237,4 +247,10 @@ private void checkHasRGB() throws IllegalStateException {
throw new IllegalStateException("Point does not have RGB data");
}
}

private void checkHasGPSTime() throws IllegalStateException {
if (!hasGPSTime()) {
throw new IllegalStateException("Point does not have GPS Time");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ private IGpsTimeProvider getGpsTimeProvider()
{
for(PointDataRecord r : PointRecords)
{
if (null != r && r instanceof IGpsTimeProvider)
if (r instanceof IGpsTimeProvider)
return (IGpsTimeProvider)r;
}

Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/github/mreutegg/laszip4j/LASReaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,20 @@ public void readPointWithoutRGB() {
}
}
}

@Test
public void readPointWithoutGPSTime() {
// extraBytes test file does not have GPS Time
LASReader reader = new LASReader(files.extraBytes);

for (LASPoint p : reader.getPoints()) {
assertFalse(p.hasGPSTime());
try {
p.getGPSTime();
fail("LASPoint.getGPSTime() must throw IllegalStateException");
} catch (IllegalStateException e) {
// expected
}
}
}
}

0 comments on commit 23adc09

Please sign in to comment.