Search in sources :

Example 31 with Kml

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

the class KmlMarshallerTest method unmarshallNullStream.

@Test(expected = NoSuchElementException.class)
public void unmarshallNullStream() {
    final Kml kml = kmlMarshaller.unmarshal(null).get();
    final Feature feature = kml.getFeature();
    assertThat(feature.getName(), is("Simple placemark"));
}
Also used : Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Feature(de.micromata.opengis.kml.v_2_2_0.Feature) Test(org.junit.Test)

Example 32 with Kml

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

the class TestKmlEndpoint method testGetAvailableSources.

@Test
public void testGetAvailableSources() throws UnknownHostException, MalformedURLException, IllegalArgumentException, UriBuilderException, SourceUnavailableException {
    when(mockUriInfo.getQueryParameters(false)).thenReturn(mockMap);
    KmlEndpoint kmlEndpoint = new KmlEndpoint(mockBranding, mockFramework);
    Kml response = kmlEndpoint.getAvailableSources(mockUriInfo);
    assertThat(response, notNullValue());
    assertThat(response.getFeature(), instanceOf(Folder.class));
    Folder folder = (Folder) response.getFeature();
    assertThat(folder.getFeature(), notNullValue());
    assertThat(folder.getFeature().size(), is(2));
    assertThat(folder.getFeature().get(0), instanceOf(NetworkLink.class));
    assertThat(folder.getFeature().get(1), instanceOf(NetworkLink.class));
    NetworkLink nl1 = (NetworkLink) folder.getFeature().get(0);
    assertThat(nl1.getName(), anyOf(is(REMOTE_SITE_NAME), is(LOCAL_SITE_NAME)));
    NetworkLink nl2 = (NetworkLink) folder.getFeature().get(1);
    assertThat(nl2.getName(), anyOf(is(REMOTE_SITE_NAME), is(LOCAL_SITE_NAME)));
}
Also used : NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) Test(org.junit.Test)

Example 33 with Kml

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

the class KMLTransformerImpl method createKmlGeo.

private Geometry createKmlGeo(com.vividsolutions.jts.geom.Geometry geo) throws CatalogTransformerException {
    Geometry kmlGeo = null;
    if (Point.class.getSimpleName().equals(geo.getGeometryType())) {
        Point jtsPoint = (Point) geo;
        kmlGeo = KmlFactory.createPoint().addToCoordinates(jtsPoint.getX(), jtsPoint.getY());
    } else if (LineString.class.getSimpleName().equals(geo.getGeometryType())) {
        LineString jtsLS = (LineString) geo;
        de.micromata.opengis.kml.v_2_2_0.LineString kmlLS = KmlFactory.createLineString();
        List<Coordinate> kmlCoords = kmlLS.createAndSetCoordinates();
        for (com.vividsolutions.jts.geom.Coordinate coord : jtsLS.getCoordinates()) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
        kmlGeo = kmlLS;
    } else if (Polygon.class.getSimpleName().equals(geo.getGeometryType())) {
        Polygon jtsPoly = (Polygon) geo;
        de.micromata.opengis.kml.v_2_2_0.Polygon kmlPoly = KmlFactory.createPolygon();
        List<Coordinate> kmlCoords = kmlPoly.createAndSetOuterBoundaryIs().createAndSetLinearRing().createAndSetCoordinates();
        for (com.vividsolutions.jts.geom.Coordinate coord : jtsPoly.getCoordinates()) {
            kmlCoords.add(new Coordinate(coord.x, coord.y));
        }
        kmlGeo = kmlPoly;
    } else if (geo instanceof GeometryCollection) {
        List<Geometry> geos = new ArrayList<Geometry>();
        for (int xx = 0; xx < geo.getNumGeometries(); xx++) {
            geos.add(createKmlGeo(geo.getGeometryN(xx)));
        }
        kmlGeo = KmlFactory.createMultiGeometry().withGeometry(geos);
    } else {
        throw new CatalogTransformerException("Unknown / Unsupported Geometry Type '" + geo.getGeometryType() + "'. Unale to preform KML Transform.");
    }
    return kmlGeo;
}
Also used : CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Point(com.vividsolutions.jts.geom.Point) Geometry(de.micromata.opengis.kml.v_2_2_0.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) LineString(com.vividsolutions.jts.geom.LineString) Coordinate(de.micromata.opengis.kml.v_2_2_0.Coordinate) List(java.util.List) ArrayList(java.util.ArrayList) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 34 with Kml

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

the class TestKmlEndpoint method testGetAvailableSourcesVisibleByDefault.

@Test
public void testGetAvailableSourcesVisibleByDefault() throws UnknownHostException, MalformedURLException, IllegalArgumentException, UriBuilderException, SourceUnavailableException {
    when(mockUriInfo.getQueryParameters(false)).thenReturn(mockMap);
    KmlEndpoint kmlEndpoint = new KmlEndpoint(mockBranding, mockFramework);
    Kml response = kmlEndpoint.getAvailableSources(mockUriInfo);
    assertThat(response, notNullValue());
    assertThat(response.getFeature(), instanceOf(Folder.class));
    Folder folder = (Folder) response.getFeature();
    assertThat(folder.getFeature(), notNullValue());
    assertThat(folder.getFeature().size(), is(2));
    assertThat(folder.getFeature().get(0), instanceOf(NetworkLink.class));
    assertThat(folder.getFeature().get(1), instanceOf(NetworkLink.class));
    NetworkLink nl1 = (NetworkLink) folder.getFeature().get(0);
    assertThat(nl1.getName(), anyOf(is(REMOTE_SITE_NAME), is(LOCAL_SITE_NAME)));
    assertThat(nl1.isVisibility(), is(false));
    NetworkLink nl2 = (NetworkLink) folder.getFeature().get(1);
    assertThat(nl2.getName(), anyOf(is(REMOTE_SITE_NAME), is(LOCAL_SITE_NAME)));
    assertThat(nl2.isVisibility(), is(false));
}
Also used : NetworkLink(de.micromata.opengis.kml.v_2_2_0.NetworkLink) Kml(de.micromata.opengis.kml.v_2_2_0.Kml) Folder(de.micromata.opengis.kml.v_2_2_0.Folder) Test(org.junit.Test)

Example 35 with Kml

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

the class KMLTransformerImpl method encloseDoc.

/**
     * Encapsulate the kml content (placemarks, etc.) with a style in a KML Document element If
     * either content or style are null, they will be in the resulting Document
     *
     * @param kml
     * @param style
     * @param documentId
     *            which should be the metacard id
     * @return KML DocumentType element with style and content
     */
public static Document encloseDoc(Placemark placemark, Style style, String documentId, String docName) throws IllegalArgumentException {
    Document document = KmlFactory.createDocument();
    document.setId(documentId);
    document.setOpen(true);
    document.setName(docName);
    if (style != null) {
        document.getStyleSelector().add(style);
    }
    if (placemark != null) {
        document.getFeature().add(placemark);
    }
    return document;
}
Also used : Document(de.micromata.opengis.kml.v_2_2_0.Document)

Aggregations

Kml (de.micromata.opengis.kml.v_2_2_0.Kml)53 InputStream (java.io.InputStream)34 Test (org.junit.Test)31 Placemark (de.micromata.opengis.kml.v_2_2_0.Placemark)15 BeforeClass (org.junit.BeforeClass)13 NetworkLink (de.micromata.opengis.kml.v_2_2_0.NetworkLink)10 Folder (de.micromata.opengis.kml.v_2_2_0.Folder)9 Geometry (org.locationtech.jts.geom.Geometry)8 Document (de.micromata.opengis.kml.v_2_2_0.Document)7 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)6 Metacard (ddf.catalog.data.Metacard)4 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)4 LinearRing (de.micromata.opengis.kml.v_2_2_0.LinearRing)4 MultiGeometry (de.micromata.opengis.kml.v_2_2_0.MultiGeometry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 UriBuilder (javax.ws.rs.core.UriBuilder)4 Handlebars (com.github.jknack.handlebars.Handlebars)3 Template (com.github.jknack.handlebars.Template)3 Feature (de.micromata.opengis.kml.v_2_2_0.Feature)3