ADD: new track message, Entity class and Position class
This commit is contained in:
57
libs/geographiclib/wrapper/python/CMakeLists.txt
Normal file
57
libs/geographiclib/wrapper/python/CMakeLists.txt
Normal file
@@ -0,0 +1,57 @@
|
||||
cmake_minimum_required (VERSION 3.13.0)
|
||||
project (PyGeographicLib)
|
||||
|
||||
# Set a default build type for single-configuration cmake generators if
|
||||
# no build type is set.
|
||||
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
|
||||
set (CMAKE_BUILD_TYPE Release)
|
||||
endif ()
|
||||
|
||||
# Make the compiler more picky.
|
||||
if (MSVC)
|
||||
string (REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
else ()
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
||||
endif ()
|
||||
|
||||
# The version of python that boost-python uses. Also used for the
|
||||
# installation directory.
|
||||
set (PYTHON_VERSION 2.7)
|
||||
|
||||
# Requires python + python devel
|
||||
find_package (PythonLibs ${PYTHON_VERSION} REQUIRED)
|
||||
|
||||
# Required boost-python + boost-devel
|
||||
find_package (Boost REQUIRED COMPONENTS python)
|
||||
|
||||
find_package (GeographicLib REQUIRED COMPONENTS SHARED)
|
||||
|
||||
include_directories (${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
|
||||
|
||||
add_library (${PROJECT_NAME} MODULE ${PROJECT_NAME}.cpp)
|
||||
|
||||
get_target_property (GEOGRAPHICLIB_LIB_TYPE ${GeographicLib_LIBRARIES} TYPE)
|
||||
if (GEOGRAPHICLIB_LIB_TYPE STREQUAL "SHARED_LIBRARY")
|
||||
if (WIN32)
|
||||
add_custom_command (TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E
|
||||
copy $<TARGET_FILE:${GeographicLib_LIBRARIES}> ${CMAKE_CFG_INTDIR}
|
||||
COMMENT "Installing shared library in build tree")
|
||||
else ()
|
||||
# Set the run time path for shared libraries for non-Windows machines.
|
||||
set_target_properties (${PROJECT_NAME}
|
||||
PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Don't include the "lib" prefix on the output name
|
||||
set_target_properties (${PROJECT_NAME} PROPERTIES PREFIX "")
|
||||
target_link_libraries (${PROJECT_NAME} ${GeographicLib_LIBRARIES}
|
||||
${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
|
||||
|
||||
install (TARGETS ${PROJECT_NAME} LIBRARY
|
||||
# if CMAKE_INSTALL_PREFIX=~/.local then this specifies a directory in
|
||||
# the default path.
|
||||
DESTINATION lib/python${PYTHON_VERSION}/site-packages)
|
||||
21
libs/geographiclib/wrapper/python/PyGeographicLib.cpp
Normal file
21
libs/geographiclib/wrapper/python/PyGeographicLib.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <boost/python.hpp>
|
||||
#include <GeographicLib/Geoid.hpp>
|
||||
|
||||
using namespace boost::python;
|
||||
using namespace GeographicLib;
|
||||
|
||||
double EllipsoidHeight(Geoid& geoid,
|
||||
double lat, double lon, double hmsl) {
|
||||
return hmsl + Geoid::GEOIDTOELLIPSOID * geoid(lat, lon);
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(PyGeographicLib) {
|
||||
|
||||
class_<Geoid, boost::noncopyable>("Geoid", init<std::string>())
|
||||
.def("EllipsoidHeight", &EllipsoidHeight,
|
||||
"Return geoid height:\n\
|
||||
input: lat, lon, height_above_geoid\n\
|
||||
output: height_above_ellipsoid")
|
||||
;
|
||||
|
||||
}
|
||||
85
libs/geographiclib/wrapper/python/README.md
Normal file
85
libs/geographiclib/wrapper/python/README.md
Normal file
@@ -0,0 +1,85 @@
|
||||
# Calling the GeographicLib C++ library from Python
|
||||
|
||||
The geodesic routines in GeographicLib have been implemented as a
|
||||
[native Python library](http://pypi.python.org/pypi/geographiclib).
|
||||
For documentation see
|
||||
|
||||
https://geographiclib.sourceforge.io/Python/doc/
|
||||
|
||||
## boost-python
|
||||
|
||||
It is also possible to call the C++ version of GeographicLib directly
|
||||
from Python and this directory contains a small example,
|
||||
`PyGeographicLib.cpp`, which uses boost-python and the `Geoid` class to
|
||||
convert heights above the geoid to heights above the ellipsoid. More
|
||||
information on calling boost-python, see
|
||||
|
||||
https://www.boost.org/doc/libs/release/libs/python
|
||||
|
||||
To build and install this interface, do
|
||||
```bash
|
||||
mkdir BUILD
|
||||
cd BUILD
|
||||
cmake -D CMAKE_INSTALL_PREFIX=~/.local ..
|
||||
make
|
||||
make install
|
||||
```
|
||||
This assumes that you have installed GeographicLib somewhere that cmake
|
||||
can find it. If you want just to use the version of GeographicLib that
|
||||
you have built in the top-level BUILD directory, include, e.g.,
|
||||
```bash
|
||||
-D GeographicLib_DIR=../../BUILD
|
||||
```
|
||||
in the invocation of cmake (the directory is relative to the source
|
||||
directory, wrapper/python).
|
||||
|
||||
`make install` installs PyGeographicLib in
|
||||
```
|
||||
~/.local/lib/python2.7/site-packages
|
||||
```
|
||||
which is in the default search path for python 2.7. To convert 20m
|
||||
above the geoid at 42N 75W to a height above the ellipsoid, do
|
||||
```python
|
||||
$ python
|
||||
>>> from PyGeographicLib import Geoid
|
||||
>>> geoid = Geoid("egm2008-1")
|
||||
>>> geoid.EllipsoidHeight(42, -75, 20)
|
||||
-10.671887499999997
|
||||
>>> help(Geoid.EllipsoidHeight)
|
||||
```
|
||||
|
||||
Notes:
|
||||
|
||||
* The geoid data (`egm2008-1`) should be installed somewhere that
|
||||
GeographicLib knows about.
|
||||
|
||||
* This prescription applies to Linux machines. Similar steps can be
|
||||
used on Windows and MacOSX machines.
|
||||
|
||||
* You will need the packages boost-python, boost-devel, python, and
|
||||
python-devel installed.
|
||||
|
||||
* `CMakeLists.txt` specifies the version of python to look for (version
|
||||
2.7). This must match that used in boost-python. To check do, e.g.,
|
||||
```bash
|
||||
ldd /usr/lib64/libboost_python.so
|
||||
```
|
||||
|
||||
* `CMakeLists.txt` looks for a shared-library version of GeographicLib.
|
||||
This is the default with cmake build on non-Windows platforms. On
|
||||
Windows, use the cmake option `-D BUILD_SHARED_LIBS=ON` to specify
|
||||
building a shared library.
|
||||
|
||||
Acknowledgment:
|
||||
|
||||
Thanks to Jonathan Takahashi <jtakahashi@gmail.com> for the sample code
|
||||
in PyGeographicLib.cpp and the commands needed to compile and link this.
|
||||
|
||||
## Cython
|
||||
|
||||
An alternative to boost-python is provided by [Cython](https::/cython.org).
|
||||
Sergey Serebryakov offers the github project
|
||||
|
||||
https://github.com/megaserg/geographiclib-cython-bindings
|
||||
|
||||
which provides a fast python interface to the geodesic routines.
|
||||
Reference in New Issue
Block a user