-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support embedding GDALMetadata with tiffset #317
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
openeo-geotrellis/src/test/scala/org/openeo/geotrellis/geotiff/PackageTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.openeo.geotrellis.geotiff | ||
|
||
import geotrellis.raster.io.geotiff.MultibandGeoTiff | ||
import org.junit.jupiter.api.Assertions.{assertEquals, assertThrows, assertTrue} | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.io.TempDir | ||
|
||
import java.nio.file.{Files, Path, Paths} | ||
|
||
class PackageTest { | ||
|
||
@Test | ||
def testEmbedGdalMetadata(@TempDir tempDir: Path): Unit = { | ||
val geotiffCopy = tempDir.resolve("copy.tif") | ||
Files.copy(getClass.getResourceAsStream("/org/openeo/geotrellis/cgls_ndvi300.tif"), geotiffCopy) | ||
|
||
assertTrue(processingSoftware(geotiffCopy).isEmpty) | ||
|
||
val gdalMetadataXml = | ||
<GDALMetadata> | ||
<Item name="PROCESSING_SOFTWARE">0.45.0a1</Item> | ||
<Item name="DESCRIPTION" sample="0">CO</Item> | ||
</GDALMetadata> | ||
|
||
embedGdalMetadata(gdalMetadataXml.toString(), geotiffCopy) | ||
|
||
assertEquals(Some("0.45.0a1"), processingSoftware(geotiffCopy)) | ||
} | ||
|
||
@Test | ||
def testEmbedGdalMetadataFails(): Unit = { | ||
val e = assertThrows(classOf[Exception], () => | ||
embedGdalMetadata(gdalMetadataXml = "", geotiffPath = Paths.get("doesnotexist.tif"))) | ||
|
||
assertTrue(e.getMessage contains "doesnotexist.tif: No such file or directory") | ||
} | ||
|
||
private def processingSoftware(geotiff: Path): Option[String] = | ||
MultibandGeoTiff(geotiff.toString).tags.headTags.get("PROCESSING_SOFTWARE") | ||
} |