简体   繁体   中英

library in C/C++ for location search

I have a set of latitude and longitudes for a given Place which depict the place. The set of latitude and longitude for London is given below (of the form (lat,long)):

(36.47606,-119.44318), (43.63457, -123.09285), (36.48091, -119.44401), (10.36389, -66.73333), (-24.81667,31.05), (-24.76667, 30.86667), (-24.3,30.58333).

Now I want to create a region out of the points given above: such that given another set of (lat,long) points -- I can find out whether the two points:

  1. Intersect or not.
  2. Whether one set of points is inside another set of points.

I tried using Boost's R-tree library for the same -- but the library only lets me specify a rectangle, whereas I want to form a polygon out of points. Is there some library in C/c++ which would let me get the desired functionality. If yes, can someone please illustrate the same with the help of an example. Or if I am going wrong somewhere with using Boost -- then can someone please help me correct it.

http://www.boost.org/doc/libs/1_53_0/libs/geometry/doc/html/geometry/reference/algorithms/intersects/intersects_2_two_geometries.html has an example of using Boost geometry to detect intersection of polygons, with the function being:

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

Their example can be summarised as:

boost::geometry::read_wkt("linestring(1 1,2 2,3 3)", line1);
boost::geometry::read_wkt("linestring(2 1,1 2,4 0)", line2);

bool b = boost::geometry::intersects(line1, line2);

std::cout << "Intersects: " << (b ? "YES" : "NO") << std::endl;

For the second issue of detecting whether a set of points is inside another set of points, http://www.boost.org/doc/libs/1_54_0/libs/geometry/doc/html/geometry/reference/algorithms/within/within_2.html seems a relevant reference to their within function:

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

In this case their example is:

polygon_type poly;
boost::geometry::read_wkt(
    "POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)"
        "(4.0 2.0, 4.2 1.4, 4.8 1.9, 4.4 2.2, 4.0 2.0))", poly);

point_type p(4, 1);

std::cout << "within: " << (boost::geometry::within(p, poly) ? "yes" : "no") << std::endl;

Read the latest documentation to check the restrictions on geometries currently supported by within - currently it appears the internal geometry can only be a point or box

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM