Fast map matching  0.1.0
geometry.cpp
1 #include "core/geometry.hpp"
2 
3 #include <ogrsf_frmts.h> // C++ API for GDAL
4 #include <boost/geometry.hpp>
5 #include <boost/geometry/geometries/geometries.hpp>
6 #include <iterator>
7 #include <vector>
8 #include <sstream>
9 
10 #include "boost/geometry/extensions/gis/io/wkb/read_wkb.hpp"
11 #include "boost/geometry/extensions/gis/io/wkb/write_wkb.hpp"
12 
13 std::ostream& FMM::CORE::operator<<(std::ostream& os,
14  const FMM::CORE::LineString& rhs){
15  os<< std::setprecision(12) << boost::geometry::wkt(rhs.line);
16  return os;
17 };
18 
20  int binary_size = line->WkbSize();
21  std::vector<unsigned char> wkb(binary_size);
22  // http://www.gdal.org/ogr__core_8h.html#a36cc1f4d807ba8f6fb8951f3adf251e2
23  line->exportToWkb(wkbNDR,&wkb[0]);
24  LineString l;
25  boost::geometry::read_wkb(wkb.begin(),wkb.end(),l.get_geometry());
26  return l;
27 };
28 
30  const OGRMultiLineString *mline){
32  if (!mline->IsEmpty() && mline->getNumGeometries()>0){
33  const OGRGeometry *line = mline->getGeometryRef(0);
34  int binary_size = line->WkbSize();
35  std::vector<unsigned char> wkb(binary_size);
36  line->exportToWkb(wkbNDR,&wkb[0]);
37  boost::geometry::read_wkb(wkb.begin(),wkb.end(),l.get_geometry());
38  }
39  return l;
40 };
41 
44  boost::geometry::read_wkt(wkt,line.get_geometry());
45  return line;
46 };
47 
49  std::vector<unsigned char> wkb;
50  boost::geometry::write_wkb(line.get_geometry_const(),std::back_inserter(wkb));
51  OGRGeometry *poGeometry;
52  OGRGeometryFactory::createFromWkb(&wkb[0], NULL, &poGeometry);
53  return (OGRLineString *) poGeometry;
54 };
55 
57  std::vector<unsigned char> wkb;
58  boost::geometry::write_wkb(p,std::back_inserter(wkb));
59  OGRGeometry *poGeometry;
60  OGRGeometryFactory::createFromWkb(&wkb[0], NULL, &poGeometry);
61  return (OGRPoint *) poGeometry;
62 };
FMM::CORE::ogr2linestring
LineString ogr2linestring(const OGRLineString *line)
Convert a OGRLineString to a linestring.
Definition: geometry.cpp:19
FMM::CORE::LineString::get_geometry_const
const linestring_t & get_geometry_const() const
Get a const reference to the inner boost geometry linestring.
Definition: geometry.hpp:170
FMM::CORE::operator<<
std::ostream & operator<<(std::ostream &os, const FMM::CORE::LineString &rhs)
Definition: geometry.cpp:13
FMM::CORE::linestring2ogr
OGRLineString * linestring2ogr(const LineString &line)
Convert a linestring into a OGRLineString.
Definition: geometry.cpp:48
FMM::CORE::LineString
Linestring geometry class.
Definition: geometry.hpp:34
FMM::CORE::point2ogr
OGRPoint * point2ogr(const Point &p)
Convert a point into a OGRPoint.
Definition: geometry.cpp:56
FMM::CORE::wkt2linestring
LineString wkt2linestring(const std::string &wkt)
Convert a wkt into a linestring.
Definition: geometry.cpp:42
FMM::CORE::Point
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Point class.
Definition: geometry.hpp:28
FMM::CORE::LineString::get_geometry
linestring_t & get_geometry()
Get a reference to the inner boost geometry linestring.
Definition: geometry.hpp:177