srtm-update
This commit is contained in:
parent
d277db0bd1
commit
19fd3112bf
6 changed files with 845 additions and 136 deletions
|
|
@ -1,9 +1,11 @@
|
|||
package btools.mapcreator;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
|
||||
import btools.util.CompactLongSet;
|
||||
|
|
@ -13,10 +15,8 @@ import btools.util.FrozenLongSet;
|
|||
/**
|
||||
* PosUnifier does 3 steps in map-processing:
|
||||
*
|
||||
* - unify positions
|
||||
* - add srtm elevation data
|
||||
* - make a bordernodes file containing net data
|
||||
* from the bordernids-file just containing ids
|
||||
* - unify positions - add srtm elevation data - make a bordernodes file
|
||||
* containing net data from the bordernids-file just containing ids
|
||||
*
|
||||
* @author ab
|
||||
*/
|
||||
|
|
@ -27,21 +27,20 @@ public class PosUnifier extends MapCreatorBase
|
|||
private File nodeTilesOut;
|
||||
private CompactLongSet positionSet;
|
||||
|
||||
private HashMap<String,SrtmData> srtmmap ;
|
||||
private HashMap<String, SrtmRaster> srtmmap;
|
||||
private int lastStrmLonIdx;
|
||||
private int lastStrmLatIdx;
|
||||
private SrtmData lastSrtmData;
|
||||
private SrtmRaster lastSrtmRaster;
|
||||
private String srtmdir;
|
||||
|
||||
private CompactLongSet borderNids;
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
System.out.println("*** PosUnifier: Unify position values and enhance elevation");
|
||||
if (args.length != 5)
|
||||
System.out.println( "*** PosUnifier: Unify position values and enhance elevation" );
|
||||
if ( args.length != 5 )
|
||||
{
|
||||
System.out.println("usage: java PosUnifier <node-tiles-in> <node-tiles-out> <bordernids-in> <bordernodes-out> <strm-data-dir>" );
|
||||
System.out.println( "usage: java PosUnifier <node-tiles-in> <node-tiles-out> <bordernids-in> <bordernodes-out> <strm-data-dir>" );
|
||||
return;
|
||||
}
|
||||
new PosUnifier().process( new File( args[0] ), new File( args[1] ), new File( args[2] ), new File( args[3] ), args[4] );
|
||||
|
|
@ -57,13 +56,14 @@ public class PosUnifier extends MapCreatorBase
|
|||
borderNids = new CompactLongSet();
|
||||
try
|
||||
{
|
||||
for(;;)
|
||||
for ( ;; )
|
||||
{
|
||||
long nid = readId( dis );
|
||||
if ( !borderNids.contains( nid ) ) borderNids.fastAdd( nid );
|
||||
if ( !borderNids.contains( nid ) )
|
||||
borderNids.fastAdd( nid );
|
||||
}
|
||||
}
|
||||
catch( EOFException eof )
|
||||
catch (EOFException eof)
|
||||
{
|
||||
dis.close();
|
||||
}
|
||||
|
|
@ -88,8 +88,8 @@ public class PosUnifier extends MapCreatorBase
|
|||
@Override
|
||||
public void nextNode( NodeData n ) throws Exception
|
||||
{
|
||||
SrtmData srtm = srtmForNode( n.ilon, n.ilat );
|
||||
n.selev = srtm == null ? Short.MIN_VALUE : srtm.getElevation( n.ilon, n.ilat);
|
||||
SrtmRaster srtm = srtmForNode( n.ilon, n.ilat );
|
||||
n.selev = srtm == null ? Short.MIN_VALUE : srtm.getElevation( n.ilon, n.ilat );
|
||||
|
||||
findUniquePos( n );
|
||||
|
||||
|
|
@ -113,13 +113,13 @@ public class PosUnifier extends MapCreatorBase
|
|||
int londelta = lonmod < 500000 ? 1 : -1;
|
||||
int latmod = n.ilat % 1000000;
|
||||
int latdelta = latmod < 500000 ? 1 : -1;
|
||||
for(int latsteps = 0; latsteps < 100; latsteps++)
|
||||
for ( int latsteps = 0; latsteps < 100; latsteps++ )
|
||||
{
|
||||
for(int lonsteps = 0; lonsteps <= latsteps; lonsteps++)
|
||||
for ( int lonsteps = 0; lonsteps <= latsteps; lonsteps++ )
|
||||
{
|
||||
int lon = n.ilon + lonsteps*londelta;
|
||||
int lat = n.ilat + latsteps*latdelta;
|
||||
long pid = ((long)lon)<<32 | lat; // id from position
|
||||
int lon = n.ilon + lonsteps * londelta;
|
||||
int lat = n.ilat + latsteps * latdelta;
|
||||
long pid = ( (long) lon ) << 32 | lat; // id from position
|
||||
if ( !positionSet.contains( pid ) )
|
||||
{
|
||||
positionSet.fastAdd( pid );
|
||||
|
|
@ -132,16 +132,14 @@ public class PosUnifier extends MapCreatorBase
|
|||
System.out.println( "*** WARNING: cannot unify position for: " + n.ilon + " " + n.ilat );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the srtm data set for a position
|
||||
* srtm coords are srtm_<srtmLon>_<srtmLat>
|
||||
* where srtmLon = 180 + lon, srtmLat = 60 - lat
|
||||
* get the srtm data set for a position srtm coords are
|
||||
* srtm_<srtmLon>_<srtmLat> where srtmLon = 180 + lon, srtmLat = 60 - lat
|
||||
*/
|
||||
private SrtmData srtmForNode( int ilon, int ilat ) throws Exception
|
||||
private SrtmRaster srtmForNode( int ilon, int ilat ) throws Exception
|
||||
{
|
||||
int srtmLonIdx = (ilon+5000000)/5000000;
|
||||
int srtmLatIdx = (154999999-ilat)/5000000;
|
||||
int srtmLonIdx = ( ilon + 5000000 ) / 5000000;
|
||||
int srtmLatIdx = ( 154999999 - ilat ) / 5000000;
|
||||
|
||||
if ( srtmLatIdx < 1 || srtmLatIdx > 24 || srtmLonIdx < 1 || srtmLonIdx > 72 )
|
||||
{
|
||||
|
|
@ -149,45 +147,63 @@ public class PosUnifier extends MapCreatorBase
|
|||
}
|
||||
if ( srtmLonIdx == lastStrmLonIdx && srtmLatIdx == lastStrmLatIdx )
|
||||
{
|
||||
return lastSrtmData;
|
||||
return lastSrtmRaster;
|
||||
}
|
||||
lastStrmLonIdx = srtmLonIdx;
|
||||
lastStrmLatIdx = srtmLatIdx;
|
||||
|
||||
StringBuilder sb = new StringBuilder( 16 );
|
||||
sb.append( "srtm_" );
|
||||
sb.append( (char)('0' + srtmLonIdx/10 ) ).append( (char)('0' + srtmLonIdx%10 ) ).append( '_' );
|
||||
sb.append( (char)('0' + srtmLatIdx/10 ) ).append( (char)('0' + srtmLatIdx%10 ) ).append( ".zip" );
|
||||
sb.append( (char) ( '0' + srtmLonIdx / 10 ) ).append( (char) ( '0' + srtmLonIdx % 10 ) ).append( '_' );
|
||||
sb.append( (char) ( '0' + srtmLatIdx / 10 ) ).append( (char) ( '0' + srtmLatIdx % 10 ) );
|
||||
String filename = sb.toString();
|
||||
|
||||
|
||||
lastSrtmData = srtmmap.get( filename );
|
||||
if ( lastSrtmData == null && !srtmmap.containsKey( filename ) )
|
||||
lastSrtmRaster = srtmmap.get( filename );
|
||||
if ( lastSrtmRaster == null && !srtmmap.containsKey( filename ) )
|
||||
{
|
||||
File f = new File( new File( srtmdir ), filename );
|
||||
File f = new File( new File( srtmdir ), filename + ".bef" );
|
||||
System.out.println( "checking: " + f + " ilon=" + ilon + " ilat=" + ilat );
|
||||
if ( f.exists() )
|
||||
{
|
||||
System.out.println( "*** reading: " + f );
|
||||
try
|
||||
{
|
||||
InputStream isc = new BufferedInputStream( new FileInputStream( f ) );
|
||||
lastSrtmRaster = new RasterCoder().decodeRaster( isc );
|
||||
isc.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println( "**** ERROR reading " + f + " ****" );
|
||||
}
|
||||
srtmmap.put( filename, lastSrtmRaster );
|
||||
return lastSrtmRaster;
|
||||
}
|
||||
|
||||
f = new File( new File( srtmdir ), filename + ".zip" );
|
||||
System.out.println( "reading: " + f + " ilon=" + ilon + " ilat=" + ilat );
|
||||
if ( f.exists() )
|
||||
{
|
||||
try
|
||||
{
|
||||
lastSrtmData = new SrtmData( f );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
System.out.println( "**** ERROR reading " + f + " ****" );
|
||||
}
|
||||
try
|
||||
{
|
||||
lastSrtmRaster = new SrtmData( f ).getRaster();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println( "**** ERROR reading " + f + " ****" );
|
||||
}
|
||||
}
|
||||
srtmmap.put( filename, lastSrtmData );
|
||||
srtmmap.put( filename, lastSrtmRaster );
|
||||
}
|
||||
return lastSrtmData;
|
||||
return lastSrtmRaster;
|
||||
}
|
||||
|
||||
private void resetSrtm()
|
||||
{
|
||||
srtmmap = new HashMap<String,SrtmData>();
|
||||
srtmmap = new HashMap<String, SrtmRaster>();
|
||||
lastStrmLonIdx = -1;
|
||||
lastStrmLatIdx = -1;
|
||||
lastSrtmData = null;
|
||||
lastSrtmRaster = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue