Skip to content

Union of arbitrary number of overlapping polygons. #947

Answered by barendgehrels
awulkiew asked this question in Q&A
Discussion options

You must be logged in to vote

This works well:

template <typename Geometry, typename It>
Geometry recursive_union(It begin, It end, std::size_t max_distance) {
  Geometry unioned = {};
  if (begin == end) {
    return unioned;
  }

  const auto dist = std::distance(begin, end);
  if (dist >= max_distance) {
    It mid = begin;
    std::advance(mid, dist / 2);

    const Geometry left = recursive_union<Geometry>(begin, mid, max_distance);
    const Geometry right = recursive_union<Geometry>(mid, end, max_distance);

    bg::union_(left, right, unioned);

    return unioned;
  }

  // Iteratively add this small amount of polygons
  for (It it = begin; it != end; ++it) {
    multipol_t combined;
    bg::union_(unioned, *…

Replies: 4 comments 9 replies

Comment options

You must be logged in to vote
0 replies
Comment options

awulkiew
Dec 2, 2021
Maintainer Author

You must be logged in to vote
2 replies
@barendgehrels
Comment options

@barendgehrels
Comment options

Comment options

You must be logged in to vote
5 replies
@awulkiew
Comment options

awulkiew Dec 6, 2021
Maintainer Author

@barendgehrels
Comment options

@barendgehrels
Comment options

@barendgehrels
Comment options

@awulkiew
Comment options

awulkiew May 9, 2023
Maintainer Author

Answer selected by awulkiew
Comment options

You must be logged in to vote
2 replies
@awulkiew
Comment options

awulkiew May 9, 2023
Maintainer Author

@viveksood97
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants