Boost.Geometry is a generic C++ library for geometry. Boost is a well-known peer-reviewed Open Source library collection for C++.
Besides that, this blog contain some texts about (piano)music.

Saturday, November 19, 2011

Linestring/polygon intersection

Linestring/polygon intersection

After a long while a blog again, a short one this time. I'm currently
implementing intersections linestring/polygon for Boost.Geometry. Well, the basics (calculating intersection points) are already there for a long time, but for this combination the intersection points should be followed in another way and the correct pieces should be outputted.

When I do these things I normally check the results with both PostGIS
and SQL Server. However, I'm encountering something weird in both of
them.

The testcase

My testcase is looking like this:

SQL Server

In SQL Server the intersection is correctly done, but the linestring is
reversed! I'm using this query:

You see, the linestring is reversed!
It is not only reversed with this linestring, but with all linestrings.
Even if they are, for example, complete inside the polygon. If I
reverse the polygon (from clockwise to counter clockwise), the output
is still reversed. Mysterious...

I'm getting a multilinestring back! With respect to contents, it is
OK. But it is surprising...

OGC

I did not look it up but I don't think this specific behaviour is
specified. So yes, all implementations will be correct but...

Boost.Geometry

At the moment of writing, technically more difficult cases as this is one are not
completely finished. But I can already tell that the linestring will not be
reversed and that the output will consist of only one linestring...