Search in sources :

Example 1 with LineString

use of ddf.geo.formatter.LineString 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)

Example 2 with LineString

use of ddf.geo.formatter.LineString in project ddf by codice.

the class TestGeoJsonMetacardTransformer method testwithLineStringGeo.

/**
     * Tests that a LineString Geography can be returned in JSON
     *
     * @throws CatalogTransformerException
     * @throws IOException
     * @throws ParseException
     */
@Test
public void testwithLineStringGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("LINESTRING (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(LineString.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)

Aggregations

BinaryContent (ddf.catalog.data.BinaryContent)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 LineString (ddf.geo.formatter.LineString)2 MultiLineString (ddf.geo.formatter.MultiLineString)2 Date (java.util.Date)2 Map (java.util.Map)2 JSONObject (org.json.simple.JSONObject)2 Test (org.junit.Test)2 List (java.util.List)1