10 #ifndef FMM_GEOMTYPES_HPP
11 #define FMM_GEOMTYPES_HPP
13 #include <ogrsf_frmts.h>
14 #include <boost/geometry.hpp>
27 typedef boost::geometry::model::point<double, 2,
28 boost::geometry::cs::cartesian>
Point;
46 inline double get_x(
int i)
const{
47 return boost::geometry::get<0>(line.at(i));
55 inline double get_y(
int i)
const{
56 return boost::geometry::get<1>(line.at(i));
63 inline void set_x(
int i,
double v){
64 boost::geometry::set<0>(line.at(i),v);
71 inline void set_y(
int i,
double v){
72 boost::geometry::set<1>(line.at(i),v);
80 boost::geometry::append(line,
Point(x,y));
87 boost::geometry::append(line, point);
99 return Point(boost::geometry::get<0>(
100 line.at(i)),boost::geometry::get<1>(line.at(i)));
116 return boost::geometry::num_points(line);
123 return boost::geometry::num_points(line)==0;
129 boost::geometry::clear(line);
136 return boost::geometry::length(line);
145 std::ostringstream ss;
146 ss << boost::geometry::wkt(line);
154 std::ostringstream ss;
157 ss <<
"{\"type\":\"LineString\",\"coordinates\": [";
158 for (
int i=0;i<N;++i){
159 ss <<
"[" <<
get_x(i) <<
"," <<
get_y(i) <<
"]"
160 << (i==N-1 ?
"":
",");
195 for (
int i=0;i<N;++i){
264 #endif // FMM_GEOMTYPES_HPP
void add_point(double x, double y)
Add a point to the end of the current line.
LineString ogr2linestring(const OGRLineString *line)
Convert a OGRLineString to a linestring.
std::string export_wkt() const
Export a string containing WKT representation of the line.
bool operator==(const LineString &rhs) const
Compare if two linestring are the same.
const linestring_t & get_geometry_const() const
Get a const reference to the inner boost geometry linestring.
std::ostream & operator<<(std::ostream &os, const FMM::CORE::LineString &rhs)
boost::geometry::model::linestring< Point > linestring_t
This is the boost geometry linestring class, stored inside the LineString class.
OGRLineString * linestring2ogr(const LineString &line)
Convert a linestring into a OGRLineString.
void set_y(int i, double v)
Set y coordinate of i-th point in the line.
friend std::ostream & operator<<(std::ostream &os, const LineString &rhs)
Overwrite the operator of << of linestring.
Point get_point(int i) const
Get the i-th point in the line.
void clear()
Remove all points in the current line.
void add_point(const Point &point)
Add a point to the end of the current line.
void set_x(int i, double v)
Set x coordinate of i-th point in the line.
std::string export_json() const
Export a string containing GeoJSON representation of the line.
Linestring geometry class.
bool is_empty()
Check if the line is empty or not.
double get_length() const
Get the length of the line.
OGRPoint * point2ogr(const Point &p)
Convert a point into a OGRPoint.
LineString wkt2linestring(const std::string &wkt)
Convert a wkt into a linestring.
const Point & at(int i) const
Get a constance reference of the i-th point in the line.
int get_num_points() const
Get the number of points in a line.
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > Point
Point class.
double get_y(int i) const
Get the y coordinate of i-th point in the line.
double get_x(int i) const
Get the x coordinate of i-th point in the line.
linestring_t & get_geometry()
Get a reference to the inner boost geometry linestring.