Search in sources :

Example 11 with MultiPolygon

use of com.mapbox.geojson.MultiPolygon in project mapbox-java by mapbox.

the class TurfConversionTest method combinePolygonAndMultiPolygonToMultiPolygon.

@Test
public void combinePolygonAndMultiPolygonToMultiPolygon() throws Exception {
    FeatureCollection polygonFeatureCollection = FeatureCollection.fromFeatures(Arrays.asList(Feature.fromGeometry(Polygon.fromLngLats(Arrays.asList(Arrays.asList(Point.fromLngLat(61.938950426660604, 5.9765625), Point.fromLngLat(52.696361078274485, 33.046875), Point.fromLngLat(69.90011762668541, 28.828124999999996), Point.fromLngLat(61.938950426660604, 5.9765625))))), Feature.fromGeometry(MultiPolygon.fromPolygons(Arrays.asList(Polygon.fromLngLats(Arrays.asList(Arrays.asList(Point.fromLngLat(11.42578125, 16.636191878397664), Point.fromLngLat(7.91015625, -9.102096738726443), Point.fromLngLat(31.113281249999996, 17.644022027872726), Point.fromLngLat(11.42578125, 16.636191878397664)))), Polygon.fromLngLats(Arrays.asList(Arrays.asList(Point.fromLngLat(30.0, 0.0), Point.fromLngLat(102.0, 0.0), Point.fromLngLat(103.0, 1.0), Point.fromLngLat(30.0, 0.0)))))))));
    FeatureCollection combinedFeatureCollection = TurfConversion.combine(polygonFeatureCollection);
    assertNotNull(combinedFeatureCollection);
    MultiPolygon multiPolygon = (MultiPolygon) combinedFeatureCollection.features().get(0).geometry();
    assertNotNull(multiPolygon);
    // Checking the first Polygon in the MultiPolygon
    // Checking the first Point
    assertEquals(61.938950426660604, multiPolygon.coordinates().get(0).get(0).get(0).longitude(), DELTA);
    assertEquals(5.9765625, multiPolygon.coordinates().get(0).get(0).get(0).latitude(), DELTA);
    // Checking the second Point
    assertEquals(52.696361078274485, multiPolygon.coordinates().get(0).get(0).get(1).longitude(), DELTA);
    assertEquals(33.046875, multiPolygon.coordinates().get(0).get(0).get(1).latitude(), DELTA);
    // Checking the second Polygon in the MultiPolygon
    // Checking the first Point
    assertEquals(11.42578125, multiPolygon.coordinates().get(1).get(0).get(0).longitude(), DELTA);
    assertEquals(16.636191878397664, multiPolygon.coordinates().get(1).get(0).get(0).latitude(), DELTA);
    // Checking the second Point
    assertEquals(7.91015625, multiPolygon.coordinates().get(1).get(0).get(1).longitude(), DELTA);
    assertEquals(-9.102096738726443, multiPolygon.coordinates().get(1).get(0).get(1).latitude(), DELTA);
    // Checking the third Polygon in the MultiPolygon
    // Checking the first Point
    assertEquals(30.0, multiPolygon.coordinates().get(2).get(0).get(0).longitude(), DELTA);
    assertEquals(0.0, multiPolygon.coordinates().get(2).get(0).get(0).latitude(), DELTA);
    // Checking the second Point
    assertEquals(102.0, multiPolygon.coordinates().get(2).get(0).get(1).longitude(), DELTA);
    assertEquals(0.0, multiPolygon.coordinates().get(2).get(0).get(1).latitude(), DELTA);
}
Also used : FeatureCollection(com.mapbox.geojson.FeatureCollection) MultiPolygon(com.mapbox.geojson.MultiPolygon) Test(org.junit.Test)

Example 12 with MultiPolygon

use of com.mapbox.geojson.MultiPolygon in project mapbox-java by mapbox.

the class TurfJoinsTest method testMultipolygonWithHole.

@Test
public void testMultipolygonWithHole() throws TurfException, IOException {
    Point ptInHole = Point.fromLngLat(-86.69208526611328, 36.20373274711739);
    Point ptInPoly = Point.fromLngLat(-86.72229766845702, 36.20258997094334);
    Point ptInPoly2 = Point.fromLngLat(-86.75079345703125, 36.18527313913089);
    Point ptOutsidePoly = Point.fromLngLat(-86.75302505493164, 36.23015046460186);
    Feature multiPolyHole = Feature.fromJson(loadJsonFixture(MULTIPOLY_WITH_HOLE_FIXTURE));
    assertFalse(TurfJoins.inside(ptInHole, (MultiPolygon) multiPolyHole.geometry()));
    assertTrue(TurfJoins.inside(ptInPoly, (MultiPolygon) multiPolyHole.geometry()));
    assertTrue(TurfJoins.inside(ptInPoly2, (MultiPolygon) multiPolyHole.geometry()));
    assertFalse(TurfJoins.inside(ptOutsidePoly, (MultiPolygon) multiPolyHole.geometry()));
}
Also used : MultiPolygon(com.mapbox.geojson.MultiPolygon) Point(com.mapbox.geojson.Point) Feature(com.mapbox.geojson.Feature) Test(org.junit.Test)

Aggregations

MultiPolygon (com.mapbox.geojson.MultiPolygon)12 Test (org.junit.Test)10 Point (com.mapbox.geojson.Point)6 Feature (com.mapbox.geojson.Feature)5 FeatureCollection (com.mapbox.geojson.FeatureCollection)4 MultiPoint (com.mapbox.geojson.MultiPoint)4 Geometry (com.mapbox.geojson.Geometry)3 LineString (com.mapbox.geojson.LineString)3 MultiLineString (com.mapbox.geojson.MultiLineString)3 Polygon (com.mapbox.geojson.Polygon)3 ArrayList (java.util.ArrayList)3 BoundingBox (com.mapbox.geojson.BoundingBox)1 GeometryCollection (com.mapbox.geojson.GeometryCollection)1