-1

I am using JTS and I have one big Multypolygon with seperated Areas. How can I get a List of Polygons representing these seperated areas.

Thanks in Advance Lukas

  • What have you tried so far? Basically, you loop through the individual polygons in the multi polygons and put them in a list or other collection – Ian Turton Jan 16 '22 at 16:50

1 Answers1

2

This is fairly simple, given a MultiPolygon p:

ArrayList<Polygon> polygons = new ArrayList<>();
for (int i = 0; i < p.getNumGeometries(); i++) {
    Polygon polygon = (Polygon)p.getGeometryN(i);
    polygons.add(polygon)
}
Ian Turton
  • 10,018
  • 1
  • 28
  • 47
  • Hey Ian, thank you so much. I had a different solution that took so long. Now its working much better. Best regards – lord rufusus Jan 17 '22 at 21:11
  • Please take the [tour] to see how to become a good citizen on this site - https://meta.stackexchange.com/questions/47962/what-should-i-do-when-the-correct-answer-to-a-question-changes-over-time – Ian Turton Jan 18 '22 at 08:50