Search in sources :

Example 26 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestGeoJsonMetacardTransformer method testwithPolygonGeoWithHole.

@Test
public void testwithPolygonGeoWithHole() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10),(20 30, 35 35, 30 20, 20 30))");
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    assertEquals(content.getMimeTypeValue(), GeoJsonMetacardTransformer.DEFAULT_MIME_TYPE.getBaseType());
    String jsonText = new String(content.getByteArray());
    LOGGER.debug(jsonText);
    Object object = PARSER.parse(jsonText);
    JSONObject obj2 = (JSONObject) object;
    Map geometryMap = (Map) obj2.get("geometry");
    assertThat(geometryMap.get(CompositeGeometry.TYPE_KEY).toString(), is(Polygon.TYPE));
    List<List> listOfRings = (List<List>) geometryMap.get(CompositeGeometry.COORDINATES_KEY);
    assertThat(listOfRings.size(), is(2));
    List<List> exteriorRing = listOfRings.get(0);
    List<List> interiorRing = listOfRings.get(1);
    testPopularPolygon(exteriorRing);
    List<Double> interiorlist1 = interiorRing.get(0);
    List<Double> interiorlist2 = interiorRing.get(1);
    List<Double> interiorlist3 = interiorRing.get(2);
    List<Double> interiorlist4 = interiorRing.get(3);
    assertThat(interiorlist1.get(0), equalTo(20.0));
    assertThat(interiorlist1.get(1), equalTo(30.0));
    assertThat(interiorlist2.get(0), equalTo(35.0));
    assertThat(interiorlist2.get(1), equalTo(35.0));
    assertThat(interiorlist3.get(0), equalTo(30.0));
    assertThat(interiorlist3.get(1), equalTo(20.0));
    assertThat(interiorlist4.get(0), equalTo(20.0));
    assertThat(interiorlist4.get(1), equalTo(30.0));
    verifyBasicMetacardJson(now, obj2);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) List(java.util.List) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 27 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestGeoJsonMetacardTransformer method testwithMultiPointGeo.

@Test
public void testwithMultiPointGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("MULTIPOINT ((30 10), (10 30), (40 40))");
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    assertEquals(content.getMimeTypeValue(), GeoJsonMetacardTransformer.DEFAULT_MIME_TYPE.getBaseType());
    String jsonText = new String(content.getByteArray());
    LOGGER.debug(jsonText);
    Object object = PARSER.parse(jsonText);
    JSONObject obj2 = (JSONObject) object;
    Map geometryMap = (Map) obj2.get("geometry");
    assertThat(geometryMap.get(CompositeGeometry.TYPE_KEY).toString(), is(MultiPoint.TYPE));
    List<List<Double>> coordsList = (List<List<Double>>) geometryMap.get(CompositeGeometry.COORDINATES_KEY);
    assertThat(coordsList.size(), is(3));
    for (List list : coordsList) {
        assertEquals(list.size(), 2);
    }
    assertThat(coordsList.get(0).get(0), equalTo(30.0));
    assertThat(coordsList.get(0).get(1), equalTo(10.0));
    assertThat(coordsList.get(1).get(0), equalTo(10.0));
    assertThat(coordsList.get(1).get(1), equalTo(30.0));
    assertThat(coordsList.get(2).get(0), equalTo(40.0));
    assertThat(coordsList.get(2).get(1), equalTo(40.0));
    verifyBasicMetacardJson(now, obj2);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) List(java.util.List) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 28 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestGeoJsonMetacardTransformer method testwithMultiLineStringGeo.

@Test
public void testwithMultiLineStringGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))");
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    assertEquals(content.getMimeTypeValue(), GeoJsonMetacardTransformer.DEFAULT_MIME_TYPE.getBaseType());
    String jsonText = new String(content.getByteArray());
    LOGGER.debug(jsonText);
    Object object = PARSER.parse(jsonText);
    JSONObject obj2 = (JSONObject) object;
    Map geometryMap = (Map) obj2.get("geometry");
    assertThat(geometryMap.get(CompositeGeometry.TYPE_KEY).toString(), is(MultiLineString.TYPE));
    List<List<List<Double>>> coordsList = (List<List<List<Double>>>) geometryMap.get(CompositeGeometry.COORDINATES_KEY);
    assertThat(coordsList.size(), is(2));
    List<List<Double>> list1 = coordsList.get(0);
    List<List<Double>> list2 = coordsList.get(1);
    assertThat(list1.get(0).get(0), equalTo(10.0));
    assertThat(list1.get(0).get(1), equalTo(10.0));
    assertThat(list1.get(1).get(0), equalTo(20.0));
    assertThat(list1.get(1).get(1), equalTo(20.0));
    assertThat(list1.get(2).get(0), equalTo(10.0));
    assertThat(list1.get(2).get(1), equalTo(40.0));
    assertThat(list2.get(0).get(0), equalTo(40.0));
    assertThat(list2.get(0).get(1), equalTo(40.0));
    assertThat(list2.get(1).get(0), equalTo(30.0));
    assertThat(list2.get(1).get(1), equalTo(30.0));
    assertThat(list2.get(2).get(0), equalTo(40.0));
    assertThat(list2.get(2).get(1), equalTo(20.0));
    assertThat(list2.get(3).get(0), equalTo(30.0));
    assertThat(list2.get(3).get(1), equalTo(10.0));
    verifyBasicMetacardJson(now, obj2);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) List(java.util.List) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 29 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestGeoJsonMetacardTransformer method testwithPointGeo.

/**
     * Tests that a POINT Geography can be returned in JSON
     *
     * @throws CatalogTransformerException
     * @throws IOException
     * @throws ParseException
     */
@Test
public void testwithPointGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation(DEFAULT_LOCATION);
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    assertEquals(content.getMimeTypeValue(), GeoJsonMetacardTransformer.DEFAULT_MIME_TYPE.getBaseType());
    String jsonText = new String(content.getByteArray());
    LOGGER.debug(jsonText);
    Object object = PARSER.parse(jsonText);
    JSONObject obj2 = (JSONObject) object;
    Map geometryMap = (Map) obj2.get("geometry");
    assertThat(geometryMap.get(CompositeGeometry.TYPE_KEY).toString(), is(Point.TYPE));
    List<Double> coords = (List<Double>) geometryMap.get(CompositeGeometry.COORDINATES_KEY);
    assertThat(coords.size(), is(2));
    assertThat(coords.get(0), equalTo(1.0));
    assertThat(coords.get(1), equalTo(0.0));
    verifyBasicMetacardJson(now, obj2);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) List(java.util.List) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 30 with BinaryContent

use of ddf.catalog.data.BinaryContent in project ddf by codice.

the class TestGeoJsonMetacardTransformer method testWithGeometryCollection.

@Test
public void testWithGeometryCollection() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10))");
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
    assertEquals(content.getMimeTypeValue(), GeoJsonMetacardTransformer.DEFAULT_MIME_TYPE.getBaseType());
    String jsonText = new String(content.getByteArray());
    LOGGER.debug(jsonText);
    Object object = PARSER.parse(jsonText);
    JSONObject obj2 = (JSONObject) object;
    Map geometryMap = (Map) obj2.get("geometry");
    assertThat(geometryMap.get(CompositeGeometry.TYPE_KEY).toString(), is(GeometryCollection.TYPE));
    assertThat(geometryMap.get(CompositeGeometry.GEOMETRIES_KEY), notNullValue());
    verifyBasicMetacardJson(now, obj2);
}
Also used : JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Map(java.util.Map) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)214 Test (org.junit.Test)164 Metacard (ddf.catalog.data.Metacard)87 SourceResponse (ddf.catalog.operation.SourceResponse)78 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)51 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)44 HashMap (java.util.HashMap)42 Result (ddf.catalog.data.Result)41 Map (java.util.Map)39 Serializable (java.io.Serializable)33 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)27 ResultImpl (ddf.catalog.data.impl.ResultImpl)26 LineString (ddf.geo.formatter.LineString)21 MultiLineString (ddf.geo.formatter.MultiLineString)21 Date (java.util.Date)21 File (java.io.File)20 JSONObject (org.json.simple.JSONObject)20 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)19 FileOutputStream (java.io.FileOutputStream)18 ByteArrayInputStream (java.io.ByteArrayInputStream)17