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

wkt do not duplicate first point at the end for "non closed" ring #1269

Open
GS6902 opened this issue Mar 29, 2024 · 3 comments
Open

wkt do not duplicate first point at the end for "non closed" ring #1269

GS6902 opened this issue Mar 29, 2024 · 3 comments

Comments

@GS6902
Copy link

GS6902 commented Mar 29, 2024

Hello

The following code give "POLYGON((0 0,0 1,1 1,1 0))"
I expected "POLYGON((0 0,0 1,1 1,1 0, 0 0))"

the last point was not repeated.

A ring is supposed to be always closed.
I used a "non closed" ring in my code. But I have understood that template parameter as a convenience way to omit internally the last redundant point. But I suppose the result of the function should not change.

I suppose we should use the closing iterator in this algorithm.

Am I wrong ?

#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>

namespace bg  = boost::geometry;
namespace mdl = boost::geometry::model;
namespace cs  = boost::geometry::cs;

int main()
   {
   constexpr bool IsClosed = false;
   using CPoint = mdl::point<double, 2, cs::cartesian>;
   using CRing = mdl::ring<CPoint, true, IsClosed>;
   CRing Ring {
      { 0, 0 },
      { 0, 1 },
      { 1, 1 },
      { 1, 0 }
   };
   const bool IsValid = bg::is_valid(Ring);
   assert(IsValid);

   std::ostringstream Oss;
   Oss << bg::wkt(Ring);
   std::string String = Oss.str();
   std::cout << String;
   return 0;
   }
@vissarion
Copy link
Member

If you define a ring as non closed and then you omit the repeated point it is a valid geometry. If you define a ring as closed and then you omit the repeated point the geometry is non valid. You can run correct algorithm and then the geometry will be corrected to have the repeated point. So I think everything is as expected here.

Interestingly though, if you define a geometry to be open (as in your case) and you include the repeated point in the creation then the geometry is valid. @barendgehrels is this intended?

@GS6902
Copy link
Author

GS6902 commented Apr 5, 2024

If you define a ring as non closed and then you omit the repeated point it is a valid geometry. If you define a ring as closed and then you omit the repeated point the geometry is non valid. You can run correct algorithm and then the geometry will be corrected to have the repeated point. So I think everything is as expected here.

Interestingly though, if you define a geometry to be open (as in your case) and you include the repeated point in the creation then the geometry is valid. @barendgehrels is this intended?

Thanks a lot for your answer,
My point is that a non closed ring is an oxymoron.
If I follow you a non closed ring (a ring with template parameter set as non closed) is just non closed and a synonym of a linestring ?
Or it is a ring. So it is closed but by convinience the last point can be omitted in case of a "non closed" ring (by setting the template parameter)

In that case I suppose the result of valid ring (closed and non closed) shouldn't change because it model the same concept

@vissarion
Copy link
Member

The correct case is the second case you mentioned. A non closed ring is not a linestring.

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