@Test public void testInvariantCollectionOf4() { String json = "{type: 'FeatureCollection', features: [{ type: 'Feature', geometry: { " + "type: 'Point', coordinates: [0, 0]}, properties: {}}]}"; TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Point", "myfn"); } }
@Test public void toJson() throws IOException { final String json = loadJsonFixture(SAMPLE_FEATURECOLLECTION_BBOX); FeatureCollection geo = FeatureCollection.fromJson(json); compareJson(json, geo.toJson()); } }
@Test public void testInvariantCollectionOf1() throws TurfException { String json = "{type: 'FeatureCollection', features: [{ type: 'Feature', geometry: { " + "type: 'Point', coordinates: [0, 0]}, properties: {}}]}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("Invalid input to myfn: must be a Polygon, given Point")); TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", "myfn"); }
@Test public void testInvariantCollectionOf3() throws TurfException { String json = "{type: 'FeatureCollection'}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("Invalid input to foo, FeatureCollection required")); TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", "foo"); }
@Test public void testInvariantCollectionOf2() throws TurfException { String json = "{type: 'FeatureCollection'}"; thrown.expect(TurfException.class); thrown.expectMessage(startsWith("collectionOf() requires a name")); TurfAssertions.collectionOf(FeatureCollection.fromJson(json), "Polygon", null); }
@Test @Ignore public void name() throws Exception { Feature feature = Feature.fromJson(loadJsonFixture(CIRCLE_IN)); Polygon polygon = TurfTransformation.circle((Point) feature.geometry(), feature.getNumberProperty("radius").doubleValue()); FeatureCollection featureCollection = FeatureCollection.fromJson(loadJsonFixture(CIRCLE_OUT)); compareJson(featureCollection.features().get(1).geometry().toJson(), polygon.toJson()); } }
@Test public void fromJson() throws IOException { final String json = loadJsonFixture(SAMPLE_FEATURECOLLECTION); FeatureCollection geo = FeatureCollection.fromJson(json); assertEquals(geo.type(), "FeatureCollection"); assertEquals(geo.features().size(), 3); assertEquals(geo.features().get(0).type(), "Feature"); assertEquals(geo.features().get(0).geometry().type(), "Point"); assertEquals(geo.features().get(1).type(), "Feature"); assertEquals(geo.features().get(1).geometry().type(), "LineString"); assertEquals(geo.features().get(2).type(), "Feature"); assertEquals(geo.features().get(2).geometry().type(), "Polygon"); }
@Test public void testLineDistanceWithGeometries() throws IOException, TurfException { Point pt = (Point) Feature.fromJson(loadJsonFixture(PT)).geometry(); FeatureCollection pts = FeatureCollection.fromJson(loadJsonFixture(PTS)); List<Point> pointList = new ArrayList<>(); for (Feature feature : pts.features()) { pointList.add((Point) (feature.geometry())); } Point closestPt = TurfClassification.nearestPoint(pt, pointList); Assert.assertNotNull(closestPt); Assert.assertEquals(closestPt.type(), "Point"); Assert.assertEquals(closestPt.longitude(), -75.33, DELTA); Assert.assertEquals(closestPt.latitude(), 39.44, DELTA); } }