Package ucar.nc2.geotiff
Class GeotiffWriter
- java.lang.Object
-
- ucar.nc2.geotiff.GeotiffWriter
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
GeoTiffWriter2
public class GeotiffWriter extends Object implements Closeable
Write GeoTIFF files. Regular data only
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
colorTable
protected GeoTiff
geotiff
protected short
pageNumber
-
Constructor Summary
Constructors Constructor Description GeotiffWriter(String fileOut)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static HashMap<Integer,Color>
createColorMap(int[] flag_values, String[] flag_colors)
Creates a colormap in the form of a mapping of the pixel value to the rgb color.int[]
getColorTable()
Get a copy of the current colormap as a 1-D 3*256 element array (or null).void
setColorTable(Map<Integer,Color> colorMap)
Have the geotiff include a colormap in the form of a mapping of the pixel value to the rgb triplet.void
setColorTable(Map<Integer,Color> colorMap, Color defaultRGB)
Have the geotiff include a colormap in the form of a mapping of the pixel value to the rgb triplet.void
writeGrid(GridDataset dataset, GridDatatype grid, Array data, boolean greyScale)
Write GridDatatype data to the geotiff file.void
writeGrid(GridDataset dataset, GridDatatype grid, Array data, boolean greyScale, DataType dtype)
Write GridDatatype data to the geotiff file.void
writeGrid(GeoReferencedArray array, boolean greyScale)
Write GridCoverage data to the geotiff file.void
writeGrid(GeoReferencedArray array, boolean greyScale, DataType dtype)
Write GridCoverage data to the geotiff file.
-
-
-
Field Detail
-
geotiff
protected GeoTiff geotiff
-
pageNumber
protected short pageNumber
-
colorTable
protected int[] colorTable
-
-
Constructor Detail
-
GeotiffWriter
public GeotiffWriter(String fileOut)
Constructor- Parameters:
fileOut
- name of output file.
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
writeGrid
public void writeGrid(GridDataset dataset, GridDatatype grid, Array data, boolean greyScale) throws IOException
Write GridDatatype data to the geotiff file. Greyscale mode will auto-normalize the data from 1 to 255 and save as unsigned bytes, with 0's used for missing data. A color table can be applied if specified via `setColorTable()`. Non-greyscale mode will save the data as floats, encoding missing data as the data minimum minus one.- Parameters:
dataset
- grid in contained in this datasetgrid
- data is in this griddata
- 2D array in YX ordergreyScale
- if true, write greyScale image, else dataSample.- Throws:
IOException
- on i/o error
-
writeGrid
public void writeGrid(GridDataset dataset, GridDatatype grid, Array data, boolean greyScale, DataType dtype) throws IOException, IllegalArgumentException
Write GridDatatype data to the geotiff file. Greyscale mode will auto-normalize the data from 1 to 255 and save as unsigned bytes, with 0's used for missing data. Non-greyscale mode with a floating point dtype will save the data as floats, encoding missing data as the data's minimum minus one. Any other dtype will save the data coerced to the specified dtype. A color table can be applied if specified via `setColorTable()` and the dtype is UBYTE.- Parameters:
dataset
- grid in contained in this datasetgrid
- data is in this griddata
- 2D array in YX ordergreyScale
- if true, write greyScale image, else dataSample.dtype
- DataType for the output. See other writeGrid() documentation for more details.- Throws:
IOException
- on i/o errorIllegalArgumentException
- if above assumptions not valid
-
getColorTable
public int[] getColorTable()
Get a copy of the current colormap as a 1-D 3*256 element array (or null). All 256 red values first, then green, then blue. For these RGB triplets, 0 is minimum intensity, 65535 is maximum intensity (due to geotiff conventions). This function is intended for debugging and testing.
-
setColorTable
public void setColorTable(Map<Integer,Color> colorMap)
Have the geotiff include a colormap in the form of a mapping of the pixel value to the rgb triplet. Assumes an RGB of {0, 0, 0} for any values not specified. Pass null to unset the colorTable. For these RGB triplets, 0 is minimum intensity, 255 is maximum intensity. Values outside that range will be floored/ceilinged to the [0, 255] range. The color table is also assumed to be for pixel values between 0 and 255. In order for the color table to be properly included in the geotiff, the output data type must be unsigned bytes. This works even for greyscale mode.
-
setColorTable
public void setColorTable(Map<Integer,Color> colorMap, Color defaultRGB)
Have the geotiff include a colormap in the form of a mapping of the pixel value to the rgb triplet. Provide a default RGB triplet for any values not specified. Pass null to unset the colorTable. For these RGB triplets, 0 is minimum intensity, 255 is maximum intensity. Values outside that range will be floored/ceilinged to the [0, 255] range. The color table is also assumed to be for pixel values between 0 and 255. In order for the color table to be properly included in the geotiff, the output data type must be unsigned bytes. This works even for greyscale mode.
-
createColorMap
public static HashMap<Integer,Color> createColorMap(int[] flag_values, String[] flag_colors) throws IllegalArgumentException, NumberFormatException
Creates a colormap in the form of a mapping of the pixel value to the rgb color.- Parameters:
flag_values
- is an array of values for each categoricalflag_colors
- is an array of octal strings (e.g., #00AAFF) of same length as flag_values.- Returns:
- Map of the flag values to Color objects the RGB color values, with 0 representing minimum intensity and 255 representing maximum intensity.
- Throws:
IllegalArgumentException
- if above assumptions not validNumberFormatException
- if a supplied color isn't parsable
-
writeGrid
public void writeGrid(GeoReferencedArray array, boolean greyScale) throws IOException
Write GridCoverage data to the geotiff file. Greyscale mode will auto-normalize the data from 1 to 255 and save as unsigned bytes, with 0's used for missing data. A color table can be applied if specified via `setColorTable()`. Non-greyscale mode will save the data as floats, encoding missing data as the data minimum minus one.- Parameters:
array
- GeoReferencedArray array in YX ordergreyScale
- if true, write greyScale image, else dataSample.- Throws:
IOException
- on i/o error
-
writeGrid
public void writeGrid(GeoReferencedArray array, boolean greyScale, DataType dtype) throws IOException, IllegalArgumentException
Write GridCoverage data to the geotiff file. Greyscale mode will auto-normalize the data from 1 to 255 and save as unsigned bytes, with 0's used for missing data. Non-greyscale mode with a floating point dtype will save the data as floats, encoding missing data as the data's minimum minus one. Any other dtype will save the data coerced to the specified dtype. A color table can be applied if specified via `setColorTable()` and the dtype is UBYTE.- Parameters:
array
- GeoReferencedArray array in YX ordergreyScale
- if true, write greyScale image, else dataSample.dtype
- if greyScale is false, then save the data in the given data type. Currently, this is a bit hobbled in order to avoid back-compatibility breaks. If greyScale is true and this is not UBYTE, then an exception is thrown. If dtype is DOUBLE, it downcasted to FLOAT instead. If using the colorTable and this is not UBYTE, then an exception is thrown. If null, then use the datatype of the given array.- Throws:
IOException
- on i/o errorIllegalArgumentException
- if data isn't regular or if contradicting the greyScale argument.
-
-