Intersection of linestring with polygon

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Intersection of linestring with polygon

mumakin

Hello,

 

I have successfully used boost::geometry::intersection to get the intersection of two polygons. How I want to get the intersection of a polygon and a line (the portion of the line that is internal to the polygon). When I call intersection(polygon, linestring, vector_of_linestring) I get compiler errors.

 

Could someone please advise me on how that can be accomplished.

 

Thanks,

 

Mike


.
===============================================
The content of this message may contain the private views and opinions of the sender and does not constitute a formal view and/or opinion of the company unless specifically stated.

The contents of this email and any attachments may contain confidential and/or proprietary information, and is intended only for the person/entity to whom it was originally addressed. Any dissemination, distribution or copying of this communication is strictly prohibited.

If you have received this email in error please notify the sender immediately by return e-mail and delete this message and any attachments from your system.

Please refer to http://www.newmont.com/en/disclaimer for other language versions of this disclaimer. ================================================

_______________________________________________
ggl mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/ggl
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Aleksandar Babic
Hi,

It seems that the functionality for few combinations (also for some
other algorithms) is not yet implemented.

One approximation that you might try (may be valid approach from case to
case) is to try converting both geometries to the closest common
concept.
For example, try converting line and polygon to the linestring/ring and
the finding the intersection (might help with other algorithms as well).

Hope this helps.

BR
Aleksandar

On Mon, 2011-11-14 at 16:23 -0700, Mike Williams wrote:

> Hello,
>
>  
>
> I have successfully used boost::geometry::intersection to get the
> intersection of two polygons. How I want to get the intersection of a
> polygon and a line (the portion of the line that is internal to the
> polygon). When I call intersection(polygon, linestring,
> vector_of_linestring) I get compiler errors.
>
>  
>
> Could someone please advise me on how that can be accomplished.
>
>  
>
> Thanks,
>
>  
>
> Mike
>
>
>
> .
> ===============================================
> The content of this message may contain the private views and opinions
> of the sender and does not constitute a formal view and/or opinion of
> the company unless specifically stated.
>
> The contents of this email and any attachments may contain
> confidential and/or proprietary information, and is intended only for
> the person/entity to whom it was originally addressed. Any
> dissemination, distribution or copying of this communication is
> strictly prohibited.
>
> If you have received this email in error please notify the sender
> immediately by return e-mail and delete this message and any
> attachments from your system.
>
> Please refer to http://www.newmont.com/en/disclaimer for other
> language versions of this disclaimer.
> ================================================
> _______________________________________________
> ggl mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/ggl


_______________________________________________
ggl mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/ggl
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Barend
Hi Mike, Aleksander,

On 15-11-2011 8:23, Aleksandar Babic wrote:

> Hi,
>
> It seems that the functionality for few combinations (also for some
> other algorithms) is not yet implemented.
>
> One approximation that you might try (may be valid approach from case to
> case) is to try converting both geometries to the closest common
> concept.
> For example, try converting line and polygon to the linestring/ring and
> the finding the intersection (might help with other algorithms as well).
>
> Hope this helps.
>
> BR
> Aleksandar
>
> On Mon, 2011-11-14 at 16:23 -0700, Mike Williams wrote:
>> Hello,
>>
>>
>>
>> I have successfully used boost::geometry::intersection to get the
>> intersection of two polygons. How I want to get the intersection of a
>> polygon and a line (the portion of the line that is internal to the
>> polygon). When I call intersection(polygon, linestring,
>> vector_of_linestring) I get compiler errors.
>>
>>
>>
>> Could someone please advise me on how that can be accomplished.
>>
>>


Indeed it is not yet implemented. It can be done (is done by some
people) by using intersection points, but that is a bit tedious (if
you're not deep inside the details of the library). Because this (plus
boolean functions) is asked so much I'll try to work on this coming weekend.

Aleksandar, to be honest I don't understand your suggestion completely,
or it might work for some algorithms but I don't see how it would work here.

Regards, Barend

_______________________________________________
ggl mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/ggl
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Aleksandar Babic
Hi Barend,

I didn't claim that things I suggested will work in Mikes case. I simply
said that he might try something and see if it goes well or he can build
further on the obtained result.

Let's say we have functionality OP and "Geom1 OP Geom2" is currently
implemented just between same kinds, but not when things are mixed.
If we i.e. have segment and linearring we could build linearstrings from
them, apply the OP and then try to analyse result further.  

