Boost C++ Libraries: Ticket #12314: boost::geometry::within for a point in a geographic coordinate system fails https://svn.boost.org/trac10/ticket/12314 <blockquote> <p> I am using the geometry part of the library for a GIS application. The idea is to find points within defined regions (a rectangle in this case). This works sometimes but not always. Here is an example where the point should be within the rectangle but isn't... </p> </blockquote> <pre class="wiki"> #include &lt;boost/geometry.hpp&gt; #include &lt;boost/geometry/geometries/polygon.hpp&gt; #include &lt;boost/geometry/multi/geometries/multi_polygon.hpp&gt; #include &lt;boost/geometry/geometries/register/point.hpp&gt; #include &lt;iostream&gt; #include &lt;boost/geometry/io/wkt/wkt.hpp&gt; class wxPoint { public : double getx() const { return m_x; } double gety() const { return m_y; } void setx( double in) { m_x = in; } void sety(double in) { m_y = in; } private: double m_x; double m_y; }; BOOST_GEOMETRY_REGISTER_POINT_2D_GET_SET( wxPoint, double, boost::geometry::cs::geographic&lt;boost::geometry::degree&gt;, wxPoint::getx, wxPoint::gety, wxPoint::setx, wxPoint::sety ) int main() { boost::geometry::model::polygon&lt; wxPoint &gt; poly; boost::geometry::read_wkt( "POLYGON((0 89, 180 89, 180 0, 0 0, 0 89 ))", poly ); wxPoint point; point.setx( 150 ); point.sety( 88 ); bool within = boost::geometry::within( point, poly ); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12314 Trac 1.4.3 awulkiew Tue, 03 Jan 2017 13:51:34 GMT <link>https://svn.boost.org/trac10/ticket/12314#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12314#comment:1</guid> <description> <p> In non-cartesian coordinate systems the edges of Polygons are also shortest lines between points so e.g. the edge: <code>(0 89, 180 89)</code> intersects the north pole. In the case of the edge <code>(180 0, 0 0)</code> I'm not sure what the algorithm assumes but this edge is invalid. The reason for that is that there is infinite number of possible edges connecting these points in spherical and 2 possible edges in geographic (going through north or south pole). Either way I presume this is not what you had in mind. </p> <p> You could fix the invalidity by adding additional point between the endpoints of the invalid edge, so: <code>POLYGON((0 89, 180 89, 180 0, 90 0, 0 0, 0 89 ))</code> but this is not what you wanted to do either. </p> <p> AFAIU what you wanted to do is to create a "rectangular" region (in spherical/geographic having edges being parallels and meridians) and that you should use your own rectangle representation adapted to Boost.Geometry Box concept or <code>bg::model::box</code> for this: </p> <pre class="wiki">boost::geometry::model::box&lt; wxPoint &gt; box; boost::geometry::read_wkt("BOX(0 0, 180 89)", box); </pre><p> or </p> <pre class="wiki">boost::geometry::model::box&lt; wxPoint &gt; box(pt1, pt2); </pre><p> So I don't think this is a bug. </p> <p> Does the above explanation make sense and solution work for you? </p> </description> <category>Ticket</category> </item> </channel> </rss>