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 ofegm180.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
<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>
repositories {
maven { url 'https://maven.pkg.github.com/barbeau/earth-gravitational-model' }
}
dependencies {
implementation 'com.barbeaudev:earth-gravitational-model:1.0.0'
}
You'll need JDK 8 or higher.
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;
This project was created in IntelliJ. You can also compile it from the command line using Gradle.
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.
./gradlew build
x-SNAPSHOT to x
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.
This project is a port of the GeoTools EarthGravitationalModel (source code) and therefore inherits the LGPL license from that project.