barbeau / earth-gravitational-model

A lightweight port of the GeoTools EarthGravitationalModel (http://docs.geotools.org/latest/javadocs/org/geotools/referencing/operation/transform/EarthGravitationalModel.html).
GNU Lesser General Public License v2.1
17 stars 7 forks source link

earth-gravitational-model Java CI with Gradle

A lightweight port of the GeoTools EarthGravitationalModel (source code) that can be used on Android without requiring the entire GeoTools suite.

From the original EarthGravitationalModel.java file:

This class transforms vertical coordinates using coefficients from the Earth Gravitational Model. This class is an adaption of Fortran code clenqt.for from the National Geospatial-Intelligence Agency and available in public domain. The normalized geopotential coefficients file bundled in this module is an adaptation of egm180.nor file, with some spaces trimmed.

The egm180.nor file is included in src/main/resources directory in this project, which appears to be the EGM84 model.

Releases are published using the GitHub Package Registry.

NOTE: You need to authenticate with GitHub to download the below artifacts

Maven

<repositories>
    <repository>
        <id>github</id>
        <name>GitHub earth-gravitational-model</name>
        <url>https://maven.pkg.github.com/barbeau/earth-gravitational-model</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </repository>
</repositories>
...
<dependency>
    <groupId>com.barbeaudev</groupId>
    <artifactId>earth-gravitational-model</artifactId>
    <version>1.0.0</version>
</dependency>

Gradle

repositories {
    maven { url 'https://maven.pkg.github.com/barbeau/earth-gravitational-model' }
}

dependencies {
    implementation 'com.barbeaudev:earth-gravitational-model:1.0.0'
}

Requirements

You'll need JDK 8 or higher.

Usage

The below example shows how to use the EarthGravitationalModel.

EarthGravitationalModel gh = new EarthGravitationalModel();
gh.load("/egm180.nor");

// GPS lat, lon, and altitude
double lat = 45;
double lon = 45;
double altitudeWgs84 = 0;

// Calculate the offset between the ellipsoid and geoid
double offset = gh.heightOffset(lon, lat, altitudeWgs84);

// Add the offset to the GPS altitude to get the height above the geoid (in meters)
double altitudeMeanSeaLevel = altitudeWgs84 - offset;

Compiling the code yourself

Setting up your environment

This project was created in IntelliJ. You can also compile it from the command line using Gradle.

Getting the code

To get started with this project, use a Git client to clone this repository to your local computer. Then, in IntelliJ import the project as a Gradle project.

Build the project

Releases

  1. Change version from x-SNAPSHOT to x
  2. Create a tag using Git
  3. Create a GitHub release using that tag
  4. Change version from x to nextversion-SNAPSHOT

The GitHub Action publish.yml will then automatically create and publish a package for the GitHub Package Registry as soon as the Release is published.

License

This project is a port of the GeoTools EarthGravitationalModel (source code) and therefore inherits the LGPL license from that project.