use of com.mapbox.geojson.MultiPolygon in project mapbox-java by mapbox.
the class TurfMeasurementTest method bboxPolygonFromMultiPolygon.
@Test
public void bboxPolygonFromMultiPolygon() throws IOException, TurfException {
// Create a MultiPolygon
MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_BBOX_POLYGON_MULTIPOLYGON));
// Use the MultiPolygon object to calculate its BoundingBox area
double[] bbox = TurfMeasurement.bbox(multiPolygon);
// Use the BoundingBox coordinates to create an actual BoundingBox object
BoundingBox boundingBox = BoundingBox.fromPoints(Point.fromLngLat(bbox[0], bbox[1]), Point.fromLngLat(bbox[2], bbox[3]));
// Use the BoundingBox object in the TurfMeasurement.bboxPolygon() method.
Feature featureRepresentingBoundingBox = TurfMeasurement.bboxPolygon(boundingBox);
Polygon polygonRepresentingBoundingBox = (Polygon) featureRepresentingBoundingBox.geometry();
assertNotNull(polygonRepresentingBoundingBox);
assertEquals(0, polygonRepresentingBoundingBox.inner().size());
assertEquals(5, polygonRepresentingBoundingBox.coordinates().get(0).size());
assertEquals(Point.fromLngLat(100, 0.0), polygonRepresentingBoundingBox.coordinates().get(0).get(4));
}
use of com.mapbox.geojson.MultiPolygon in project mapbox-java by mapbox.
the class TurfConversionTest method combinePointAndMultiPolygonAndLineStringGeometry.
@Test
public void combinePointAndMultiPolygonAndLineStringGeometry() throws Exception {
FeatureCollection pointMultiPolygonAndLineStringFeatureCollection = FeatureCollection.fromFeatures(Arrays.asList(Feature.fromGeometry(Point.fromLngLat(-2.46, 27.6835)), 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))))))), Feature.fromGeometry(LineString.fromLngLats(Arrays.asList(Point.fromLngLat(-11.25, 55.7765), Point.fromLngLat(41.1328, 22.91792))))));
FeatureCollection combinedFeatureCollection = TurfConversion.combine(pointMultiPolygonAndLineStringFeatureCollection);
assertNotNull(combinedFeatureCollection);
MultiPoint multiPoint = null;
MultiLineString multiLineString = null;
MultiPolygon multiPolygon = null;
for (int x = 0; x < combinedFeatureCollection.features().size(); x++) {
Feature singleFeature = combinedFeatureCollection.features().get(x);
if (singleFeature.geometry() instanceof MultiPoint) {
multiPoint = (MultiPoint) combinedFeatureCollection.features().get(x).geometry();
}
if (singleFeature.geometry() instanceof MultiLineString) {
multiLineString = (MultiLineString) combinedFeatureCollection.features().get(x).geometry();
}
if (singleFeature.geometry() instanceof MultiPolygon) {
multiPolygon = (MultiPolygon) combinedFeatureCollection.features().get(x).geometry();
}
}
assertNotNull(multiPoint);
assertNotNull(multiLineString);
assertNotNull(multiPolygon);
// Checking the Polygon in the MultiPolygon
// Checking the first Point
assertEquals(11.42578125, multiPolygon.coordinates().get(0).get(0).get(0).longitude(), DELTA);
assertEquals(16.636191878397664, multiPolygon.coordinates().get(0).get(0).get(0).latitude(), DELTA);
// Checking the second Point
assertEquals(7.91015625, multiPolygon.coordinates().get(0).get(0).get(1).longitude(), DELTA);
assertEquals(-9.102096738726443, multiPolygon.coordinates().get(0).get(0).get(1).latitude(), DELTA);
// Checking the LineString in the MultiLineString
// Checking the first LineString location
assertEquals(-11.25, multiLineString.coordinates().get(0).get(0).longitude(), DELTA);
assertEquals(55.7765, multiLineString.coordinates().get(0).get(0).latitude(), DELTA);
// Checking the second LineString location
assertEquals(41.1328, multiLineString.coordinates().get(0).get(1).longitude(), DELTA);
assertEquals(22.91792, multiLineString.coordinates().get(0).get(1).latitude(), DELTA);
// Checking the Point in the MultiPoint
// Checking the first and only Point
assertEquals(-2.46, multiPoint.coordinates().get(0).longitude(), DELTA);
assertEquals(27.6835, multiPoint.coordinates().get(0).latitude(), DELTA);
}
use of com.mapbox.geojson.MultiPolygon in project mapbox-java by mapbox.
the class TurfConversionTest method explodeMultiPolygonSingleFeature.
@Test
public void explodeMultiPolygonSingleFeature() throws NullPointerException {
MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_EXPLODE_MULTIPOLYGON));
assertEquals(12, TurfConversion.explode(Feature.fromGeometry(multiPolygon)).features().size());
}
use of com.mapbox.geojson.MultiPolygon in project mapbox-java by mapbox.
the class TurfConversionTest method combinePolygonToMultiPolygon.
@Test
public void combinePolygonToMultiPolygon() 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(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)))))));
FeatureCollection featureCollectionWithNewMultiPolygonObject = TurfConversion.combine(polygonFeatureCollection);
assertNotNull(featureCollectionWithNewMultiPolygonObject);
MultiPolygon multiPolygon = (MultiPolygon) featureCollectionWithNewMultiPolygonObject.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);
}
use of com.mapbox.geojson.MultiPolygon in project mapbox-java by mapbox.
the class TurfConversionTest method combinePolygonAndMultiPolygonAndPointToMultiPolygon.
@Test
public void combinePolygonAndMultiPolygonAndPointToMultiPolygon() throws Exception {
FeatureCollection featureCollectionWithPointPolygonAndMultiPolygon = FeatureCollection.fromFeatures(Arrays.asList(Feature.fromGeometry(Point.fromLngLat(-2.46, 27.6835)), 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(featureCollectionWithPointPolygonAndMultiPolygon);
assertNotNull(combinedFeatureCollection);
MultiPolygon multiPolygon = null;
MultiPoint multiPoint = null;
for (int x = 0; x < combinedFeatureCollection.features().size(); x++) {
Feature singleFeature = combinedFeatureCollection.features().get(x);
if (singleFeature.geometry() instanceof MultiPolygon) {
multiPolygon = (MultiPolygon) combinedFeatureCollection.features().get(x).geometry();
}
if (singleFeature.geometry() instanceof MultiPoint) {
multiPoint = (MultiPoint) combinedFeatureCollection.features().get(x).geometry();
}
}
assertNotNull(multiPolygon);
assertNotNull(multiPoint);
// 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);
}
Aggregations