Skip to content

Commit 05712d0

Browse files
committed
Add Format.has() method to test for whether a Format has a Raster
1 parent b6a962c commit 05712d0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/main/groovy/geoscript/layer/Format.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ class Format {
197197
names
198198
}
199199

200+
/**
201+
* Whether the Format has a Raster by the given name
202+
* @param name The Raster name
203+
* @return Whether the Format has a Raster by the given name
204+
*/
205+
boolean has(String name) {
206+
getNames().contains(name)
207+
}
208+
200209
/**
201210
* Get metadata
202211
* @param name The optional Raster name

src/test/groovy/geoscript/layer/FormatTestCase.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ class FormatTestCase {
1717
assertNotNull(format)
1818
assertNotNull(format.stream)
1919
assertTrue(format instanceof GeoTIFF)
20+
assertTrue(format.has("alki"))
21+
assertFalse(format.has("badname"))
2022

2123
// Existing NetCDF
2224
file = new File(getClass().getClassLoader().getResource("O3-NO2.nc").toURI())
2325
format = Format.getFormat(file)
2426
assertNotNull(format)
2527
assertNotNull(format.stream)
2628
assertTrue(format instanceof NetCDF)
29+
assertTrue(format.has("NO2"))
30+
assertTrue(format.has("O3"))
31+
assertFalse(format.has("A123"))
2732

2833
// New png file
2934
file = new File("doesnotexist.png")

0 commit comments

Comments
 (0)