-
Notifications
You must be signed in to change notification settings - Fork 214
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
[Request] Provide an argument to correct
giving a vector defining the interior or exterior of a spherical polygon.
#1075
Comments
I guess one way to implement is do a "contains" query, and then reverse if the answer is the opposite of the expected answer. But maybe there are more efficient ways. |
Could you please provide a minimal code example and explain the issue in more details. I am afraid I cannot fully understand your problem with the current description. |
I think I can explain more without code - but if you still want code later I can provide it. First let's start with boolean operations on a 2d plane. For a polygon, there's a clear inside and outside. Therefore based on the template argument for whether rings are specified clockwise or counter clockwise, correct can easily fix outer and inner rings to be "correct". However, things are not so simple for a spherical polygon. For example, an outer ring could valid define the interior of the polygon no matter which direction it's vertices are specified in. Therefore, in order to properly perform a "correct" a point defining the intended interior is required. |
OK, I see your point now, thanks for clarifications. I think a simpler choice from what you propose is to change |
Here's a code example btw: A couple thoughts:
|
OK, my proposal above was not correct. The main issue here is that Boost.Geometry does not support polygons that cover more than half of the spheroid. So if one gives an order that is opposite from the one in polygon declaration (default: clockwise) then the polygon is invalid and @awulkiew @barendgehrels I cannot find a point in documentation that explicitly states that those polygons are nor supported. Am I missing something here? |
Ouch - I definitely don't like that outcome. I admit I'm not an expert in the internals, but I don't see any reason that should be the case. Already the operations work as expected if the vertex order matches the intended definition - it's just |
OK I think you have to face this feature (Boost.Geometry does not support polygons that cover more than half of the spheroid) as a limitation. I agree that one can use the opposite (to the one defined by the polygon) vertex orientation to represent the complement of a polygon but this is not supported in Boost.Geometry now. Indeed if this is implemented you proposal with the extra point could be used for correct. But I do not see this as a straightforward task since all operations and algorithms should be enhanced to work with that kind of polygons. |
I guess I'm confused when you say it doesn't support it. Maybe |
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <cmath>
#include <iostream>
#include <vector>
namespace bg = boost::geometry;
using SphericalPoint =
bg::model::d2::point_xy<double, bg::cs::spherical_equatorial<bg::degree>>;
using SphericalPolygon =
boost::geometry::model::polygon<SphericalPoint,
false, // clockwise if true
true, // closed
std::vector, std::vector, std::allocator,
std::allocator>;
int main()
{
SphericalPolygon quad {{{0,0}, {0,1}, {1,1}, {1,0}, {0,0}}};
SphericalPoint p {0.5,0.5};
std::cout << "within=" << bg::within(p,quad) << std::endl;
std::cout << bg::wkt(quad) << std::endl;
std::cout << "is valid=" << bg::is_valid(quad) << std::endl;
std::cout << bg::area(quad) << std::endl;
bg::correct(quad);
std::cout << "within=" << bg::within(p,quad) << std::endl;
std::cout << bg::wkt(quad) << std::endl;
std::cout << "is valid=" << bg::is_valid(quad) << std::endl;
std::cout << bg::area(quad) << std::endl;
return 0;
} ΟΚ let me share a simple example based on your code where I use CW ordering while the definition of the polygon was CCW. Then |
sigh - ok...that's a good example. Though, this is a very clear case - I'm still not sure for a much more complex case how the determination is made. Maybe "if all points of a polygon fall within a (freely oriented) hemisphere, then the all of the interior of that polygon must also fall within this hemisphere." It would be nice if this could be fixed, but you don't seem very amenable to that priority. |
Say you have a bunch of polygons which all seem valid by your definition - if you union them they might create a polygon which violates the definition of valid. It seems like this issue has to be fixed for general usage. |
I agree this is a interesting non-trivial feature. I would be interested to work on it but I cannot promise timelines. Also I do not know if other libraries support this feature (AFAIK Microsoft's SQL Server does; at least for certain operations). |
In Boost Geometry union (as any other) function should not generate invalid geometries from valid ones, if you have an example that this happens please file an (different) issue. |
SQL Server supports boolean operations on spherical polygons? |
This case just follows from the fact that the "greater than half" polygons are not handled correctly. |
btw if you can provide guidance, I would be interested in collaborating on fixing this |
sorry for the late reply, sure, I can help! |
great - if you can give me an outline of the tasks that need to be completed i can start digging in...would that be possible? |
@vissarion just pinging to remind you of this |
sorry for the slow replies here... I think it make sense to start with some simple algorithm like area since the whole project seems complicated (i.e. to provide full support for polygons larger than half of the globe). Then there is some issue of consistency since we do not want to change the behaviour of |
That seems like a good place to start to me. |
@vissarion AFAIR polygons that cover less than half of the globe are there because either in setops or buffer the algorithm has to detect the order of points in rings (I don't remember why) and based on that do something with them. @barendgehrels should know more about it. |
@vissarion So one approach to area is pretty simple. If you assume the area should be positive, then you check for a negative result and add 4*pi. This does seem to break stuff downstream though (for example, correct). |
Just wanted to note that I think potentially this enhancement can apply to 2d polygons as well. You could imagine defining a "pure" hole in the 2d plane such that everything outside the exterior ring is "inside the polygon"...although i guess you could do the same by just allowing an empty exterior ring. |
Discussed in #1061
Originally posted by rconde01 October 4, 2022
I'm trying to find a way to specify the inside of a polygon so that the results are correct when calling
correct
. For example, you might have a "cone" where the half angle is greater than 90 degrees. Currently this is corrected such that the axis of the code is flipped to the other side. Specifying a vector in the interior of the polygon should be able to resolve the ambiguity...but so far I don't see a way to do this.The text was updated successfully, but these errors were encountered: