@Test public void combine_featureCollectionSizeCheck() 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); assertEquals(3, combinedFeatureCollection.features().size()); }
public static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection) { if (originalFeatureCollection.features() == null) { throw new TurfException("Your FeatureCollection is null."); } else if (originalFeatureCollection.features().size() == 0) { throw new TurfException("Your FeatureCollection doesn't have any Feature objects in it."); } List<Point> pointList = new ArrayList<>(0); List<LineString> lineStringList = new ArrayList<>(0); List<Polygon> polygonList = new ArrayList<>(0); for (Feature singleFeature : originalFeatureCollection.features()) { Geometry singleFeatureGeometry = singleFeature.geometry(); if (singleFeatureGeometry instanceof Point || singleFeatureGeometry instanceof MultiPoint) { if (singleFeatureGeometry instanceof Point) { pointList.add((Point) singleFeatureGeometry); } else { pointList.addAll(((MultiPoint) singleFeatureGeometry).coordinates()); } } else if (singleFeatureGeometry instanceof LineString || singleFeatureGeometry instanceof MultiLineString) { if (singleFeatureGeometry instanceof LineString) { lineStringList.add((LineString) singleFeatureGeometry); } else { lineStringList.addAll(((MultiLineString) singleFeatureGeometry).lineStrings()); } } else if (singleFeatureGeometry instanceof Polygon || singleFeatureGeometry instanceof MultiPolygon) { if (singleFeatureGeometry instanceof Polygon) { polygonList.add((Polygon) singleFeatureGeometry); } else { polygonList.addAll(((MultiPolygon) singleFeatureGeometry).polygons()); } } } List<Feature> finalFeatureList = new ArrayList<>(0); if (!pointList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPoint.fromLngLats(pointList))); } if (!lineStringList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiLineString.fromLineStrings(lineStringList))); } if (!polygonList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPolygon.fromPolygons(polygonList))); } return finalFeatureList.isEmpty() ? originalFeatureCollection : FeatureCollection.fromFeatures(finalFeatureList); }
TurfConversion { public static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection) { if (originalFeatureCollection.features() == null) { throw new TurfException("Your FeatureCollection is null."); } else if (originalFeatureCollection.features().size() == 0) { throw new TurfException("Your FeatureCollection doesn't have any Feature objects in it."); } List<Point> pointList = new ArrayList<>(0); List<LineString> lineStringList = new ArrayList<>(0); List<Polygon> polygonList = new ArrayList<>(0); for (Feature singleFeature : originalFeatureCollection.features()) { Geometry singleFeatureGeometry = singleFeature.geometry(); if (singleFeatureGeometry instanceof Point || singleFeatureGeometry instanceof MultiPoint) { if (singleFeatureGeometry instanceof Point) { pointList.add((Point) singleFeatureGeometry); } else { pointList.addAll(((MultiPoint) singleFeatureGeometry).coordinates()); } } else if (singleFeatureGeometry instanceof LineString || singleFeatureGeometry instanceof MultiLineString) { if (singleFeatureGeometry instanceof LineString) { lineStringList.add((LineString) singleFeatureGeometry); } else { lineStringList.addAll(((MultiLineString) singleFeatureGeometry).lineStrings()); } } else if (singleFeatureGeometry instanceof Polygon || singleFeatureGeometry instanceof MultiPolygon) { if (singleFeatureGeometry instanceof Polygon) { polygonList.add((Polygon) singleFeatureGeometry); } else { polygonList.addAll(((MultiPolygon) singleFeatureGeometry).polygons()); } } } List<Feature> finalFeatureList = new ArrayList<>(0); if (!pointList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPoint.fromLngLats(pointList))); } if (!lineStringList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiLineString.fromLineStrings(lineStringList))); } if (!polygonList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPolygon.fromPolygons(polygonList))); } return finalFeatureList.isEmpty() ? originalFeatureCollection : FeatureCollection.fromFeatures(finalFeatureList); } }
TurfConversion { public static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection) { if (originalFeatureCollection.features() == null) { throw new TurfException("Your FeatureCollection is null."); } else if (originalFeatureCollection.features().size() == 0) { throw new TurfException("Your FeatureCollection doesn't have any Feature objects in it."); } List<Point> pointList = new ArrayList<>(0); List<LineString> lineStringList = new ArrayList<>(0); List<Polygon> polygonList = new ArrayList<>(0); for (Feature singleFeature : originalFeatureCollection.features()) { Geometry singleFeatureGeometry = singleFeature.geometry(); if (singleFeatureGeometry instanceof Point || singleFeatureGeometry instanceof MultiPoint) { if (singleFeatureGeometry instanceof Point) { pointList.add((Point) singleFeatureGeometry); } else { pointList.addAll(((MultiPoint) singleFeatureGeometry).coordinates()); } } else if (singleFeatureGeometry instanceof LineString || singleFeatureGeometry instanceof MultiLineString) { if (singleFeatureGeometry instanceof LineString) { lineStringList.add((LineString) singleFeatureGeometry); } else { lineStringList.addAll(((MultiLineString) singleFeatureGeometry).lineStrings()); } } else if (singleFeatureGeometry instanceof Polygon || singleFeatureGeometry instanceof MultiPolygon) { if (singleFeatureGeometry instanceof Polygon) { polygonList.add((Polygon) singleFeatureGeometry); } else { polygonList.addAll(((MultiPolygon) singleFeatureGeometry).polygons()); } } } List<Feature> finalFeatureList = new ArrayList<>(0); if (!pointList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPoint.fromLngLats(pointList))); } if (!lineStringList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiLineString.fromLineStrings(lineStringList))); } if (!polygonList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPolygon.fromPolygons(polygonList))); } return finalFeatureList.isEmpty() ? originalFeatureCollection : FeatureCollection.fromFeatures(finalFeatureList); } private  TurfConversion(); }
TurfConversion { public static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection) { if (originalFeatureCollection.features() == null) { throw new TurfException("Your FeatureCollection is null."); } else if (originalFeatureCollection.features().size() == 0) { throw new TurfException("Your FeatureCollection doesn't have any Feature objects in it."); } List<Point> pointList = new ArrayList<>(0); List<LineString> lineStringList = new ArrayList<>(0); List<Polygon> polygonList = new ArrayList<>(0); for (Feature singleFeature : originalFeatureCollection.features()) { Geometry singleFeatureGeometry = singleFeature.geometry(); if (singleFeatureGeometry instanceof Point || singleFeatureGeometry instanceof MultiPoint) { if (singleFeatureGeometry instanceof Point) { pointList.add((Point) singleFeatureGeometry); } else { pointList.addAll(((MultiPoint) singleFeatureGeometry).coordinates()); } } else if (singleFeatureGeometry instanceof LineString || singleFeatureGeometry instanceof MultiLineString) { if (singleFeatureGeometry instanceof LineString) { lineStringList.add((LineString) singleFeatureGeometry); } else { lineStringList.addAll(((MultiLineString) singleFeatureGeometry).lineStrings()); } } else if (singleFeatureGeometry instanceof Polygon || singleFeatureGeometry instanceof MultiPolygon) { if (singleFeatureGeometry instanceof Polygon) { polygonList.add((Polygon) singleFeatureGeometry); } else { polygonList.addAll(((MultiPolygon) singleFeatureGeometry).polygons()); } } } List<Feature> finalFeatureList = new ArrayList<>(0); if (!pointList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPoint.fromLngLats(pointList))); } if (!lineStringList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiLineString.fromLineStrings(lineStringList))); } if (!polygonList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPolygon.fromPolygons(polygonList))); } return finalFeatureList.isEmpty() ? originalFeatureCollection : FeatureCollection.fromFeatures(finalFeatureList); } private  TurfConversion(); static double lengthToDegrees(double distance, @TurfUnitCriteria String units); static double degreesToRadians(double degrees); static double radiansToDegrees(double radians); static double radiansToLength(double radians); static double radiansToLength(double radians, @NonNull @TurfUnitCriteria String units); static double lengthToRadians(double distance); static double lengthToRadians(double distance, @NonNull @TurfUnitCriteria String units); static double convertLength(@FloatRange(from = 0) double distance,
                                     @NonNull @TurfUnitCriteria String originalUnit); static double convertLength(@FloatRange(from = 0) double distance,
                                     @NonNull @TurfUnitCriteria String originalUnit,
                                     @Nullable @TurfUnitCriteria String finalUnit); static FeatureCollection explode(@NonNull FeatureCollection featureCollection); static FeatureCollection explode(@NonNull Feature feature); static Feature polygonToLine(@NonNull Feature feature); static Feature polygonToLine(@NonNull Feature feature, @Nullable JsonObject properties); static Feature polygonToLine(@NonNull Polygon polygon); static FeatureCollection polygonToLine(@NonNull MultiPolygon multiPolygon); static Feature polygonToLine(@NonNull Polygon polygon, @Nullable JsonObject properties); static FeatureCollection polygonToLine(@NonNull MultiPolygon multiPolygon,
                                                @Nullable JsonObject properties); static FeatureCollection multiPolygonToLine(@NonNull Feature feature); static FeatureCollection multiPolygonToLine(@NonNull Feature feature,
                                                     @Nullable JsonObject properties); static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection); }
TurfConversion { public static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection) { if (originalFeatureCollection.features() == null) { throw new TurfException("Your FeatureCollection is null."); } else if (originalFeatureCollection.features().size() == 0) { throw new TurfException("Your FeatureCollection doesn't have any Feature objects in it."); } List<Point> pointList = new ArrayList<>(0); List<LineString> lineStringList = new ArrayList<>(0); List<Polygon> polygonList = new ArrayList<>(0); for (Feature singleFeature : originalFeatureCollection.features()) { Geometry singleFeatureGeometry = singleFeature.geometry(); if (singleFeatureGeometry instanceof Point || singleFeatureGeometry instanceof MultiPoint) { if (singleFeatureGeometry instanceof Point) { pointList.add((Point) singleFeatureGeometry); } else { pointList.addAll(((MultiPoint) singleFeatureGeometry).coordinates()); } } else if (singleFeatureGeometry instanceof LineString || singleFeatureGeometry instanceof MultiLineString) { if (singleFeatureGeometry instanceof LineString) { lineStringList.add((LineString) singleFeatureGeometry); } else { lineStringList.addAll(((MultiLineString) singleFeatureGeometry).lineStrings()); } } else if (singleFeatureGeometry instanceof Polygon || singleFeatureGeometry instanceof MultiPolygon) { if (singleFeatureGeometry instanceof Polygon) { polygonList.add((Polygon) singleFeatureGeometry); } else { polygonList.addAll(((MultiPolygon) singleFeatureGeometry).polygons()); } } } List<Feature> finalFeatureList = new ArrayList<>(0); if (!pointList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPoint.fromLngLats(pointList))); } if (!lineStringList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiLineString.fromLineStrings(lineStringList))); } if (!polygonList.isEmpty()) { finalFeatureList.add(Feature.fromGeometry(MultiPolygon.fromPolygons(polygonList))); } return finalFeatureList.isEmpty() ? originalFeatureCollection : FeatureCollection.fromFeatures(finalFeatureList); } private  TurfConversion(); static double lengthToDegrees(double distance, @TurfUnitCriteria String units); static double degreesToRadians(double degrees); static double radiansToDegrees(double radians); static double radiansToLength(double radians); static double radiansToLength(double radians, @NonNull @TurfUnitCriteria String units); static double lengthToRadians(double distance); static double lengthToRadians(double distance, @NonNull @TurfUnitCriteria String units); static double convertLength(@FloatRange(from = 0) double distance,
                                     @NonNull @TurfUnitCriteria String originalUnit); static double convertLength(@FloatRange(from = 0) double distance,
                                     @NonNull @TurfUnitCriteria String originalUnit,
                                     @Nullable @TurfUnitCriteria String finalUnit); static FeatureCollection explode(@NonNull FeatureCollection featureCollection); static FeatureCollection explode(@NonNull Feature feature); static Feature polygonToLine(@NonNull Feature feature); static Feature polygonToLine(@NonNull Feature feature, @Nullable JsonObject properties); static Feature polygonToLine(@NonNull Polygon polygon); static FeatureCollection polygonToLine(@NonNull MultiPolygon multiPolygon); static Feature polygonToLine(@NonNull Polygon polygon, @Nullable JsonObject properties); static FeatureCollection polygonToLine(@NonNull MultiPolygon multiPolygon,
                                                @Nullable JsonObject properties); static FeatureCollection multiPolygonToLine(@NonNull Feature feature); static FeatureCollection multiPolygonToLine(@NonNull Feature feature,
                                                     @Nullable JsonObject properties); static FeatureCollection combine(@NonNull FeatureCollection originalFeatureCollection);  }