use of com.mapbox.geojson.MultiLineString in project mapbox-java by mapbox.
the class TurfMeasurementTest method testLineDistanceMultiLineString.
@Test
public void testLineDistanceMultiLineString() throws IOException, TurfException {
Feature feature = Feature.fromJson(loadJsonFixture(LINE_DISTANCE_MULTILINESTRING));
assertEquals(4705d, Math.round(1000 * TurfMeasurement.length((MultiLineString) feature.geometry(), TurfConstants.UNIT_KILOMETERS)), DELTA);
}
use of com.mapbox.geojson.MultiLineString 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.MultiLineString in project mapbox-java by mapbox.
the class TurfConversionTest method combinePointAndLineStringGeometry.
@Test
public void combinePointAndLineStringGeometry() throws Exception {
FeatureCollection pointAndLineStringFeatureCollection = FeatureCollection.fromFeatures(Arrays.asList(Feature.fromGeometry(Point.fromLngLat(-2.46, 27.6835)), Feature.fromGeometry(LineString.fromLngLats(Arrays.asList(Point.fromLngLat(-11.25, 55.7765), Point.fromLngLat(41.1328, 22.91792))))));
FeatureCollection combinedFeatureCollection = TurfConversion.combine(pointAndLineStringFeatureCollection);
assertNotNull(combinedFeatureCollection);
MultiPoint multiPoint = null;
MultiLineString multiLineString = 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();
}
}
assertNotNull(multiPoint);
assertNotNull(multiLineString);
// 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.MultiLineString in project mapbox-java by mapbox.
the class TurfConversionTest method combineTwoLineStringsToMultiLineString.
@Test
public void combineTwoLineStringsToMultiLineString() throws Exception {
FeatureCollection lineStringFeatureCollection = FeatureCollection.fromFeatures(Arrays.asList(Feature.fromGeometry(LineString.fromLngLats(Arrays.asList(Point.fromLngLat(-11.25, 55.7765), Point.fromLngLat(41.1328, 22.91792)))), Feature.fromGeometry(LineString.fromLngLats(Arrays.asList(Point.fromLngLat(3.8671, 19.3111), Point.fromLngLat(20.742, -20.3034))))));
FeatureCollection featureCollectionWithNewMultiLineStringObject = TurfConversion.combine(lineStringFeatureCollection);
assertNotNull(featureCollectionWithNewMultiLineStringObject);
MultiLineString multiLineString = (MultiLineString) featureCollectionWithNewMultiLineStringObject.features().get(0).geometry();
assertNotNull(multiLineString);
// Checking the first LineString in the MultiLineString
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 in the MultiLineString
assertEquals(41.1328, multiLineString.coordinates().get(0).get(1).longitude(), DELTA);
assertEquals(22.91792, multiLineString.coordinates().get(0).get(1).latitude(), DELTA);
}
use of com.mapbox.geojson.MultiLineString in project mapbox-java by mapbox.
the class TurfConversionTest method combineLineStringAndMultiLineStringToMultiLineString.
@Test
public void combineLineStringAndMultiLineStringToMultiLineString() throws Exception {
FeatureCollection lineStringFeatureCollection = FeatureCollection.fromFeatures(Arrays.asList(Feature.fromGeometry(LineString.fromLngLats(Arrays.asList(Point.fromLngLat(-11.25, 55.7765), Point.fromLngLat(41.1328, 22.91792)))), Feature.fromGeometry(MultiLineString.fromLineStrings(Arrays.asList(LineString.fromLngLats(Arrays.asList(Point.fromLngLat(102, -10), Point.fromLngLat(130.0, 4.0))), LineString.fromLngLats(Arrays.asList(Point.fromLngLat(40.0, -20.0), Point.fromLngLat(150.0, 18.0))))))));
FeatureCollection featureCollectionWithNewMultiLineStringObject = TurfConversion.combine(lineStringFeatureCollection);
assertNotNull(featureCollectionWithNewMultiLineStringObject);
MultiLineString multiLineString = (MultiLineString) featureCollectionWithNewMultiLineStringObject.features().get(0).geometry();
assertNotNull(multiLineString);
// Checking the first LineString in the MultiLineString
assertEquals(-11.25, multiLineString.coordinates().get(0).get(0).longitude(), DELTA);
assertEquals(55.7765, multiLineString.coordinates().get(0).get(0).latitude(), DELTA);
assertEquals(41.1328, multiLineString.coordinates().get(0).get(1).longitude(), DELTA);
assertEquals(22.91792, multiLineString.coordinates().get(0).get(1).latitude(), DELTA);
// Checking the second LineString in the MultiLineString
assertEquals(102, multiLineString.coordinates().get(1).get(0).longitude(), DELTA);
assertEquals(-10, multiLineString.coordinates().get(1).get(0).latitude(), DELTA);
assertEquals(130.0, multiLineString.coordinates().get(1).get(1).longitude(), DELTA);
assertEquals(4.0, multiLineString.coordinates().get(1).get(1).latitude(), DELTA);
// Checking the third LineString in the MultiLineString
assertEquals(40.0, multiLineString.coordinates().get(2).get(0).longitude(), DELTA);
assertEquals(-20.0, multiLineString.coordinates().get(2).get(0).latitude(), DELTA);
assertEquals(150.0, multiLineString.coordinates().get(2).get(1).longitude(), DELTA);
assertEquals(18.0, multiLineString.coordinates().get(2).get(1).latitude(), DELTA);
}
Aggregations