|
1 | 1 | package com.mapbox.turf; |
2 | 2 |
|
| 3 | +import com.mapbox.geojson.Feature; |
| 4 | +import com.mapbox.geojson.FeatureCollection; |
| 5 | +import com.mapbox.geojson.GeometryCollection; |
| 6 | +import com.mapbox.geojson.LineString; |
| 7 | +import com.mapbox.geojson.MultiLineString; |
| 8 | +import com.mapbox.geojson.MultiPoint; |
| 9 | +import com.mapbox.geojson.MultiPolygon; |
| 10 | +import com.mapbox.geojson.Point; |
| 11 | +import com.mapbox.geojson.Polygon; |
| 12 | + |
3 | 13 | import org.junit.Rule; |
4 | 14 | import org.junit.Test; |
5 | 15 | import org.junit.rules.ExpectedException; |
6 | 16 |
|
| 17 | +import java.io.IOException; |
| 18 | +import java.util.Arrays; |
| 19 | + |
7 | 20 | import static org.junit.Assert.assertEquals; |
8 | 21 |
|
9 | 22 | public class TurfConversionTest extends TestUtils { |
10 | 23 |
|
| 24 | + private static final String TURF_EXPLODE_MULTI_POINT = "turf-explode/multipoint.geojson"; |
| 25 | + private static final String TURF_EXPLODE_LINESTRING = "turf-explode/linestring.geojson"; |
| 26 | + private static final String TURF_EXPLODE_MULTILINESTRING = "turf-explode/multilinestring.geojson"; |
| 27 | + private static final String TURF_EXPLODE_MULTIPOLYGON = "turf-explode/multipolygon.geojson"; |
| 28 | + private static final String TURF_EXPLODE_GEOMETRY_COLLECTION = "turf-explode/geometrycollection.geojson"; |
| 29 | + |
11 | 30 | @Rule |
12 | 31 | public ExpectedException thrown = ExpectedException.none(); |
13 | 32 |
|
@@ -58,4 +77,60 @@ public void convertDistance() throws TurfException { |
58 | 77 | TurfConversion.convertLength(1, TurfConstants.UNIT_METERS, |
59 | 78 | TurfConstants.UNIT_CENTIMETERS), DELTA); |
60 | 79 | } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void explodePointSingleFeature() throws IOException, NullPointerException { |
| 83 | + Point point = Point.fromLngLat(102, 0.5); |
| 84 | + assertEquals(1, TurfConversion.explode(Feature.fromGeometry(point)).features().size()); |
| 85 | + } |
| 86 | + |
| 87 | + @Test |
| 88 | + public void explodeMultiPointSingleFeature() throws IOException, NullPointerException { |
| 89 | + MultiPoint multiPoint = MultiPoint.fromJson(loadJsonFixture(TURF_EXPLODE_MULTI_POINT)); |
| 90 | + assertEquals(4, TurfConversion.explode(Feature.fromGeometry(multiPoint)).features().size()); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void explodeLineStringSingleFeature() throws IOException, NullPointerException { |
| 95 | + LineString lineString = LineString.fromJson(loadJsonFixture(TURF_EXPLODE_LINESTRING)); |
| 96 | + assertEquals(4, TurfConversion.explode(Feature.fromGeometry(lineString)).features().size()); |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + public void explodePolygonSingleFeature() throws IOException, NullPointerException { |
| 101 | + Polygon polygon = Polygon.fromLngLats(Arrays.asList( |
| 102 | + Arrays.asList( |
| 103 | + Point.fromLngLat(0, 101), |
| 104 | + Point.fromLngLat(1, 101), |
| 105 | + Point.fromLngLat(1, 100), |
| 106 | + Point.fromLngLat(0, 100)))); |
| 107 | + assertEquals(3, TurfConversion.explode(Feature.fromGeometry(polygon)).features().size()); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void explodeMultiLineStringSingleFeature() throws IOException, NullPointerException { |
| 112 | + MultiLineString multiLineString = MultiLineString.fromJson(loadJsonFixture(TURF_EXPLODE_MULTILINESTRING)); |
| 113 | + assertEquals(4, TurfConversion.explode(Feature.fromGeometry(multiLineString)).features().size()); |
| 114 | + } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void explodeMultiPolygonSingleFeature() throws IOException, NullPointerException { |
| 118 | + MultiPolygon multiPolygon = MultiPolygon.fromJson(loadJsonFixture(TURF_EXPLODE_MULTIPOLYGON)); |
| 119 | + assertEquals(12, TurfConversion.explode(Feature.fromGeometry(multiPolygon)).features().size()); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + public void explodeGeometryCollectionSingleFeature() throws IOException, NullPointerException { |
| 124 | + GeometryCollection geometryCollection = GeometryCollection.fromJson(loadJsonFixture(TURF_EXPLODE_GEOMETRY_COLLECTION)); |
| 125 | + assertEquals(3, TurfConversion.explode(Feature.fromGeometry(geometryCollection)).features().size()); |
| 126 | + } |
| 127 | + |
| 128 | + @Test |
| 129 | + public void explodeFeatureCollection() throws IOException, NullPointerException { |
| 130 | + FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[] { |
| 131 | + Feature.fromGeometry(MultiLineString.fromJson(loadJsonFixture(TURF_EXPLODE_MULTILINESTRING))), |
| 132 | + Feature.fromGeometry(MultiPolygon.fromJson(loadJsonFixture(TURF_EXPLODE_MULTIPOLYGON))) |
| 133 | + }); |
| 134 | + assertEquals(16, TurfConversion.explode(featureCollection).features().size()); |
| 135 | + } |
61 | 136 | } |
0 commit comments