Skip to content

Commit

Permalink
[GEOS-8674]: Updating WCS GeoTIFF Encoding profiles (parameter values)
Browse files Browse the repository at this point in the history
  • Loading branch information
dromagnoli committed Apr 5, 2018
1 parent ac753d6 commit f1976da
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ private void handleInterleaving(Map<String, String> encondingParameters, GridCov
if(encondingParameters.containsKey("interleave")){
// ok, the interleaving has been specified, let's see what we got
final String interleavingS= encondingParameters.get("interleave");
if(interleavingS.equals("pixel")){
if (interleavingS.equals("pixel") || interleavingS.equals("Pixel")) {
// ok we want pixel interleaving, TIFF ImageWriter always writes
// with pixel interleaving hence, we are good!
} else if(interleavingS.equals("band")){
} else if (interleavingS.equals("band") || interleavingS.equals("Band")) {
// TODO implement this in TIFF Writer, as it is not supported right now
throw new OWS20Exception("Banded Interleaving not supported", ows20Code(WcsExceptionCode.InterleavingNotSupported), interleavingS);
} else {
Expand Down Expand Up @@ -330,7 +330,7 @@ private void handleCompression(Map<String, String> econdingParameters,
} else if(compressionS.equals("PackBits")){
wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
wp.setCompressionType("PackBits");
} else if(compressionS.equals("DEFLATE")){
} else if (compressionS.equals("DEFLATE") || compressionS.equals("Deflate")) {
wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
wp.setCompressionType("Deflate");
} else if(compressionS.equals("Huffman")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@

public class GeoTiffKvpTest extends WCSKVPTestSupport {

static class TiffTagTest {
String tagString;
String tagValue;

public TiffTagTest(String tagString, String tagValue) {
this.tagString = tagString;
this.tagValue = tagValue;
}
}

final static TiffTagTest JPEG_TAG = new TiffTagTest("JPEG",
Integer.toString(BaselineTIFFTagSet.COMPRESSION_JPEG));

final static TiffTagTest DEFLATE_TAG = new TiffTagTest("Deflate",
Integer.toString(BaselineTIFFTagSet.COMPRESSION_DEFLATE));

@Test
public void extensionGeotiff() throws Exception {
// complete
Expand All @@ -62,6 +78,27 @@ public void extensionGeotiff() throws Exception {
assertEquals("256", extensions.get("http://www.opengis.net/wcs/geotiff/1.0:tilewidth"));
}

@Test
public void extensionGeotiff2() throws Exception {
String request = "wcs?request=GetCoverage&service=WCS&version=2.0.1" +
"&coverageId=wcs__BlueMarble&compression=Deflate" +
"&interleave=Pixel&tiling=true&tileheight=256&tilewidth=256";
GetCoverageType gc = parse(request);

Map<String, Object> extensions = getExtensionsMap(gc);

assertEquals("Deflate", extensions.get("http://www.opengis.net/wcs/geotiff/1.0:compression"));
assertEquals("Pixel", extensions.get("http://www.opengis.net/wcs/geotiff/1.0:interleave"));
assertEquals("true", extensions.get("http://www.opengis.net/wcs/geotiff/1.0:tiling"));
assertEquals("256", extensions.get("http://www.opengis.net/wcs/geotiff/1.0:tileheight"));
assertEquals("256", extensions.get("http://www.opengis.net/wcs/geotiff/1.0:tilewidth"));
MockHttpServletResponse response = getAsServletResponse(request);

assertEquals("image/tiff", response.getContentType());
byte[] tiffContents = getBinary(response);
checkTiff(tiffContents, DEFLATE_TAG);
}

@Test
public void extensionGeotiffPrefixed() throws Exception {
// complete
Expand Down Expand Up @@ -125,7 +162,7 @@ private void jpeg(boolean prefix) throws Exception {

assertEquals("image/tiff", response.getContentType());
byte[] tiffContents = getBinary(response);
checkJpegTiff(tiffContents);
checkTiff(tiffContents, JPEG_TAG);
}

@Test
Expand Down Expand Up @@ -157,10 +194,10 @@ public void jpegMediaType() throws Exception {

// make sure we can read the coverage back and perform checks on it
byte[] tiffContents = IOUtils.toByteArray(coveragePart.getInputStream());
checkJpegTiff(tiffContents);
checkTiff(tiffContents, JPEG_TAG);
}

private void checkJpegTiff(byte[] tiffContents) throws IOException,
private void checkTiff(byte[] tiffContents, TiffTagTest tiffTagTest) throws IOException,
FileNotFoundException, IIOException {
File file = File.createTempFile("bm_gtiff", "bm_gtiff.tiff", new File("./target"));
FileUtils.writeByteArrayToFile(file, tiffContents);
Expand All @@ -175,8 +212,8 @@ private void checkJpegTiff(byte[] tiffContents) throws IOException,
IIOMetadataNode root = (IIOMetadataNode)reader.getImageMetadata(0).getAsTree(TIFFImageMetadata.nativeMetadataFormatName);
IIOMetadataNode field = getTiffField(root, BaselineTIFFTagSet.TAG_COMPRESSION);
assertNotNull(field);
assertEquals("JPEG", field.getFirstChild().getFirstChild().getAttributes().item(1).getNodeValue());
assertEquals("7", field.getFirstChild().getFirstChild().getAttributes().item(0).getNodeValue());
assertEquals(tiffTagTest.tagString, field.getFirstChild().getFirstChild().getAttributes().item(1).getNodeValue());
assertEquals(tiffTagTest.tagValue, field.getFirstChild().getFirstChild().getAttributes().item(0).getNodeValue());

IIOMetadataNode node = metadata.getStandardDataNode();
assertNotNull(node);
Expand Down

0 comments on commit f1976da

Please sign in to comment.