Search in sources :

Example 1 with MultiLineString

use of ddf.geo.formatter.MultiLineString 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 2 with MultiLineString

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

the class GeoJsonMetacardTransformerTest 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 3 with MultiLineString

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

the class GeoJsonMetacardTransformerTest method testwithBadGeo.

/**
 * Tests that improper WKT throws an exception
 *
 * @throws CatalogTransformerException
 * @throws IOException
 * @throws ParseException
 */
@Test(expected = CatalogTransformerException.class)
public void testwithBadGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    String badWktMissingComma = "MULTILINESTRING ((10 10, 20 20, 10 40)(40 40, 30 30, 40 20, 30 10))";
    metacard.setLocation(badWktMissingComma);
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    transformer.transform(metacard, null);
}
Also used : LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 4 with MultiLineString

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

the class TestGeoJsonMetacardTransformer method testwithBadGeo.

/**
     * Tests that improper WKT throws an exception
     *
     * @throws CatalogTransformerException
     * @throws IOException
     * @throws ParseException
     */
@Test(expected = CatalogTransformerException.class)
public void testwithBadGeo() throws CatalogTransformerException, IOException, ParseException {
    Date now = new Date();
    MetacardImpl metacard = new MetacardImpl();
    String badWktMissingComma = "MULTILINESTRING ((10 10, 20 20, 10 40)(40 40, 30 30, 40 20, 30 10))";
    metacard.setLocation(badWktMissingComma);
    setupBasicMetacard(now, metacard);
    GeoJsonMetacardTransformer transformer = new GeoJsonMetacardTransformer();
    BinaryContent content = transformer.transform(metacard, null);
}
Also used : LineString(ddf.geo.formatter.LineString) MultiLineString(ddf.geo.formatter.MultiLineString) BinaryContent(ddf.catalog.data.BinaryContent) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

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