use of org.codice.imaging.nitf.fluent.NitfSegmentsFlow in project alliance by codice.
the class NitfGmtiTransformerTest method testNullMetacard.
@Test(expected = IllegalArgumentException.class)
public void testNullMetacard() throws Exception {
NitfSegmentsFlow nitfSegmentsFlow = mock(NitfSegmentsFlow.class);
nitfGmtiTransformer.transform(nitfSegmentsFlow, null);
}
use of org.codice.imaging.nitf.fluent.NitfSegmentsFlow in project alliance by codice.
the class ImageInputTransformerTest method testNitfWithDifferentImageDates.
@Test
public void testNitfWithDifferentImageDates() throws Exception {
File nitfFile = File.createTempFile("nitf-", ".ntf");
try {
final DateTime fileDateTime = NitfTestCommons.createNitfDateTime(2016, 1, 1, 0, 0, 0);
DateTime[] imageDateTimes = { NitfTestCommons.createNitfDateTime(2001, 1, 1, 0, 0, 0), NitfTestCommons.createNitfDateTime(2002, 1, 1, 0, 0, 0), NitfTestCommons.createNitfDateTime(2003, 1, 1, 0, 0, 0) };
createNitfWithDifferentImageDateTimes(nitfFile, fileDateTime, imageDateTimes);
try (InputStream inputStream = new FileInputStream(nitfFile)) {
Metacard metacard = metacardFactory.createMetacard("differentImageDateTimesTest");
NitfSegmentsFlow nitfSegmentsFlow = new NitfParserInputFlowImpl().inputStream(inputStream).headerOnly();
nitfSegmentsFlow = headerTransformer.transform(nitfSegmentsFlow, metacard);
metacard = transformer.transform(nitfSegmentsFlow, metacard);
assertNotNull(metacard);
validateDates(metacard, fileDateTime, imageDateTimes);
}
} finally {
nitfFile.delete();
}
}
use of org.codice.imaging.nitf.fluent.NitfSegmentsFlow in project alliance by codice.
the class ImageInputTransformerTest method testPiaimc.
@Test
public void testPiaimc() throws IOException, NitfFormatException {
File nitfFile = File.createTempFile("nitf-", ".ntf");
try {
createNitfWithPiaimc(nitfFile);
try (InputStream inputStream = new FileInputStream(nitfFile)) {
Metacard metacard = metacardFactory.createMetacard("csexraTest");
NitfSegmentsFlow nitfSegmentsFlow = new NitfParserInputFlowImpl().inputStream(inputStream).headerOnly();
transformer.transform(nitfSegmentsFlow, metacard);
assertThat(metacard.getAttribute(Isr.CLOUD_COVER).getValue(), is(70.0));
}
} finally {
nitfFile.delete();
}
}
use of org.codice.imaging.nitf.fluent.NitfSegmentsFlow in project alliance by codice.
the class ImageInputTransformerTest method testPiatgb.
@Test
public void testPiatgb() throws IOException, NitfFormatException {
File nitfFile = File.createTempFile("nitf-", ".ntf");
try {
createNitfWithPiatgb(nitfFile);
try (InputStream inputStream = new FileInputStream(nitfFile)) {
Metacard metacard = metacardFactory.createMetacard("piatgbTest");
NitfSegmentsFlow nitfSegmentsFlow = new NitfParserInputFlowImpl().inputStream(inputStream).headerOnly();
transformer.transform(nitfSegmentsFlow, metacard);
assertThat(metacard.getAttribute(PiatgbAttribute.TARGET_NAME_ATTRIBUTE.getLongName()).getValue(), is("Canberra Hill"));
}
} finally {
nitfFile.delete();
}
}
use of org.codice.imaging.nitf.fluent.NitfSegmentsFlow in project alliance by codice.
the class NitfImageTransformer method handleSegments.
private void handleSegments(NitfSegmentsFlow nitfSegmentsFlow, Metacard metacard) {
validateArgument(nitfSegmentsFlow, "nitfSegmentsFlow");
validateArgument(metacard, "metacard");
List<Polygon> polygonList = new ArrayList<>();
List<Date> imageDateAndTimeList = new ArrayList<>();
nitfSegmentsFlow.forEachImageSegment(segment -> handleImageSegmentHeader(metacard, segment, polygonList, imageDateAndTimeList)).forEachGraphicSegment(segment -> handleSegmentHeader(metacard, segment, GraphicAttribute.values())).forEachTextSegment(segment -> handleSegmentHeader(metacard, segment, TextAttribute.values())).forEachSymbolSegment(segment -> handleSegmentHeader(metacard, segment, SymbolAttribute.values())).forEachLabelSegment(segment -> handleSegmentHeader(metacard, segment, LabelAttribute.values())).end();
// Set GEOGRAPHY from discovered polygons
if (polygonList.size() == 1) {
metacard.setAttribute(new AttributeImpl(Core.LOCATION, polygonList.get(0).toText()));
} else if (polygonList.size() > 1) {
Polygon[] polyAry = polygonList.toArray(new Polygon[polygonList.size()]);
MultiPolygon multiPolygon = GEOMETRY_FACTORY.createMultiPolygon(polyAry);
metacard.setAttribute(new AttributeImpl(Core.LOCATION, multiPolygon.toText()));
}
// Set start, effective, and end from discovered imageDateAndTimes
if (!imageDateAndTimeList.isEmpty()) {
LOGGER.trace("Discovered imageDateTimes of the image segments: {}", imageDateAndTimeList);
final Date firstDateAndTime = imageDateAndTimeList.get(0);
final Date lastDateAndTime = imageDateAndTimeList.get(imageDateAndTimeList.size() - 1);
LOGGER.trace(SETTING_THE_METACARD_ATTRIBUTE_TO, Metacard.EFFECTIVE, firstDateAndTime);
metacard.setAttribute(new AttributeImpl(Metacard.EFFECTIVE, firstDateAndTime));
LOGGER.trace(SETTING_THE_METACARD_ATTRIBUTE_TO, ddf.catalog.data.types.DateTime.START, firstDateAndTime);
metacard.setAttribute(new AttributeImpl(ddf.catalog.data.types.DateTime.START, firstDateAndTime));
LOGGER.trace(SETTING_THE_METACARD_ATTRIBUTE_TO, ddf.catalog.data.types.DateTime.END, lastDateAndTime);
metacard.setAttribute(new AttributeImpl(ddf.catalog.data.types.DateTime.END, lastDateAndTime));
}
}
Aggregations