ADD: new track message, Entity class and Position class
This commit is contained in:
39
libs/geographiclib/wrapper/c/CMakeLists.txt
Normal file
39
libs/geographiclib/wrapper/c/CMakeLists.txt
Normal file
@@ -0,0 +1,39 @@
|
||||
cmake_minimum_required (VERSION 3.13.0)
|
||||
project (geoidtest)
|
||||
|
||||
# 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")
|
||||
string (REGEX REPLACE "/W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
|
||||
else ()
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra")
|
||||
endif ()
|
||||
|
||||
find_package (GeographicLib REQUIRED COMPONENTS SHARED)
|
||||
|
||||
add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c cgeoid.cpp)
|
||||
target_link_libraries (${PROJECT_NAME} ${GeographicLib_LIBRARIES})
|
||||
|
||||
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 ()
|
||||
52
libs/geographiclib/wrapper/c/README.md
Normal file
52
libs/geographiclib/wrapper/c/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Calling the GeographicLib C++ library from C
|
||||
|
||||
The geodesic routines in GeographicLib have been implemented as a native
|
||||
C library. See
|
||||
|
||||
https://geographiclib.sourceforge.io/C/doc/
|
||||
|
||||
It is also possible to call the C++ version of GeographicLib directly
|
||||
from C and this directory contains a small example, which convert
|
||||
heights above the geoid to heights above the ellipsoid. More
|
||||
information on calling C++ from C, see
|
||||
|
||||
https://isocpp.org/wiki/faq/mixing-c-and-cpp
|
||||
|
||||
To build and install this interface, do
|
||||
```bash
|
||||
mkdir BUILD
|
||||
cd BUILD
|
||||
cmake ..
|
||||
make
|
||||
```
|
||||
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/C). To convert 20m above the geoid at 42N 75W to a
|
||||
height above the ellipsoid, use
|
||||
```bash
|
||||
$ echo 42 -75 20 | ./geoidtest
|
||||
-10.672
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
* It is essential that the application be linked with the C++ compiler,
|
||||
so that the C++ runtime library is included.
|
||||
|
||||
* In this example, the main program is compiled with the C compiler. In
|
||||
more complicated situations, it may be necessary to use the C++
|
||||
compiler. This is necessary to get static initializations of C++
|
||||
classes performed. (However, GeographicLib doesn't need any static
|
||||
initialization.)
|
||||
14
libs/geographiclib/wrapper/c/cgeoid.cpp
Normal file
14
libs/geographiclib/wrapper/c/cgeoid.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "cgeoid.h"
|
||||
#include "GeographicLib/Geoid.hpp"
|
||||
|
||||
extern "C"
|
||||
double HeightAboveEllipsoid(double lat, double lon, double h) {
|
||||
try {
|
||||
// Declare static so that g is only constructed once
|
||||
static const GeographicLib::Geoid g("egm2008-1");
|
||||
return h + GeographicLib::Geoid::GEOIDTOELLIPSOID * g(lat, lon);
|
||||
}
|
||||
catch (...) {
|
||||
return GeographicLib::Math::NaN();
|
||||
}
|
||||
}
|
||||
9
libs/geographiclib/wrapper/c/cgeoid.h
Normal file
9
libs/geographiclib/wrapper/c/cgeoid.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#if !defined(CGEOID_H)
|
||||
#define CGEOID_H 1
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
#endif
|
||||
double HeightAboveEllipsoid(double lat, double lon, double h);
|
||||
|
||||
#endif /* CGEOID_H */
|
||||
13
libs/geographiclib/wrapper/c/geoidtest.c
Normal file
13
libs/geographiclib/wrapper/c/geoidtest.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include "cgeoid.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
/* Squelch warnings about scanf */
|
||||
# pragma warning (disable: 4996)
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
double lat, lon, h;
|
||||
while(scanf("%lf %lf %lf", &lat, &lon, &h) == 3)
|
||||
printf("%.3f\n", HeightAboveEllipsoid(lat, lon, h));
|
||||
}
|
||||
Reference in New Issue
Block a user