use of it.geosolutions.imageio.plugins.nitronitf.wrapper.ImageWrapper.Representation in project imageio-ext by geosolutions-it.
the class WriterTest method testNITFWrite.
@Test
@Ignore
public /**
* Simple writing code which won't be run. You can use it as a sample on how to
* setup some writing machinery.
*
* @throws IOException
* @throws NITFException
*/
void testNITFWrite() throws IOException, NITFException {
// This TEST won't run, you can use it as a sample on how to setup some writing code
if (!NITFUtilities.isNITFAvailable()) {
System.out.println("NITF native libs aren't available: skipping tests");
return;
}
final String[] inputFilePaths = new String[] { "/tmp/sampleForNitf.tif" };
final String[] requestedCrs = new String[] { "EPSG:32638" };
FileImageInputStream fisi = new FileImageInputStream(new File("/tmp/license.txt"));
int length = (int) fisi.length();
byte[] data = new byte[length];
fisi.read(data);
// final int j = 0;
// String inputFilePath = inputFilePaths[0];
//
// final GeoTiffReader gtReader = new GeoTiffReader(new File(inputFilePath));
// final GridCoverage2D gridCoverage = gtReader.read(null);
// final RenderedImage ri = gridCoverage.getRenderedImage();
// Image to be written
RenderedImage ri = null;
final int numBands = ri.getSampleModel().getNumBands();
// Geometry geom = null;
// ShapeFileWrapper shpWrapper = buildShape(geom);
LinkedHashMap<String, Map<String, String>> tresMap = new LinkedHashMap<String, Map<String, String>>();
// //
//
// Populating TaggedRecordExtensions field with "FAKE" values,
// for testing purposes
//
// //
NITFImageWriterSpi SPI = new NITFImageWriterSpi();
final WriteCompression[] compressions = new WriteCompression[] { WriteCompression.NPJE_NL, WriteCompression.EPJE_NL, WriteCompression.NPJE_VL, WriteCompression.EPJE_VL };
for (int w = 0; w < 4; w++) {
final NITFImageWriter writer = new NITFImageWriter(SPI);
final WriteCompression compression = compressions[w];
String fileName = "/tmp/output_" + (numBands == 1 ? "PAN_" : "MULTI_") + compression.toString() + "_jp2.ntf";
File nitfFile = new File(fileName);
HeaderWrapper header = setupDefaultHeaderWrapper();
Calendar cal = Calendar.getInstance();
String timeStamp = null;
synchronized (SDF) {
// not thread safe
timeStamp = SDF.format(cal.getTime());
}
header.setDateTime(timeStamp);
List<TextWrapper> texts = new LinkedList<TextWrapper>();
// Adding 3 text segments
for (int i = 0; i < 3; i++) {
TextWrapper text = setupDefaultNITFText();
if (i > 0) {
text.setTitle("SAMPLE" + i);
text.setId("ID" + i);
}
text.setTextContent(data);
texts.add(text);
}
header.setTitle(nitfFile.getName());
NITFImageWriteParam param = new NITFImageWriteParam();
NITFProperties metadata = new NITFProperties();
param.setWriteCompression(compression);
writer.setOutput(nitfFile);
ImageWrapper image = new ImageWrapper();
image.setImage(ri);
image.setSource(DEFAULT_IMAGE_SOURCE);
image.setTitle(numBands == 1 ? "SamplePanchromaticImagery.ntf" : "SampleMultiSpectralImagery.NTF");
image.setId(numBands == 1 ? "P100000000" : "M100000000");
List<String> comments = new ArrayList<String>(5);
comments.add("The imagery and metadata data has been added ");
comments.add("for testing purposes");
comments.add("This is a test comment");
comments.add("made of 5 lines");
comments.add("of text.");
image.setComments(comments);
image.setCompression(compression);
image.setDateTime(timeStamp);
image.setImageCoordinateSystem("G");
image.setIgeolo("453131173651215453133773651210453133713650902453131113650907");
image.setImageMagnification("1.0");
final int nBands = ri.getSampleModel().getNumBands();
image.setImageCategory(nBands > 1 ? Category.MS : Category.VIS);
Representation r = nBands > 1 ? Representation.RGB : Representation.MONO;
String rString = r.toString();
image.setRepresentation(r);
ImageBand[] imageBands = new ImageBand[nBands];
if (nBands == 1) {
imageBands[0] = new ImageBand("", "" + rString.charAt(0));
} else {
for (int i = 0; i < nBands; i++) {
imageBands[i] = new ImageBand("" + (rString.charAt(i)), "" + (rString.charAt(i)));
}
}
image.setBands(imageBands);
List<ImageWrapper> imagesWrapper = new ArrayList<ImageWrapper>();
imagesWrapper.add(image);
metadata.setHeader(header);
// metadata.setShape(shpWrapper);
image.setTres(tresMap);
metadata.setImagesWrapper(imagesWrapper);
metadata.setTextsWrapper(texts);
param.setNitfProperties(metadata);
writer.write(null, new IIOImage(ri, null, null), param);
writer.dispose();
// gtReader.dispose();
}
}
Aggregations