Skip to content

Commit

Permalink
Issue 105: Enhance SVM to write GeoTIFF files
Browse files Browse the repository at this point in the history
  • Loading branch information
gwlucastrig committed Jan 15, 2024
1 parent 569de00 commit 7e660b0
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions gis/src/main/java/org/tinfour/gis/geotiff/GeoTiffTableBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.zip.Deflater;
import org.apache.commons.imaging.ImageWriteException;
import org.apache.commons.imaging.PixelDensity;
import org.apache.commons.imaging.common.RationalNumber;
import org.apache.commons.imaging.common.mylzw.MyLzwCompressor;
import org.apache.commons.imaging.formats.tiff.TiffElement;
import org.apache.commons.imaging.formats.tiff.TiffImageData;
import static org.apache.commons.imaging.formats.tiff.constants.GdalLibraryTagConstants.EXIF_TAG_GDAL_NO_DATA;
import org.apache.commons.imaging.formats.tiff.constants.GeoTiffTagConstants;
import static org.apache.commons.imaging.formats.tiff.constants.GeoTiffTagConstants.EXIF_TAG_MODEL_PIXEL_SCALE_TAG;
import static org.apache.commons.imaging.formats.tiff.constants.GeoTiffTagConstants.EXIF_TAG_MODEL_TIEPOINT_TAG;
import static org.apache.commons.imaging.formats.tiff.constants.TiffConstants.TIFF_COMPRESSION_LZW;
import static org.apache.commons.imaging.formats.tiff.constants.TiffConstants.TIFF_COMPRESSION_DEFLATE_ADOBE;
import static org.apache.commons.imaging.formats.tiff.constants.TiffConstants.TIFF_COMPRESSION_UNCOMPRESSED;
import org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants;
import static org.apache.commons.imaging.formats.tiff.constants.TiffTagConstants.PLANAR_CONFIGURATION_VALUE_CHUNKY;
Expand Down Expand Up @@ -423,29 +423,29 @@ public byte[] encodeBlock(float[] f, int nRows, int scanSize) {
b[aOffset + i] = (byte) ((b[aOffset + i] & 0xff) - (b[aOffset + i - 1] & 0xff));
}
}

try {
final int LZW_MINIMUM_CODE_SIZE = 8;
MyLzwCompressor compressor = new MyLzwCompressor(
LZW_MINIMUM_CODE_SIZE, ByteOrder.BIG_ENDIAN, true);
final byte[] compressed = compressor.compress(b);
return compressed;
} catch (IOException iex) {
return null;
}

//
// // apply the Deflate
// Deflater deflater = new Deflater(6);
// deflater.setInput(b, 0, b.length);
// deflater.finish();
// byte[] deflaterResult = new byte[b.length + 1024];
// int dN = deflater.deflate(deflaterResult, 0, deflaterResult.length, Deflater.FULL_FLUSH);
// if (dN <= 0) {
// // deflate failed
// return null;
// }
// return Arrays.copyOf(deflaterResult, dN);
// try {
// final int LZW_MINIMUM_CODE_SIZE = 8;
// MyLzwCompressor compressor = new MyLzwCompressor(
// LZW_MINIMUM_CODE_SIZE, ByteOrder.BIG_ENDIAN, true);
// final byte[] compressed = compressor.compress(b);
// return compressed;
// } catch (IOException iex) {
// return null;
// }


// apply the Deflate compression technique
Deflater deflater = new Deflater(6);
deflater.setInput(b, 0, b.length);
deflater.finish();
byte[] deflaterResult = new byte[b.length + 1024];
int dN = deflater.deflate(deflaterResult, 0, deflaterResult.length, Deflater.FULL_FLUSH);
if (dN <= 0) {
// deflate failed
return null;
}
return Arrays.copyOf(deflaterResult, dN);
}

/**
Expand All @@ -468,8 +468,8 @@ public void writeTiles(File geoTiffFile, int width, int height, int tileSize, by
short planarConfiguration;

if (compressionEnabled) {
//compression = TIFF_COMPRESSION_DEFLATE_ADOBE;
compression = TIFF_COMPRESSION_LZW;
compression = TIFF_COMPRESSION_DEFLATE_ADOBE;
//compression = TIFF_COMPRESSION_LZW;
} else {
compression = TIFF_COMPRESSION_UNCOMPRESSED;
}
Expand Down

0 comments on commit 7e660b0

Please sign in to comment.