Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public static PolygonOptions combineIntoOneGeometry(List<PolygonOptions> polygonOptionses )
  2. {
  3. PolygonOptions polygonOptions = new PolygonOptions();
  4. GeometryFactory factory = new GeometryFactory();
  5.  
  6. List<Geometry> geometryList = new ArrayList<>();
  7. for( int i = 0; i < polygonOptionses.size(); i++)
  8. {
  9. List<LatLng> latLngList = polygonOptionses.get(i).getPoints();
  10. Coordinate[] coords = new Coordinate[latLngList.size()];
  11. for( int j = 0; j < latLngList.size();j++)
  12. {
  13. coords[j] = new Coordinate(latLngList.get(j).latitude, latLngList.get(j).longitude);
  14.  
  15. }
  16. coords[coords.length - 1] = coords[0];
  17. LinearRing ring = factory.createLinearRing( coords );
  18. LinearRing holes[] = null; // use LinearRing[] to represent holes
  19. com.vividsolutions.jts.geom.Polygon polygon = factory.createPolygon(ring, holes );
  20.  
  21. geometryList.add(polygon);
  22. }
  23.  
  24. Geometry polygonMain = geometryList.get(0);
  25. for(int i = 1; i < geometryList.size(); i++)
  26. {
  27. Geometry geoAux = polygonMain.union(geometryList.get(i));
  28. polygonMain = geoAux;
  29. }
  30.  
  31. Coordinate[] coordinates = polygonMain.getCoordinates();
  32. List<LatLng> points = new ArrayList<>();
  33. for( int i = 0; i < coordinates.length; i++ )
  34. {
  35. points.add(i, new LatLng(coordinates[i].x, coordinates[i].y));
  36. }
  37. polygonOptions.addAll(points);
  38.  
  39. return polygonOptions;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement