Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffering linestring on right side creating weird results #1167

Open
bertrandpellenard opened this issue Jun 22, 2023 · 2 comments
Open

Buffering linestring on right side creating weird results #1167

bertrandpellenard opened this issue Jun 22, 2023 · 2 comments
Assignees

Comments

@bertrandpellenard
Copy link

Hello,
I have a linestring and I am running the buffer function with an asymmetric distance. I want to buffer only on the right side of the linestring LINESTRING(0 0,-3 5,15 7,17 4,14 2)
I am getting unexpected results.


buffer_01
buffer_02

Here is an idea of the code:

using coordinate_type = double;
  using point = boost::geometry::model::d2::point_xy<coordinate_type>;
  using polygon = boost::geometry::model::polygon<point>;

  // Declare strategies
  const double buffer_distance = amount;
  const int points_per_circle = 36;
  boost::geometry::strategy::buffer::distance_symmetric<coordinate_type>
      bg_both_sides_distance_strategy(buffer_distance);

  boost::geometry::strategy::buffer::distance_asymmetric<coordinate_type>
      bg_left_side_distance_strategy(buffer_distance, 0.0);

  boost::geometry::strategy::buffer::distance_asymmetric<coordinate_type>
      bg_right_side_distance_strategy(0.0, buffer_distance);

  boost::geometry::strategy::buffer::join_miter bg_join_miter_strategy;
  boost::geometry::strategy::buffer::join_round bg_join_round_strategy(
      points_per_circle);

  boost::geometry::strategy::buffer::end_round bg_end_round_strategy(
      points_per_circle);

  boost::geometry::strategy::buffer::end_flat bg_end_flat_strategy;

  boost::geometry::strategy::buffer::point_circle bg_circle_strategy(
      points_per_circle);
  boost::geometry::strategy::buffer::side_straight bg_side_straight_strategy;

 // Declare output
  boost::geometry::model::multi_polygon<polygon> result;

 // Declare/fill a linestring
    boost::geometry::model::linestring<point> ls;
    ls.reserve(pts_in.size());
    for (const auto& pt : pts_in) {
      ls.emplace_back(pt[0], pt[1]);
    }

boost::geometry::buffer(ls, result, bg_right_side_distance_strategy,
                                  bg_side_straight_strategy,
                                  bg_join_round_strategy, bg_end_round_strategy,
                                  bg_circle_strategy);

std::cout << "output: " << boost::geometry::wkt(result) << std::endl;

Thank you.
Best regards.
Bertrand

@bertrandpellenard bertrandpellenard changed the title Buffering polyline on one side created weird result Buffering linestring on right side creating weird results Jun 22, 2023
@mclow mclow transferred this issue from boostorg/boost Jun 22, 2023
@barendgehrels barendgehrels self-assigned this Jun 25, 2023
@barendgehrels
Copy link
Collaborator

Thanks for the report. I can reproduce it. Also with different coordinates - so it's not a precision issue.
With a small left distance you see already some artefacts.

I cannot look at it right now, but will do later.

image

Adapted code:

    boost::geometry::strategy::buffer::distance_asymmetric<coordinate_type> bg_distance_strategy(0.025, 0.1);

and

    boost::geometry::model::linestring<point> ls;
    boost::geometry::read_wkt("LINESTRING(0 0,-3 5,15 7,17 4,14 2)", ls);

@bertrandpellenard
Copy link
Author

I used boost::geometry::strategy::buffer::distance_asymmetric<coordinate_type> bg_distance_strategy(0.0, 1.0); in the pictures I shared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants