GeoJsonReader { @Nullable public Feature readFeature(@Nullable final String json) { if (TextUtils.isEmpty(json)) { return null; } try { return readFeature(new StringReader(json)); } catch (IOException ioe) { Log.w(TAG, ioe.getMessage()); } return null; } GeoJsonReader(); @Nullable Feature readFeature(@Nullable final String json); @NonNull Feature readFeature(@NonNull final Reader in); @Nullable FeatureCollection readFeatureCollection(@Nullable final String json); @NonNull FeatureCollection readFeatureCollection(@NonNull final Reader in); @Nullable Geometry readGeometry(@Nullable final String json); @NonNull Geometry readGeometry(@NonNull final Reader in); @NonNull Feature readFeature(@NonNull final JsonReader reader);  }
@Test public void testReadFeatureFromJsonString() throws Exception { final String json = TestHelper.getFixture("feature_point.json"); final Feature feature = geoJsonReader.readFeature(json); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createPoint(gf, 47.2256258d, -1.5545135d), feature.getGeometry()); }
@Test public void testReadFeatureFromInvalidJsonString() throws Exception { final Feature feature = geoJsonReader.readFeature(""); assertNull(feature); }
@Test public void testReadFeatureAsPoint() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_point.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createPoint(gf, 47.2256258d, -1.5545135d), feature.getGeometry()); }
@Test public void testReadFeatureAsMultiPoint() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_multipoint.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createMultiPoint(gf, createPoint(gf, 47.2256258d, -1.5545135d), createPoint(gf, 47.225136d, -1.553913d)), feature.getGeometry()); }
@Test public void testReadFeatureAsLineString() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_linestring.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d)), feature.getGeometry()); }
@Test public void testReadFeatureAsMultiLineString() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_multilinestring.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createMultiLineString(gf, createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d))), feature.getGeometry()); }
@Test public void testReadFeatureAsSimplePolygon() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_polygon_simple.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createPolygon(gf, createCoordinate(gf, 47.226219d, -1.554430d), createCoordinate(gf, 47.226237d, -1.554261d), createCoordinate(gf, 47.226122d, -1.554245d), createCoordinate(gf, 47.226106d, -1.554411d), createCoordinate(gf, 47.226219d, -1.554430d)), feature.getGeometry()); }
@Test public void testReadFeatureAsPolygonWithHoles() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_polygon_holes.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createPolygon(gf, createLinearRing(gf, createCoordinate(gf, 47.226257d, -1.554564d), createCoordinate(gf, 47.226295d, -1.554202d), createCoordinate(gf, 47.226075d, -1.554169d), createCoordinate(gf, 47.226049d, -1.554496d), createCoordinate(gf, 47.226257d, -1.554564d)), createLinearRing(gf, createCoordinate(gf, 47.226219d, -1.554430d), createCoordinate(gf, 47.226237d, -1.554261d), createCoordinate(gf, 47.226122d, -1.554245d), createCoordinate(gf, 47.226106d, -1.554411d), createCoordinate(gf, 47.226219d, -1.554430d))), feature.getGeometry()); }
@Test public void testReadFeatureAsMultiPolygon() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_multipolygon.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createMultiPolygon(gf, createPolygon(gf, createCoordinate(gf, 47.226116d, -1.554169d), createCoordinate(gf, 47.226126d, -1.554097d), createCoordinate(gf, 47.225527d, -1.553986d), createCoordinate(gf, 47.225519d, -1.554061d), createCoordinate(gf, 47.226116d, -1.554169d)), createPolygon(gf, createLinearRing(gf, createCoordinate(gf, 47.226257d, -1.554564d), createCoordinate(gf, 47.226295d, -1.554202d), createCoordinate(gf, 47.226075d, -1.554169d), createCoordinate(gf, 47.226049d, -1.554496d), createCoordinate(gf, 47.226257d, -1.554564d)), createLinearRing(gf, createCoordinate(gf, 47.226219d, -1.554430d), createCoordinate(gf, 47.226237d, -1.554261d), createCoordinate(gf, 47.226122d, -1.554245d), createCoordinate(gf, 47.226106d, -1.554411d), createCoordinate(gf, 47.226219d, -1.554430d)))), feature.getGeometry()); }
@Test public void testReadFeatureAsGeometryCollection() throws Exception { final StringReader reader = new StringReader(TestHelper.getFixture("feature_geometrycollection.json")); final Feature feature = geoJsonReader.readFeature(reader); assertNotNull(feature); assertEquals("id1", feature.getId()); assertEquals("Feature", feature.getType()); assertNotNull(feature.getGeometry()); assertEquals(createGeometryCollection(gf, createPoint(gf, 47.2256258d, -1.5545135d), createMultiPoint(gf, createPoint(gf, 47.2256258d, -1.5545135d), createPoint(gf, 47.225136d, -1.553913d)), createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d)), createMultiLineString(gf, createLineString(gf, createCoordinate(gf, 47.2256258d, -1.5545135d), createCoordinate(gf, 47.225136d, -1.553913d))), createPolygon(gf, createCoordinate(gf, 47.226219d, -1.554430d), createCoordinate(gf, 47.226237d, -1.554261d), createCoordinate(gf, 47.226122d, -1.554245d), createCoordinate(gf, 47.226106d, -1.554411d), createCoordinate(gf, 47.226219d, -1.554430d))), feature.getGeometry()); }