Skip to content

Commit

Permalink
expose mercator projection functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lonvia committed Aug 6, 2018
1 parent 2b6c45c commit 3b3172b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/geom.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <boost/python.hpp>

#include <osmium/geom/mercator_projection.hpp>
#include <osmium/geom/coordinates.hpp>
#include <osmium/geom/haversine.hpp>
#include <osmium/geom/factory.hpp>
#include <osmium/geom/wkb.hpp>
Expand Down Expand Up @@ -38,6 +40,23 @@ BOOST_PYTHON_MODULE(geom)
"curvature of earth into account. If a :py:class:`WayNodeList` is given "
"as a parameter the total length of the way in meters is computed.");

def("lonlat_to_mercator", &osmium::geom::lonlat_to_mercator,
arg("coordinate"),
"Convert coordinates from WGS84 to Mercator projection.");

def("mercator_to_lonlat", &osmium::geom::mercator_to_lonlat,
arg("coordinate"),
"Convert coordinates from WGS84 to Mercator projection.");

class_<osmium::geom::Coordinates>("Coordinates",
"A pair of coordiante values.")
.def(init<double, double>())
.def(init<osmium::Location const &>())
.add_property("x", &osmium::geom::Coordinates::x)
.add_property("y", &osmium::geom::Coordinates::y)
.def("valid", &osmium::geom::Coordinates::valid,
"Coordinates are invalid if they have been default constructed.");

class_<WKBFactory>("WKBFactory",
"Factory that creates WKB from osmium geometries.")
.add_property("epsg", &WKBFactory::epsg,
Expand Down
19 changes: 19 additions & 0 deletions test/test_geom.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,22 @@ def area(self, a):

def check_result(self):
assert_equals(1, len(self.handler.wkbs))

class TestCoordinateConversion(unittest.TestCase):

def test_lonlat_to_mercator(self):
c = o.geom.lonlat_to_mercator(o.geom.Coordinates(0,0))
assert_equals(c.x, 0)
assert_equals(c.y, 0)

def test_mercator_lonlat(self):
c = o.geom.mercator_to_lonlat(o.geom.Coordinates(0,0))
assert_equals(c.x, 0)
assert_equals(c.y, 0)

class TestCoordinates(unittest.TestCase):

def test_coordinate_from_location(self):
c = o.geom.Coordinates(o.osm.Location(10.0, -3.0))
assert_equals(c.x, 10.0)
assert_equals(c.y, -3.0)

0 comments on commit 3b3172b

Please sign in to comment.