use of de.micromata.opengis.kml.v_2_2_0.TimeSpan in project ddf by codice.
the class TestKMLTransformerImpl method testPerformDefaultTransformationPolygonLocation.
@Test
public void testPerformDefaultTransformationPolygonLocation() throws CatalogTransformerException {
MetacardImpl metacard = createMockMetacard();
metacard.setLocation(POLYGON_WKT);
Placemark placemark = kmlTransformer.performDefaultTransformation(metacard, null);
assertThat(placemark.getId(), is("Placemark-" + ID));
assertThat(placemark.getName(), is(TITLE));
assertThat(placemark.getTimePrimitive(), instanceOf(TimeSpan.class));
TimeSpan timeSpan = (TimeSpan) placemark.getTimePrimitive();
assertThat(timeSpan.getBegin(), is(dateFormat.format(metacard.getEffectiveDate())));
assertThat(placemark.getGeometry(), instanceOf(MultiGeometry.class));
MultiGeometry multiGeo = (MultiGeometry) placemark.getGeometry();
assertThat(multiGeo.getGeometry().size(), is(2));
assertThat(multiGeo.getGeometry().get(0), instanceOf(Point.class));
assertThat(multiGeo.getGeometry().get(1), instanceOf(Polygon.class));
}
use of de.micromata.opengis.kml.v_2_2_0.TimeSpan in project ddf by codice.
the class TestKMLTransformerImpl method testPerformDefaultTransformationMultiPolygonLocation.
@Test
public void testPerformDefaultTransformationMultiPolygonLocation() throws CatalogTransformerException {
MetacardImpl metacard = createMockMetacard();
metacard.setLocation(MULTIPOLYGON_WKT);
Placemark placemark = kmlTransformer.performDefaultTransformation(metacard, null);
assertThat(placemark.getId(), is("Placemark-" + ID));
assertThat(placemark.getName(), is(TITLE));
assertThat(placemark.getTimePrimitive(), instanceOf(TimeSpan.class));
TimeSpan timeSpan = (TimeSpan) placemark.getTimePrimitive();
assertThat(timeSpan.getBegin(), is(dateFormat.format(metacard.getEffectiveDate())));
assertThat(placemark.getGeometry(), instanceOf(MultiGeometry.class));
MultiGeometry multiGeo = (MultiGeometry) placemark.getGeometry();
assertThat(multiGeo.getGeometry().size(), is(2));
assertThat(multiGeo.getGeometry().get(0), instanceOf(Point.class));
assertThat(multiGeo.getGeometry().get(1), instanceOf(MultiGeometry.class));
MultiGeometry multiPolygon = (MultiGeometry) multiGeo.getGeometry().get(1);
assertThat(multiPolygon.getGeometry().size(), is(2));
assertThat(multiPolygon.getGeometry().get(0), instanceOf(Polygon.class));
assertThat(multiPolygon.getGeometry().get(1), instanceOf(Polygon.class));
}
use of de.micromata.opengis.kml.v_2_2_0.TimeSpan in project ddf by codice.
the class KMLTransformerImpl method performDefaultTransformation.
/**
* The default Transformation from a {@link Metacard} to a KML {@link Placemark}. Protected to
* easily allow other default transformations.
*
* @param entry
* - the {@link Metacard} to transform.
* @param urlToMetacard
* @return
* @throws javax.xml.transform.TransformerException
*/
protected Placemark performDefaultTransformation(Metacard entry, String url) throws CatalogTransformerException {
// wrap metacard to work around classLoader/reflection issues
entry = new MetacardImpl(entry);
Placemark kmlPlacemark = KmlFactory.createPlacemark();
kmlPlacemark.setId("Placemark-" + entry.getId());
kmlPlacemark.setName(entry.getTitle());
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
String effectiveTime = null;
if (entry.getEffectiveDate() == null) {
effectiveTime = dateFormat.format(new Date());
} else {
effectiveTime = dateFormat.format(entry.getEffectiveDate());
}
TimeSpan timeSpan = KmlFactory.createTimeSpan();
timeSpan.setBegin(effectiveTime);
kmlPlacemark.setTimePrimitive(timeSpan);
kmlPlacemark.setGeometry(getKmlGeoFromWkt(entry.getLocation()));
String description = entry.getTitle();
Handlebars handlebars = new Handlebars(templateLoader);
handlebars.registerHelpers(templateHelper);
try {
Template template = handlebars.compile(DESCRIPTION_TEMPLATE);
description = template.apply(new HandlebarsMetacard(entry));
LOGGER.debug(description);
} catch (IOException e) {
LOGGER.debug("Failed to apply description Template", e);
}
kmlPlacemark.setDescription(description);
String styleUrl = styleMapper.getStyleForMetacard(entry);
if (StringUtils.isNotBlank(styleUrl)) {
kmlPlacemark.setStyleUrl(styleUrl);
}
return kmlPlacemark;
}
use of de.micromata.opengis.kml.v_2_2_0.TimeSpan in project ddf by codice.
the class KMLTransformerImplTest method testPerformDefaultTransformationLineStringLocation.
@Test
public void testPerformDefaultTransformationLineStringLocation() throws CatalogTransformerException {
MetacardImpl metacard = createMockMetacard();
metacard.setLocation(LINESTRING_WKT);
Placemark placemark = kmlTransformer.performDefaultTransformation(metacard);
assertThat(placemark.getId(), is("Placemark-" + ID));
assertThat(placemark.getName(), is(TITLE));
assertThat(placemark.getTimePrimitive(), instanceOf(TimeSpan.class));
TimeSpan timeSpan = (TimeSpan) placemark.getTimePrimitive();
assertThat(timeSpan.getBegin(), is(dateFormat.format(metacard.getEffectiveDate())));
assertThat(placemark.getGeometry(), instanceOf(MultiGeometry.class));
MultiGeometry multiGeo = (MultiGeometry) placemark.getGeometry();
assertThat(multiGeo.getGeometry().size(), is(2));
assertThat(multiGeo.getGeometry().get(0), instanceOf(Point.class));
assertThat(multiGeo.getGeometry().get(1), instanceOf(LineString.class));
}
use of de.micromata.opengis.kml.v_2_2_0.TimeSpan in project ddf by codice.
the class KMLTransformerImplTest method testPerformDefaultTransformationMultiPolygonLocation.
@Test
public void testPerformDefaultTransformationMultiPolygonLocation() throws CatalogTransformerException {
MetacardImpl metacard = createMockMetacard();
metacard.setLocation(MULTIPOLYGON_WKT);
Placemark placemark = kmlTransformer.performDefaultTransformation(metacard);
assertThat(placemark.getId(), is("Placemark-" + ID));
assertThat(placemark.getName(), is(TITLE));
assertThat(placemark.getTimePrimitive(), instanceOf(TimeSpan.class));
TimeSpan timeSpan = (TimeSpan) placemark.getTimePrimitive();
assertThat(timeSpan.getBegin(), is(dateFormat.format(metacard.getEffectiveDate())));
assertThat(placemark.getGeometry(), instanceOf(MultiGeometry.class));
MultiGeometry multiGeo = (MultiGeometry) placemark.getGeometry();
assertThat(multiGeo.getGeometry().size(), is(2));
assertThat(multiGeo.getGeometry().get(0), instanceOf(Point.class));
assertThat(multiGeo.getGeometry().get(1), instanceOf(MultiGeometry.class));
MultiGeometry multiPolygon = (MultiGeometry) multiGeo.getGeometry().get(1);
assertThat(multiPolygon.getGeometry().size(), is(2));
assertThat(multiPolygon.getGeometry().get(0), instanceOf(Polygon.class));
assertThat(multiPolygon.getGeometry().get(1), instanceOf(Polygon.class));
}
Aggregations