Hope that this kind of thinking is applicable in some cases :)

Regards,
Aleksandar

On Tue, 2011-11-15 at 23:04 +0100, Barend Gehrels wrote:

> Hi Mike, Aleksander,
>
> On 15-11-2011 8:23, Aleksandar Babic wrote:
> > Hi,
> >
> > It seems that the functionality for few combinations (also for some
> > other algorithms) is not yet implemented.
> >
> > One approximation that you might try (may be valid approach from case to
> > case) is to try converting both geometries to the closest common
> > concept.
> > For example, try converting line and polygon to the linestring/ring and
> > the finding the intersection (might help with other algorithms as well).
> >
> > Hope this helps.
> >
> > BR
> > Aleksandar
> >
> > On Mon, 2011-11-14 at 16:23 -0700, Mike Williams wrote:
> >> Hello,
> >>
> >>
> >>
> >> I have successfully used boost::geometry::intersection to get the
> >> intersection of two polygons. How I want to get the intersection of a
> >> polygon and a line (the portion of the line that is internal to the
> >> polygon). When I call intersection(polygon, linestring,
> >> vector_of_linestring) I get compiler errors.
> >>
> >>
> >>
> >> Could someone please advise me on how that can be accomplished.
> >>
> >>
>
>
> Indeed it is not yet implemented. It can be done (is done by some
> people) by using intersection points, but that is a bit tedious (if
> you're not deep inside the details of the library). Because this (plus
> boolean functions) is asked so much I'll try to work on this coming weekend.
>
> Aleksandar, to be honest I don't understand your suggestion completely,
> or it might work for some algorithms but I don't see how it would work here.
>
> Regards, Barend
>
> _______________________________________________
> ggl mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/ggl


_______________________________________________
ggl mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/ggl
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Barend
Hi Aleksander,

On 17-11-2011 9:02, Aleksandar Babic wrote:

> Hi Barend,
>
> I didn't claim that things I suggested will work in Mikes case. I simply
> said that he might try something and see if it goes well or he can build
> further on the obtained result.
>
> Let's say we have functionality OP and "Geom1 OP Geom2" is currently
> implemented just between same kinds, but not when things are mixed.
> If we i.e. have segment and linearring we could build linearstrings from
> them, apply the OP and then try to analyse result further.
>
> Hope that this kind of thinking is applicable in some cases :)
>
Sure it is!

In the meantime I'm continuing with the linestring/polygon overlay and
hope to have more news today.

Regards, Barend


_______________________________________________
ggl mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/ggl
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Barend
In reply to this post by mumakin
Hi,

On 15-11-2011 0:23, Mike Williams wrote:

Hello,

 

I have successfully used boost::geometry::intersection to get the intersection of two polygons. How I want to get the intersection of a polygon and a line (the portion of the line that is internal to the polygon). When I call intersection(polygon, linestring, vector_of_linestring) I get compiler errors.

 

Could someone please advise me on how that can be accomplished.

 


It is now basically running for most linear/aereal combinations ((multi)linestring/(multi)polygon/ring). Almost all cases are running. Almost, because there is at least one case not yet finished and there might be more. But those are the more exotic ones, you will probably (depending on your usecase of course) have no problems. In case you are trying it already and encounter a problem, please report it.

Next week I will continue with those other cases, the difference (here the complement of the intersection), and a robustness test to verify more cases. Robustness tests are also done for polygons, it found at that time also some new cases so quite convenient.

Regards, Barend


_______________________________________________
ggl mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/ggl
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Sebastian
Barend wrote
It is now basically running for most linear/aereal combinations
((multi)linestring/(multi)polygon/ring). Almost all cases are running.
Almost, because there is at least one case not yet finished and there
might be more. But those are the more exotic ones, you will probably
(depending on your usecase of course) have no problems. In case you are
trying it already and encounter a problem, please report it.
Is there any progress on that matter? I've tried an intersection test with a line string and a polygon/ring but it didn't work. I got a compiler error. Here's my source code:

http://boost.codepad.org/rVahJTRJ

I've tried it with Boost 1.48, 1.49 beta, and the current SVN trunk (rev. 76906).

Is there any way to get this working?
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

edd cmaugo
Hi,

Alternately, you can use boost::geometry::get_turns()  and boost::geometry::detail::overlay::turn_info to make it by yourself.


2012/2/7 Sebastian <[hidden email]>

Barend wrote
>
> It is now basically running for most linear/aereal combinations
> ((multi)linestring/(multi)polygon/ring). Almost all cases are running.
> Almost, because there is at least one case not yet finished and there
> might be more. But those are the more exotic ones, you will probably
> (depending on your usecase of course) have no problems. In case you are
> trying it already and encounter a problem, please report it.
>

Is there any progress on that matter? I've tried an intersection test with a
line string and a polygon/ring but it didn't work. I got a compiler error.
Here's my source code:

http://boost.codepad.org/rVahJTRJ http://boost.codepad.org/rVahJTRJ

I've tried it with Boost 1.48, 1.49 beta, and the current SVN trunk (rev.
76906).

Is there any way to get this working?

--
View this message in context: http://boost-geometry.203548.n3.nabble.com/Intersection-of-linestring-with-polygon-tp3508279p3721876.html
Sent from the Boost Geometry mailing list archive at Nabble.com.
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry


_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Sebastian
edd cmaugo wrote
Alternately, you can use boost::geometry::get_turns()  and
boost::geometry::detail::overlay::turn_info to make it by yourself.
I'm quite new to Boost and Boost geometry. Is "get_turns()" documented anywhere? A quick search on Google didn't reveal anything, there's nothing in http://www.boost.org/doc/libs/1_48_0/libs/geometry/doc/html/geometry/indexes/alphabetical_index.html nor in http://geometrylibrary.geodan.nl/modules.html. Also there is no documentation in the source code itself (at least I couldn't find anything).

Or could you provide an example for me? Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

edd cmaugo
I used this example :

http://svn.boost.org/svn/boost/sandbox/geometry/other/exp2/example/05_b_overlay_linestring_polygon_example.cpp

By ordering the turn points, you can manage to get the parts of the linetring that lies inside or outside your polygon.

2012/2/7 Sebastian <[hidden email]>

edd cmaugo wrote
>
> Alternately, you can use boost::geometry::get_turns()  and
> boost::geometry::detail::overlay::turn_info to make it by yourself.
>

I'm quite new to Boost and Boost geometry. Is "get_turns()" documented
anywhere? A quick search on Google didn't reveal anything, there's nothing
in
http://www.boost.org/doc/libs/1_48_0/libs/geometry/doc/html/geometry/indexes/alphabetical_index.html
nor in http://geometrylibrary.geodan.nl/modules.html. Also there is no
documentation in the source code itself (at least I couldn't find anything).

Or could you provide an example for me? Thanks.

--
View this message in context: http://boost-geometry.203548.n3.nabble.com/Intersection-of-linestring-with-polygon-tp3508279p3721981.html
Sent from the Boost Geometry mailing list archive at Nabble.com.
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry


_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Sebastian
Unfortunately I don't have access to the sandbox. It seems it's only for contributers. Could you post the contents of this file somewhere?
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Sebastian
Never mind. The link needs to use "https://" instead of just "http://".

Sebastian wrote
Unfortunately I don't have access to the sandbox. It seems it's only for contributers. Could you post the contents of this file somewhere?
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Barend
In reply to this post by Sebastian
Hi Sebastian,

In addition to the answer of Edd.


On 7-2-2012 9:27, Sebastian wrote:
> Barend wrote
>> It is now basically running for most linear/aereal combinations
>> ((multi)linestring/(multi)polygon/ring). Almost all cases are running.
>> Almost, because there is at least one case not yet finished and there
>> might be more. But those are the more exotic ones, you will probably
>> (depending on your usecase of course) have no problems. In case you are
>> trying it already and encounter a problem, please report it.
>>
> Is there any progress on that matter?

What was implemented (november) is the intersection of
polygon/linestring. So that outputs zero or more linestrings. That will
be in 1.49.



> I've tried an intersection test with a
> line string and a polygon/ring but it didn't work. I got a compiler error.
> Here's my source code:
>
> http://boost.codepad.org/rVahJTRJ http://boost.codepad.org/rVahJTRJ

Your request is much simpler: you want to have true/false.

Indeed intersects does not support that, so please refer to the sample
that Edd gave (it is also in trunk/release in the example folder).

Alternatively you could call intersection and use num_points (or
empty()) to check if there is any output.

The inclusion in intersects should be possible for next round (= 1.50).

Regards, Barend


_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

jakka30
Hi Barend,

I am trying to use boost::geometry::intersection with our legacy geometry model. They have been registered successfully with Boost. I am getting the following error when I try to do it.


Error 42 error C2039: 'size' : is not a member of 'MyLineString3D<Type>' t:\boost\boost\geometry\algorithms\detail\overlay\follow.hpp 399


Could you please let me know what I am doing wrong here?

Thank you,
Suresh

Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Adam Wulkiewicz
Hi,

jakka30 wrote:

> Hi Barend,
>
> I am trying to use boost::geometry::intersection with our legacy geometry
> model. They have been registered successfully with Boost. I am getting the
> following error when I try to do it.
>
>
> *Error 42 error C2039: 'size' : is not a member of 'MyLineString3D<Type>'
> t:\boost\boost\geometry\algorithms\detail\overlay\follow.hpp 399*
>
>
> Could you please let me know what I am doing wrong here?
>

This is probably an error, boost::size() should be called instead of
size() member. Barend should I fix it?

Regards,
Adam

_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Barend
hi Adam,


> Hi,
>
> jakka30 wrote:
>> Hi Barend,
>>
>> I am trying to use boost::geometry::intersection with our legacy geometry
>> model. They have been registered successfully with Boost. I am getting the
>> following error when I try to do it.
>>
>>
>> *Error    42    error C2039: 'size' : is not a member of 'MyLineString3D<Type>'
>> t:\boost\boost\geometry\algorithms\detail\overlay\follow.hpp    399*
>>
>>
>> Could you please let me know what I am doing wrong here?
>>
>
> This is probably an error, boost::size() should be called instead of size() member. Barend should I fix it?
>

Sure, my bad. Yes, please.

Thanks, Barend
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

jakka30
Hi Adam & Barend,

Thank you a lot for your quick reply. I changed "current_piece.size()" to boost::size(linestring) in two places at line number 399 & 185 in follow.hpp. Now I am getting an error at the line number 189 (current_piece.clear()). The error message is

Error 1 error C2882: 'clear' : illegal use of namespace identifier in expression t:\boost\boost\geometry\algorithms\detail\overlay\follow.hpp 189

To just try to compile it, I commented line number 189 and then compiled it. I got the following error.

Error 1 error C2676: binary '[' : 'const MyLineString2D<Type>' does not define this operator or a conversion to a type acceptable to the predefined operator t:\boost\boost\geometry\algorithms\detail\overlay\follow.hpp 64

Could you please help me to fix this issue? I am trying to use the intersection operation between a custom polygon and custom linestring.

Thank you in advance,
Suresh
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

jakka30
Hi Adam & Barend,

I could fix the second error by overloading [] operator on MyLineString2D class. But I am still getting error from clear (first error). Could you please let me know how to fix this error?

Thank you,
Suresh
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

jakka30
Hi Adam & Barend,

I got clear error fixed by changing the line "current_piece.clear();" with "boost::geometry::clear(current_piece);". Is it correct fix? Please advice.

Thank you in advance,
Suresh
Reply | Threaded
Open this post in threaded view
|

Re: Intersection of linestring with polygon

Barend
In reply to this post by jakka30
Hi Suresh,

jakka30 wrote On 16-10-2013 15:23:

> Hi Adam & Barend,
>
> Thank you a lot for your quick reply. I changed "current_piece.size()" to
> boost::size(linestring) in two places at line number 399 & 185 in
> follow.hpp. Now I am getting an error at the line number 189
> (current_piece.clear()). The error message is
>
> *Error 1 error C2882: 'clear' : illegal use of namespace identifier in
> expression t:\boost\boost\geometry\algorithms\detail\overlay\follow.hpp 189*
>
> To just try to compile it, I commented line number 189 and then compiled it.
> I got the following error.
>
> *Error 1 error C2676: binary '[' : 'const MyLineString2D<Type>' does not
> define this operator or a conversion to a type acceptable to the predefined
> operator t:\boost\boost\geometry\algorithms\detail\overlay\follow.hpp 64*
>
> Could you please help me to fix this issue? I am trying to use the
> intersection operation between a custom polygon and custom linestring.
>
That is useful. Thanks for the report.

So .size() should indeed be boost::size(current_piece), and .clear()
should be replaced by traits::clear<LineStringOut>::apply(current_piece);

Then on line 64, linestring[op.seg_id.segment_index] should be replaced
by *(boost::begin(linestring) + op.seg_id.segment_index)

Sorry for these omissions, I apparently did not pay enough attention to
this.

Regards, Barend


_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
12