Skip to content

Commit

Permalink
Remove dependency on boost geometry wkb extension (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyang-kth authored Nov 25, 2020
1 parent c237fe5 commit 2d87a19
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 1,390 deletions.
44 changes: 14 additions & 30 deletions src/core/geometry.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* 2020-11-25 Remove linestring2ogr, wkb dependency
*/

#include "core/geometry.hpp"

#include <ogrsf_frmts.h> // C++ API for GDAL
Expand All @@ -7,34 +11,30 @@
#include <vector>
#include <sstream>

#include "boost/geometry/extensions/gis/io/wkb/read_wkb.hpp"
#include "boost/geometry/extensions/gis/io/wkb/write_wkb.hpp"

std::ostream& FMM::CORE::operator<<(std::ostream& os,
const FMM::CORE::LineString& rhs){
os<< std::setprecision(12) << boost::geometry::wkt(rhs.line);
return os;
};

FMM::CORE::LineString FMM::CORE::ogr2linestring(const OGRLineString *line){
int binary_size = line->WkbSize();
std::vector<unsigned char> wkb(binary_size);
// http://www.gdal.org/ogr__core_8h.html#a36cc1f4d807ba8f6fb8951f3adf251e2
line->exportToWkb(wkbNDR,&wkb[0]);
LineString l;
boost::geometry::read_wkb(wkb.begin(),wkb.end(),l.get_geometry());
FMM::CORE::LineString l;
int Npoints = line->getNumPoints();
for (int i=0;i<Npoints;++i){
l.add_point(line->getX(i),line->getY(i));
}
return l;
};

FMM::CORE::LineString FMM::CORE::ogr2linestring(
const OGRMultiLineString *mline){
FMM::CORE::LineString l;
if (!mline->IsEmpty() && mline->getNumGeometries()>0){
const OGRGeometry *line = mline->getGeometryRef(0);
int binary_size = line->WkbSize();
std::vector<unsigned char> wkb(binary_size);
line->exportToWkb(wkbNDR,&wkb[0]);
boost::geometry::read_wkb(wkb.begin(),wkb.end(),l.get_geometry());
const OGRLineString *line = (OGRLineString *) mline->getGeometryRef(0);
int Npoints = line->getNumPoints();
for (int i=0;i<Npoints;++i){
l.add_point(line->getX(i),line->getY(i));
}
}
return l;
};
Expand All @@ -44,19 +44,3 @@ FMM::CORE::LineString FMM::CORE::wkt2linestring(const std::string &wkt){
boost::geometry::read_wkt(wkt,line.get_geometry());
return line;
};

OGRLineString *FMM::CORE::linestring2ogr(const FMM::CORE::LineString &line){
std::vector<unsigned char> wkb;
boost::geometry::write_wkb(line.get_geometry_const(),std::back_inserter(wkb));
OGRGeometry *poGeometry;
OGRGeometryFactory::createFromWkb(&wkb[0], NULL, &poGeometry);
return (OGRLineString *) poGeometry;
};

OGRPoint *FMM::CORE::point2ogr(const FMM::CORE::Point &p){
std::vector<unsigned char> wkb;
boost::geometry::write_wkb(p,std::back_inserter(wkb));
OGRGeometry *poGeometry;
OGRGeometryFactory::createFromWkb(&wkb[0], NULL, &poGeometry);
return (OGRPoint *) poGeometry;
};
17 changes: 1 addition & 16 deletions src/core/geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Fast map matching.
*
* Definition of geometry
* 2020-11-25 Remove linestring2ogr
*
* @author: Can Yang
* @version: 2017.11.11
Expand Down Expand Up @@ -240,22 +241,6 @@ LineString ogr2linestring(const OGRMultiLineString *mline);
*/
LineString wkt2linestring(const std::string &wkt);

/**
* Convert a linestring into a OGRLineString
* @param line input line
* @return A OGRLineString, the caller is responsible for
* freeing the memory.
*/
OGRLineString *linestring2ogr(const LineString &line);

/**
* Convert a point into a OGRPoint
* @param p input point
* @return A OGRPoint, the caller is responsible for
* freeing the memory.
*/
OGRPoint *point2ogr(const Point &p);

}; // CORE

}; // FMM
Expand Down
262 changes: 0 additions & 262 deletions third_party/boost/geometry/extensions/gis/io/wkb/detail/endian.hpp

This file was deleted.

Loading

0 comments on commit 2d87a19

Please sign in to comment.