Search in sources :

Example 6 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class KMLTransformerImpl method setExtendedData.

private void setExtendedData(Placemark placemark, Metacard metacard) {
    final ExtendedData extendedData = new ExtendedData();
    final Set<AttributeDescriptor> attributeDescriptors = metacard.getMetacardType().getAttributeDescriptors();
    for (AttributeDescriptor attributeDescriptor : attributeDescriptors) {
        final String attributeName = attributeDescriptor.getName();
        final Attribute attribute = metacard.getAttribute(attributeName);
        if (attribute != null) {
            Serializable attributeValue = convertAttribute(attribute, attributeDescriptor);
            if (attributeValue == null) {
                LOGGER.debug("Attribute {} converted to null value.", attributeName);
            } else {
                final Data data = getData(attributeName, attributeValue.toString());
                extendedData.addToData(data);
            }
        }
    }
    placemark.setExtendedData(extendedData);
}
Also used : Serializable(java.io.Serializable) ExtendedData(de.micromata.opengis.kml.v_2_2_0.ExtendedData) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Data(de.micromata.opengis.kml.v_2_2_0.Data) ExtendedData(de.micromata.opengis.kml.v_2_2_0.ExtendedData)

Example 7 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark 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));
}
Also used : TimeSpan(de.micromata.opengis.kml.v_2_2_0.TimeSpan) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) Point(de.micromata.opengis.kml.v_2_2_0.Point) Polygon(de.micromata.opengis.kml.v_2_2_0.Polygon) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 8 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class KMLTransformerImplTest method testPerformDefaultTransformationExtendedData.

@Test
public void testPerformDefaultTransformationExtendedData() throws CatalogTransformerException, DateTimeParseException {
    MetacardImpl metacard = createMockMetacard();
    metacard.setLocation(POINT_WKT);
    metacard.setCreatedDate(metacardDate);
    metacard.setEffectiveDate(metacardDate);
    metacard.setExpirationDate(metacardDate);
    metacard.setModifiedDate(metacardDate);
    metacard.setTags(METACARD_TAGS);
    final Set<AttributeDescriptor> attributeDescriptors = metacard.getMetacardType().getAttributeDescriptors();
    Placemark placemark = kmlTransformer.performDefaultTransformation(metacard);
    final List<Data> dataList = placemark.getExtendedData().getData();
    int dataCount = 0;
    for (AttributeDescriptor attributeDescriptor : attributeDescriptors) {
        final String attributeName = attributeDescriptor.getName();
        final Attribute attribute = metacard.getAttribute(attributeName);
        if (attribute != null) {
            dataCount++;
        }
    }
    assertThat(dataList.size(), is(dataCount));
    for (Data data : dataList) {
        switch(data.getName()) {
            case Core.ID:
                assertThat(data.getValue(), is(METACARD_ID));
                break;
            case Core.TITLE:
                assertThat(data.getValue(), is(METACARD_TITLE));
                break;
            case Core.LOCATION:
                assertThat(data.getValue(), is(POINT_WKT));
                break;
            case Metacard.CONTENT_TYPE:
                assertThat(data.getValue(), is(METACARD_TYPE));
                break;
            case Metacard.CONTENT_TYPE_VERSION:
                assertThat(data.getValue(), is(METACARD_VERSION));
                break;
            case Core.METADATA:
                assertThat(data.getValue(), is(METACARD_METADATA));
                break;
            case Core.METACARD_TAGS:
                assertThat(data.getValue(), is(METACARD_TAGS.asList().get(0) + "," + METACARD_TAGS.asList().get(1)));
                break;
            case Core.MODIFIED:
            case Metacard.EFFECTIVE:
            case Core.EXPIRATION:
            case Core.CREATED:
                assertThat(data.getValue(), is(METACARD_DATE_STRING));
                break;
            default:
                throw new IllegalArgumentException(String.format("Data %s was not expected", data.getName()));
        }
    }
}
Also used : Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Data(de.micromata.opengis.kml.v_2_2_0.Data) LineString(de.micromata.opengis.kml.v_2_2_0.LineString) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Point(de.micromata.opengis.kml.v_2_2_0.Point) Test(org.junit.Test)

Example 9 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class KmlFeatureToJtsGeometryConverterTest method testConvertKmlPlaceMarkFeature.

@Test
public void testConvertKmlPlaceMarkFeature() {
    InputStream stream = KmlFeatureToJtsGeometryConverterTest.class.getResourceAsStream("/kmlPoint.kml");
    Kml kml = Kml.unmarshal(stream);
    assertThat(kml, notNullValue());
    Placemark kmlPlacemark = (Placemark) kml.getFeature();
    assertThat(kmlPlacemark, notNullValue());
    Geometry geometry = KmlFeatureToJtsGeometryConverter.from(kmlPlacemark);
    assertThat(geometry, notNullValue());
    assertFeature(kmlPlacemark, geometry);
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Placemark(de.micromata.opengis.kml.v_2_2_0.Placemark) InputStream(java.io.InputStream) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Test(org.junit.Test)

Example 10 with Placemark

use of de.micromata.opengis.kml.v_2_2_0.Placemark in project ddf by codice.

the class KmlToJtsMultiGeometryConverterTest method setupClass.

@BeforeClass
public static void setupClass() {
    InputStream stream = KmlToJtsMultiGeometryConverterTest.class.getResourceAsStream("/kmlMultiGeometry.kml");
    Kml kml = Kml.unmarshal(stream);
    testKmlMultiGeometry = ((MultiGeometry) ((Placemark) kml.getFeature()).getGeometry());
}
Also used : InputStream(java.io.InputStream) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) MultiGeometry(de.micromata.opengis.kml.v_2_2_0.MultiGeometry) BeforeClass(org.junit.BeforeClass)

Aggregations

Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)35 Test (org.junit.Test)29 Kml (de.micromata.opengis.kml.v_2_2_0.Kml)23 InputStream (java.io.InputStream)20 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)19 Point (de.micromata.opengis.kml.v_2_2_0.Point)19 TimeSpan (de.micromata.opengis.kml.v_2_2_0.TimeSpan)16 MultiGeometry (de.micromata.opengis.kml.v_2_2_0.MultiGeometry)15 LineString (de.micromata.opengis.kml.v_2_2_0.LineString)12 Polygon (de.micromata.opengis.kml.v_2_2_0.Polygon)10 BeforeClass (org.junit.BeforeClass)8 LinearRing (de.micromata.opengis.kml.v_2_2_0.LinearRing)5 Document (de.micromata.opengis.kml.v_2_2_0.Document)4 Feature (de.micromata.opengis.kml.v_2_2_0.Feature)4 Style (de.micromata.opengis.kml.v_2_2_0.Style)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 ProfilePlacemark (se.trixon.mapollage.profile.ProfilePlacemark)4 BalloonStyle (de.micromata.opengis.kml.v_2_2_0.BalloonStyle)3 IconStyle (de.micromata.opengis.kml.v_2_2_0.IconStyle)3