| Home | Libraries | People | FAQ | More

##### crosses

Checks if two geometries crosses.

###### Synopsis

    template<typename Geometry1, typename Geometry2>
    bool crosses(Geometry1 const & geometry1, Geometry2 const & geometry2)

###### Parameters

Type | Concept | Name | Description
--- | --- | --- | ---
Geometry1 const & | Any type fulfilling a Geometry Concept | geometry1 | A model of the specified concept
Geometry2 const & | Any type fulfilling a Geometry Concept | geometry2 | A model of the specified concept

###### Returns

Returns true if two geometries crosses

###### Header

Either

`#include <boost/geometry.hpp>`

Or

`#include <boost/geometry/algorithms/crosses.hpp>`

###### Conformance

The function crosses implements function Crosses from the OGC Simple Feature Specification.

###### Supported geometries

| Point | Segment | Box | Linestring | Ring | Polygon | MultiPoint | MultiLinestring | MultiPolygon | Variant
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
Point |  |  |  |  |  |  |  |  |  |
Segment |  |  |  |  |  |  |  |  |  |
Box |  |  |  |  |  |  |  |  |  |
Linestring |  |  |  |  |  |  |  |  |  |
Ring |  |  |  |  |  |  |  |  |  |
Polygon |  |  |  |  |  |  |  |  |  |
MultiPoint |  |  |  |  |  |  |  |  |  |
MultiLinestring |  |  |  |  |  |  |  |  |  |
MultiPolygon |  |  |  |  |  |  |  |  |  |
Variant |  |  |  |  |  |  |  |  |  |

###### Examples

Checks if two geometries crosses

    #include <iostream>

    #include <boost/geometry.hpp>
    #include <boost/geometry/geometries/point_xy.hpp>
    #include <boost/geometry/geometries/polygon.hpp>

    namespace bg = boost::geometry;

    int main()
    {
        // Checks if the two geometries (here, a polygon and a linestring) crosses or not.
        bg::model::polygon<bg::model::d2::point_xy<double> > poly;
        bg::read_wkt("POLYGON((0 0,0 3,3 3,3 0,0 0))", poly);
        bg::model::linestring<bg::model::d2::point_xy<double> > line1;
        bg::read_wkt("LINESTRING(1 1,2 2,4 4)", line1);
        bool check_crosses = bg::crosses(poly, line1);
        if (check_crosses) {
             std::cout << "Crosses: Yes" << std::endl;
        } else {
            std::cout << "Crosses: No" << std::endl;
        }

        // Edge case: linestring just touches the polygon but doesn't crosses it.
        bg::model::linestring<bg::model::d2::point_xy<double> > line2;
        bg::read_wkt("LINESTRING(1 1,1 2,1 3)", line2);
        check_crosses = bg::crosses(poly, line2);
        if (check_crosses) {
             std::cout << "Crosses: Yes" << std::endl;
        } else {
            std::cout << "Crosses: No" << std::endl;
        }

        return 0;
    }

| Convenient namespace alias

Output:

    Crosses: Yes
    Crosses: No