GeographicLib
1.21
|
Much (but not all!) of the useful functionality of GeographicLib is available via simple command line utilities. Interfaces to some of them are available via the web. See Utility programs for documentation on these.
In order to use GeographicLib from C++ code, you will need to
#include <GeographicLib/LambertConformalConic.hpp>
using namespace GeographicLib;
g++ -c -g -O3 -I/usr/local/include testprogram.cpp
C/C++ -> General -> Additional Include Directories = C:\pkg-vc10\GeographicLib\include
g++ -g -o testprogram testprogram.o -L/usr/local/lib -lGeographic
Linker -> Input -> Additional Dependencies = Geographic.lib Linker -> General -> Additional Library Directories = C:\pkg-vc10\GeographicLib\lib
g++ -g -o testprogram testprogram.o -Wl,-rpath=/usr/local/lib -L/usr/local/lib -lGeographic
LD_LIBRARY_PATH
to be a colon-separated list of directories to search; (2) as root, specify /usr/local/lib as a directory searched by ldconfig(8).) On Windows, you need to ensure that Geographic.dll is in the same directory as your executable or else include the directory containing the dll in your PATH
.# Put in your top-level CMakeLists.txt find_package (GeographicLib 1.9 REQUIRED) # In the top-level CMakeLists.txt or wherever your code is compiled include_directories (${GeographicLib_INCLUDE_DIRS}) # In the CMakeLists.txt where you define your executable targets target_link_libraries (program1 ${GeographicLib_LIBRARIES}) target_link_libraries (program2 ${GeographicLib_LIBRARIES})
GEOGRAPHICLIB_FOUND = TRUE
). For find_package to be able to locate GeographicLib, it may be necessary for GeographicLib to be built and installed with cmake (see Installation with cmake) instead of using some other installation method. In addition, on Windows systems, you should specify CMAKE_PREFIX_PATH
with, for example, cmake -G "Visual Studio 10" -D CMAKE_PREFIX_PATH=C:/pkg-vc10 -D CMAKE_INSTALL_PREFIX=C:/pkg-vc10/XYZProject ..
CMAKE_MODULE_PATH
in order for find_package to work. However, this method has not been thoroughly tested.)Here is a very simple test code, which uses the GeographicLib::Geodesic class:
// Small example of using the GeographicLib::Geodesic class // $Id: 23959b26e8023e42f76afabf7a2d7b593666a71a $ #include <iostream> #include <GeographicLib/Geodesic.hpp> using namespace std; using namespace GeographicLib; int main() { const Geodesic& geod = Geodesic::WGS84; // Distance from JFK to LHR double lat1 = 40.6, lon1 = -73.8, // JFK Airport lat2 = 51.6, lon2 = -0.5; // LHR Airport double s12; geod.Inverse(lat1, lon1, lat2, lon2, s12); cout << s12 / 1000 << " km\n"; return 0; }
This example is examples/example-Geodesic-small.cpp
. If you compile, link, and run it according to the instructions above, it should print out
5551.76 km
The next steps are:
Here's a list of some of the abbreviations used here with links to the corresponding Wikipedia articles: