Add EGM96 Worldwide support
This commit is contained in:
parent
e3220561ec
commit
680da146b8
3 changed files with 75 additions and 4 deletions
|
@ -0,0 +1,57 @@
|
|||
package net.osmand;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
public class GeoidAltitudeCorrection {
|
||||
|
||||
private final Log log = LogUtil.getLog(GeoidAltitudeCorrection.class);
|
||||
private File f;
|
||||
private RandomAccessFile rf;
|
||||
private final static String fileName = "WW15MGH.DAC";
|
||||
|
||||
private int cachedPointer = -1;
|
||||
private short cachedValue = 0;
|
||||
|
||||
public GeoidAltitudeCorrection(File dir) {
|
||||
this.f = new File(dir, fileName);
|
||||
if(f.exists()){
|
||||
try {
|
||||
rf = new RandomAccessFile(f, "r");
|
||||
} catch (FileNotFoundException e) {
|
||||
log.error("Error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isGeoidInformationAvailable(){
|
||||
return rf != null;
|
||||
}
|
||||
|
||||
public float getGeoidHeight(double lat, double lon) {
|
||||
if (!isGeoidInformationAvailable()) {
|
||||
return 0;
|
||||
}
|
||||
int shy = (int) Math.floor((90 - lat) * 4);
|
||||
int shx = (int) Math.floor((lon >= 0 ? lon : lon + 360) * 4);
|
||||
int pointer = ((shy * 1440) + shx) * 2;
|
||||
short res = 0;
|
||||
if (pointer != cachedPointer) {
|
||||
try {
|
||||
rf.seek(pointer);
|
||||
cachedValue = rf.readShort();
|
||||
cachedPointer = pointer;
|
||||
} catch (IOException e) {
|
||||
log.error("Geoid info error", e);
|
||||
}
|
||||
}
|
||||
res = cachedValue;
|
||||
return res / 100f;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ import java.util.Set;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.GeoidAltitudeCorrection;
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
|
@ -260,6 +261,7 @@ public class ResourceManager {
|
|||
|
||||
protected StringBuilder builder = new StringBuilder(40);
|
||||
protected char[] tileId = new char[120];
|
||||
private GeoidAltitudeCorrection geoidAltitudeCorrection;
|
||||
|
||||
public synchronized String calculateTileId(ITileSource map, int x, int y, int zoom) {
|
||||
builder.setLength(0);
|
||||
|
@ -383,6 +385,7 @@ public class ResourceManager {
|
|||
// check we have some assets to copy to sdcard
|
||||
warnings.addAll(checkAssets(progress));
|
||||
initRenderers(progress);
|
||||
geoidAltitudeCorrection = new GeoidAltitudeCorrection(context.getSettings().extendOsmandPath(APP_DIR));
|
||||
// do it lazy
|
||||
// indexingImageTiles(progress);
|
||||
warnings.addAll(indexingMaps(progress));
|
||||
|
@ -958,7 +961,11 @@ public class ResourceManager {
|
|||
renderer.clearCache();
|
||||
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
public GeoidAltitudeCorrection getGeoidAltitudeCorrection() {
|
||||
return geoidAltitudeCorrection;
|
||||
}
|
||||
|
||||
|
||||
protected synchronized void clearTiles() {
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.views;
|
|||
import java.util.Arrays;
|
||||
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.GeoidAltitudeCorrection;
|
||||
import net.osmand.OsmAndFormatter;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -269,15 +270,21 @@ public class RouteInfoControls {
|
|||
}
|
||||
|
||||
protected TextInfoControl createAltitudeControl(final MapActivity map, Paint paintText, Paint paintSubText) {
|
||||
final GeoidAltitudeCorrection geo = map.getMyApplication().getResourceManager().getGeoidAltitudeCorrection();
|
||||
final TextInfoControl altitudeControl = new TextInfoControl(map, 0, paintText, paintSubText) {
|
||||
private int cachedAlt = 0;
|
||||
|
||||
@Override
|
||||
public boolean updateInfo() {
|
||||
// draw speed
|
||||
if (map.getLastKnownLocation() != null && map.getLastKnownLocation().hasAltitude()) {
|
||||
if (cachedAlt != (int) map.getLastKnownLocation().getAltitude()) {
|
||||
cachedAlt = (int) map.getLastKnownLocation().getAltitude();
|
||||
Location loc = map.getLastKnownLocation();
|
||||
if (loc != null && loc.hasAltitude()) {
|
||||
double compAlt = loc.getAltitude();
|
||||
if(geo != null){
|
||||
compAlt -= geo.getGeoidHeight(loc.getLatitude(), loc.getLongitude());
|
||||
}
|
||||
if (cachedAlt != (int) compAlt) {
|
||||
cachedAlt = (int) compAlt;
|
||||
String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, map);
|
||||
int ls = ds.lastIndexOf(' ');
|
||||
if (ls == -1) {
|
||||
|
|
Loading…
Reference in a new issue