Advertisement
ytg

boost question 111011

ytg
Oct 12th, 2011
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. //bad code for StackOverflow question (http://goo.gl/Szsa5) DO NOT USE IT!
  2. #include <vector>
  3. #include <boost/range.hpp>
  4. #include <boost/geometry.hpp>
  5. #include <boost/geometry/geometries/polygon.hpp>
  6.  
  7. using namespace boost::geometry;
  8.  
  9. typedef boost::geometry::model::point
  10.     <
  11.         double, 2, boost::geometry::cs::spherical_equatorial<boost::geometry::degree>
  12.     > spherical_point;
  13.  
  14. //[in]  resultVector: this should be the result of an intersection
  15. //[out] x, y: these arrays contain the result coordinates
  16. //[out] count: this should be the length of the arrays
  17. void PolygonToArrays(std::vector<model::polygon<spherical_point> > resultVector, double x[], double y[], int *count)
  18. {
  19.     *count = resultVector.size();
  20.     x = (double*) malloc(sizeof(double) * *count);
  21.     y = (double*) malloc(sizeof(double) * *count);
  22.     int i = 0;
  23.     for (std::vector<model::polygon<spherical_point> >::iterator it = resultVector.begin(); it != resultVector.end(); ++it)
  24.     {
  25.         if (boost::size(*it) >= 2)
  26.         {
  27.             //and here comes the problematic part...
  28.             typedef typename boost::range_iterator<model::ring<spherical_point> >::type iterator;
  29.             for (iterator current = boost::begin(*it); current != boost::end(*it); ++current)
  30.             {
  31.                 x[i] = get<0>(current);
  32.                 y[i] = get<1>(current);
  33.                 i++;
  34.             }
  35.             //I only need the first polygon, so let's break here
  36.             break;
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement