No Intersection Area for geographic coordinates with Boost Geometry
I need to check whether two points (GPS coordinates) q, m are in the same side or on the opposite side or co linear to a line (great circle segment) (p,t). I know that q is not co linear to (p, t). I didn't find and any direct function to use in the boost.geometry library. So I tried to calculate it in a different way.
I construct two triangles (p, q, t) and (p, m, t). Then I intersect these two and check the area of the intersection polygon. Following is my code.
typedef boost::geometry::model::point<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> geo_point;
typedef boost::geometry::model::polygon<geo_point> geo_polygon;
geo_point p(110.48316, 29.05043);
geo_point q(110.48416, 29.05104);
geo_point t(110.48416, 29.05228);
geo_point m(110.48408, 29.05079);
geo_polygon ut, es;
boost::geometry::append(ut.outer(), p);
boost::geometry::append(ut.outer(), q);
boost::geometry::append(ut.outer(), t);
boost::geometry::append(ut.outer(), p);
boost::geometry::append(es.outer(), p);
boost::geometry::append(es.outer(), m);
boost::geometry::append(es.outer(), t);
boost::geometry::append(es.outer(), p);
std::list<geo_point> intersection_points;
boost::geometry::intersection(ut, es, intersection_points);
std::cout << intersection_points.size() << std::endl;
std::vector<geo_polygon> intersection_polygons;
boost::geometry::intersection(ut, es, intersection_polygons);
std::cout << intersection_polygons.size() << std::endl;
Live at cpp.sh
If we plot these two triangles we can clearly see that they intersects on 3 vertices yielding another triangle in the intersected region.

The above code correctly returns the number of intersected points, but it doesn't return any intersection polygon.
3
0
I have tried using geographic instead of using spherical_equatorial coordinate system. But got the same results. Am I missing something ? or this is a problem in Boost.Geometry
geometry gis computational-geometry boost-geometry
add a comment |
I need to check whether two points (GPS coordinates) q, m are in the same side or on the opposite side or co linear to a line (great circle segment) (p,t). I know that q is not co linear to (p, t). I didn't find and any direct function to use in the boost.geometry library. So I tried to calculate it in a different way.
I construct two triangles (p, q, t) and (p, m, t). Then I intersect these two and check the area of the intersection polygon. Following is my code.
typedef boost::geometry::model::point<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> geo_point;
typedef boost::geometry::model::polygon<geo_point> geo_polygon;
geo_point p(110.48316, 29.05043);
geo_point q(110.48416, 29.05104);
geo_point t(110.48416, 29.05228);
geo_point m(110.48408, 29.05079);
geo_polygon ut, es;
boost::geometry::append(ut.outer(), p);
boost::geometry::append(ut.outer(), q);
boost::geometry::append(ut.outer(), t);
boost::geometry::append(ut.outer(), p);
boost::geometry::append(es.outer(), p);
boost::geometry::append(es.outer(), m);
boost::geometry::append(es.outer(), t);
boost::geometry::append(es.outer(), p);
std::list<geo_point> intersection_points;
boost::geometry::intersection(ut, es, intersection_points);
std::cout << intersection_points.size() << std::endl;
std::vector<geo_polygon> intersection_polygons;
boost::geometry::intersection(ut, es, intersection_polygons);
std::cout << intersection_polygons.size() << std::endl;
Live at cpp.sh
If we plot these two triangles we can clearly see that they intersects on 3 vertices yielding another triangle in the intersected region.

The above code correctly returns the number of intersected points, but it doesn't return any intersection polygon.
3
0
I have tried using geographic instead of using spherical_equatorial coordinate system. But got the same results. Am I missing something ? or this is a problem in Boost.Geometry
geometry gis computational-geometry boost-geometry
What do you want to get from intersection triangle? I don't see how it could help to solve your problem. But calculation of bearings is useful to determine " the same side"
– MBo
Nov 27 '18 at 10:07
The intersection polygon is a straight line if they are on the opposite side, so the area will be 0. Otherwise there will be a non zero area.
– Neel Basu
Nov 27 '18 at 10:14
OK, it's reasonable. I made an answer.
– MBo
Nov 27 '18 at 10:23
add a comment |
I need to check whether two points (GPS coordinates) q, m are in the same side or on the opposite side or co linear to a line (great circle segment) (p,t). I know that q is not co linear to (p, t). I didn't find and any direct function to use in the boost.geometry library. So I tried to calculate it in a different way.
I construct two triangles (p, q, t) and (p, m, t). Then I intersect these two and check the area of the intersection polygon. Following is my code.
typedef boost::geometry::model::point<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> geo_point;
typedef boost::geometry::model::polygon<geo_point> geo_polygon;
geo_point p(110.48316, 29.05043);
geo_point q(110.48416, 29.05104);
geo_point t(110.48416, 29.05228);
geo_point m(110.48408, 29.05079);
geo_polygon ut, es;
boost::geometry::append(ut.outer(), p);
boost::geometry::append(ut.outer(), q);
boost::geometry::append(ut.outer(), t);
boost::geometry::append(ut.outer(), p);
boost::geometry::append(es.outer(), p);
boost::geometry::append(es.outer(), m);
boost::geometry::append(es.outer(), t);
boost::geometry::append(es.outer(), p);
std::list<geo_point> intersection_points;
boost::geometry::intersection(ut, es, intersection_points);
std::cout << intersection_points.size() << std::endl;
std::vector<geo_polygon> intersection_polygons;
boost::geometry::intersection(ut, es, intersection_polygons);
std::cout << intersection_polygons.size() << std::endl;
Live at cpp.sh
If we plot these two triangles we can clearly see that they intersects on 3 vertices yielding another triangle in the intersected region.

The above code correctly returns the number of intersected points, but it doesn't return any intersection polygon.
3
0
I have tried using geographic instead of using spherical_equatorial coordinate system. But got the same results. Am I missing something ? or this is a problem in Boost.Geometry
geometry gis computational-geometry boost-geometry
I need to check whether two points (GPS coordinates) q, m are in the same side or on the opposite side or co linear to a line (great circle segment) (p,t). I know that q is not co linear to (p, t). I didn't find and any direct function to use in the boost.geometry library. So I tried to calculate it in a different way.
I construct two triangles (p, q, t) and (p, m, t). Then I intersect these two and check the area of the intersection polygon. Following is my code.
typedef boost::geometry::model::point<
double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
> geo_point;
typedef boost::geometry::model::polygon<geo_point> geo_polygon;
geo_point p(110.48316, 29.05043);
geo_point q(110.48416, 29.05104);
geo_point t(110.48416, 29.05228);
geo_point m(110.48408, 29.05079);
geo_polygon ut, es;
boost::geometry::append(ut.outer(), p);
boost::geometry::append(ut.outer(), q);
boost::geometry::append(ut.outer(), t);
boost::geometry::append(ut.outer(), p);
boost::geometry::append(es.outer(), p);
boost::geometry::append(es.outer(), m);
boost::geometry::append(es.outer(), t);
boost::geometry::append(es.outer(), p);
std::list<geo_point> intersection_points;
boost::geometry::intersection(ut, es, intersection_points);
std::cout << intersection_points.size() << std::endl;
std::vector<geo_polygon> intersection_polygons;
boost::geometry::intersection(ut, es, intersection_polygons);
std::cout << intersection_polygons.size() << std::endl;
Live at cpp.sh
If we plot these two triangles we can clearly see that they intersects on 3 vertices yielding another triangle in the intersected region.

The above code correctly returns the number of intersected points, but it doesn't return any intersection polygon.
3
0
I have tried using geographic instead of using spherical_equatorial coordinate system. But got the same results. Am I missing something ? or this is a problem in Boost.Geometry
geometry gis computational-geometry boost-geometry
geometry gis computational-geometry boost-geometry
edited Nov 27 '18 at 8:52
Neel Basu
asked Nov 27 '18 at 8:33
Neel BasuNeel Basu
7,4451060119
7,4451060119
What do you want to get from intersection triangle? I don't see how it could help to solve your problem. But calculation of bearings is useful to determine " the same side"
– MBo
Nov 27 '18 at 10:07
The intersection polygon is a straight line if they are on the opposite side, so the area will be 0. Otherwise there will be a non zero area.
– Neel Basu
Nov 27 '18 at 10:14
OK, it's reasonable. I made an answer.
– MBo
Nov 27 '18 at 10:23
add a comment |
What do you want to get from intersection triangle? I don't see how it could help to solve your problem. But calculation of bearings is useful to determine " the same side"
– MBo
Nov 27 '18 at 10:07
The intersection polygon is a straight line if they are on the opposite side, so the area will be 0. Otherwise there will be a non zero area.
– Neel Basu
Nov 27 '18 at 10:14
OK, it's reasonable. I made an answer.
– MBo
Nov 27 '18 at 10:23
What do you want to get from intersection triangle? I don't see how it could help to solve your problem. But calculation of bearings is useful to determine " the same side"
– MBo
Nov 27 '18 at 10:07
What do you want to get from intersection triangle? I don't see how it could help to solve your problem. But calculation of bearings is useful to determine " the same side"
– MBo
Nov 27 '18 at 10:07
The intersection polygon is a straight line if they are on the opposite side, so the area will be 0. Otherwise there will be a non zero area.
– Neel Basu
Nov 27 '18 at 10:14
The intersection polygon is a straight line if they are on the opposite side, so the area will be 0. Otherwise there will be a non zero area.
– Neel Basu
Nov 27 '18 at 10:14
OK, it's reasonable. I made an answer.
– MBo
Nov 27 '18 at 10:23
OK, it's reasonable. I made an answer.
– MBo
Nov 27 '18 at 10:23
add a comment |
1 Answer
1
active
oldest
votes
To ensure that polygons are closed and oriented as needed, apply correct. Inserting
boost::geometry::correct(ut);
boost::geometry::correct(es);
gives result 1 polygon for your test
The polygons are closed properly because I append that first point at the end. Isn't that sufficient ? Also what doesorientedmean in this context ?
– Neel Basu
Nov 27 '18 at 11:03
From description:all rings which are wrongly oriented with respect to their expected orientation are reversed(I was wondering myself)
– MBo
Nov 27 '18 at 11:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53495542%2fno-intersection-area-for-geographic-coordinates-with-boost-geometry%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To ensure that polygons are closed and oriented as needed, apply correct. Inserting
boost::geometry::correct(ut);
boost::geometry::correct(es);
gives result 1 polygon for your test
The polygons are closed properly because I append that first point at the end. Isn't that sufficient ? Also what doesorientedmean in this context ?
– Neel Basu
Nov 27 '18 at 11:03
From description:all rings which are wrongly oriented with respect to their expected orientation are reversed(I was wondering myself)
– MBo
Nov 27 '18 at 11:04
add a comment |
To ensure that polygons are closed and oriented as needed, apply correct. Inserting
boost::geometry::correct(ut);
boost::geometry::correct(es);
gives result 1 polygon for your test
The polygons are closed properly because I append that first point at the end. Isn't that sufficient ? Also what doesorientedmean in this context ?
– Neel Basu
Nov 27 '18 at 11:03
From description:all rings which are wrongly oriented with respect to their expected orientation are reversed(I was wondering myself)
– MBo
Nov 27 '18 at 11:04
add a comment |
To ensure that polygons are closed and oriented as needed, apply correct. Inserting
boost::geometry::correct(ut);
boost::geometry::correct(es);
gives result 1 polygon for your test
To ensure that polygons are closed and oriented as needed, apply correct. Inserting
boost::geometry::correct(ut);
boost::geometry::correct(es);
gives result 1 polygon for your test
answered Nov 27 '18 at 10:21
MBoMBo
48.8k23050
48.8k23050
The polygons are closed properly because I append that first point at the end. Isn't that sufficient ? Also what doesorientedmean in this context ?
– Neel Basu
Nov 27 '18 at 11:03
From description:all rings which are wrongly oriented with respect to their expected orientation are reversed(I was wondering myself)
– MBo
Nov 27 '18 at 11:04
add a comment |
The polygons are closed properly because I append that first point at the end. Isn't that sufficient ? Also what doesorientedmean in this context ?
– Neel Basu
Nov 27 '18 at 11:03
From description:all rings which are wrongly oriented with respect to their expected orientation are reversed(I was wondering myself)
– MBo
Nov 27 '18 at 11:04
The polygons are closed properly because I append that first point at the end. Isn't that sufficient ? Also what does
oriented mean in this context ?– Neel Basu
Nov 27 '18 at 11:03
The polygons are closed properly because I append that first point at the end. Isn't that sufficient ? Also what does
oriented mean in this context ?– Neel Basu
Nov 27 '18 at 11:03
From description:
all rings which are wrongly oriented with respect to their expected orientation are reversed (I was wondering myself)– MBo
Nov 27 '18 at 11:04
From description:
all rings which are wrongly oriented with respect to their expected orientation are reversed (I was wondering myself)– MBo
Nov 27 '18 at 11:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53495542%2fno-intersection-area-for-geographic-coordinates-with-boost-geometry%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What do you want to get from intersection triangle? I don't see how it could help to solve your problem. But calculation of bearings is useful to determine " the same side"
– MBo
Nov 27 '18 at 10:07
The intersection polygon is a straight line if they are on the opposite side, so the area will be 0. Otherwise there will be a non zero area.
– Neel Basu
Nov 27 '18 at 10:14
OK, it's reasonable. I made an answer.
– MBo
Nov 27 '18 at 10:23