Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static PolygonOptions combineIntoOneGeometry(List<PolygonOptions> polygonOptionses )
- {
- PolygonOptions polygonOptions = new PolygonOptions();
- GeometryFactory factory = new GeometryFactory();
- List<Geometry> geometryList = new ArrayList<>();
- for( int i = 0; i < polygonOptionses.size(); i++)
- {
- List<LatLng> latLngList = polygonOptionses.get(i).getPoints();
- Coordinate[] coords = new Coordinate[latLngList.size()];
- for( int j = 0; j < latLngList.size();j++)
- {
- coords[j] = new Coordinate(latLngList.get(j).latitude, latLngList.get(j).longitude);
- }
- coords[coords.length - 1] = coords[0];
- LinearRing ring = factory.createLinearRing( coords );
- LinearRing holes[] = null; // use LinearRing[] to represent holes
- com.vividsolutions.jts.geom.Polygon polygon = factory.createPolygon(ring, holes );
- geometryList.add(polygon);
- }
- Geometry polygonMain = geometryList.get(0);
- for(int i = 1; i < geometryList.size(); i++)
- {
- Geometry geoAux = polygonMain.union(geometryList.get(i));
- polygonMain = geoAux;
- }
- Coordinate[] coordinates = polygonMain.getCoordinates();
- List<LatLng> points = new ArrayList<>();
- for( int i = 0; i < coordinates.length; i++ )
- {
- points.add(i, new LatLng(coordinates[i].x, coordinates[i].y));
- }
- polygonOptions.addAll(points);
- return polygonOptions;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement