1.0 preparations
This commit is contained in:
parent
55717c6e71
commit
8fa82633d4
34 changed files with 742 additions and 462 deletions
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* fast data-reading from a byte-array
|
||||
*
|
||||
* @author ab
|
||||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
|
||||
final class ByteDataReader
|
||||
{
|
||||
private byte[] ab;
|
||||
private int aboffset;
|
||||
|
||||
public ByteDataReader( byte[] byteArray )
|
||||
{
|
||||
ab = byteArray;
|
||||
}
|
||||
|
||||
public int readInt()
|
||||
{
|
||||
int i3 = ab[aboffset++]& 0xff;
|
||||
int i2 = ab[aboffset++]& 0xff;
|
||||
int i1 = ab[aboffset++]& 0xff;
|
||||
int i0 = ab[aboffset++]& 0xff;
|
||||
return (i3 << 24) + (i2 << 16) + (i1 << 8) + i0;
|
||||
}
|
||||
|
||||
public long readLong()
|
||||
{
|
||||
long i7 = ab[aboffset++]& 0xff;
|
||||
long i6 = ab[aboffset++]& 0xff;
|
||||
long i5 = ab[aboffset++]& 0xff;
|
||||
long i4 = ab[aboffset++]& 0xff;
|
||||
long i3 = ab[aboffset++]& 0xff;
|
||||
long i2 = ab[aboffset++]& 0xff;
|
||||
long i1 = ab[aboffset++]& 0xff;
|
||||
long i0 = ab[aboffset++]& 0xff;
|
||||
return (i7 << 56) + (i6 << 48) + (i5 << 40) + (i4 << 32) + (i3 << 24) + (i2 << 16) + (i1 << 8) + i0;
|
||||
}
|
||||
|
||||
public boolean readBoolean()
|
||||
{
|
||||
int i0 = ab[aboffset++]& 0xff;
|
||||
return i0 != 0;
|
||||
}
|
||||
|
||||
public byte readByte()
|
||||
{
|
||||
int i0 = ab[aboffset++] & 0xff;
|
||||
return (byte)(i0);
|
||||
}
|
||||
|
||||
public short readShort()
|
||||
{
|
||||
int i1 = ab[aboffset++] & 0xff;
|
||||
int i0 = ab[aboffset++] & 0xff;
|
||||
return (short)( (i1 << 8) | i0);
|
||||
}
|
||||
|
||||
public void readFully( byte[] ta )
|
||||
{
|
||||
System.arraycopy( ab, aboffset, ta, 0, ta.length );
|
||||
aboffset += ta.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder( "[" );
|
||||
for( int i=0; i<ab.length; i++ ) sb.append( i == 0 ? " " : ", " ).append( Integer.toString( ab[i] ) );
|
||||
sb.append( " ]" );
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* fast data-reading from a byte-array
|
||||
*
|
||||
* @author ab
|
||||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
|
||||
final class ByteDataWriter
|
||||
{
|
||||
private byte[] ab;
|
||||
private int aboffset;
|
||||
|
||||
public ByteDataWriter( byte[] byteArray )
|
||||
{
|
||||
ab = byteArray;
|
||||
}
|
||||
|
||||
public void writeInt( int v )
|
||||
{
|
||||
ab[aboffset++] = (byte)( (v >> 24) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 16) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 8) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v ) & 0xff );
|
||||
}
|
||||
|
||||
public void writeLong( long v )
|
||||
{
|
||||
ab[aboffset++] = (byte)( (v >> 56) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 48) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 40) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 32) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 24) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 16) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v >> 8) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v ) & 0xff );
|
||||
}
|
||||
|
||||
public void writeBoolean( boolean v)
|
||||
{
|
||||
ab[aboffset++] = (byte)( v ? 1 : 0 );
|
||||
}
|
||||
|
||||
public void writeByte( int v )
|
||||
{
|
||||
ab[aboffset++] = (byte)( (v ) & 0xff );
|
||||
}
|
||||
|
||||
public void writeShort( int v )
|
||||
{
|
||||
ab[aboffset++] = (byte)( (v >> 8) & 0xff );
|
||||
ab[aboffset++] = (byte)( (v ) & 0xff );
|
||||
}
|
||||
|
||||
public void write( byte[] sa )
|
||||
{
|
||||
System.arraycopy( sa, 0, ab, aboffset, sa.length );
|
||||
aboffset += sa.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder( "[" );
|
||||
for( int i=0; i<ab.length; i++ ) sb.append( i == 0 ? " " : ", " ).append( Integer.toString( ab[i] ) );
|
||||
sb.append( " ]" );
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,12 +5,14 @@
|
|||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import btools.util.ByteDataReader;
|
||||
import btools.util.Crc32;
|
||||
|
||||
final class MicroCache
|
||||
final class MicroCache extends ByteDataReader
|
||||
{
|
||||
private long[] faid;
|
||||
private int[] fapos;
|
||||
|
|
@ -18,10 +20,10 @@ final class MicroCache
|
|||
private int delcount = 0;
|
||||
private int delbytes = 0;
|
||||
private int p2size; // next power of 2 of size
|
||||
|
||||
private boolean readVarLength;
|
||||
|
||||
// the object parsing position and length
|
||||
private byte[] ab;
|
||||
private int aboffset;
|
||||
private int aboffsetEnd;
|
||||
|
||||
// cache control: a virgin cache can be
|
||||
|
|
@ -29,8 +31,11 @@ final class MicroCache
|
|||
boolean virgin = true;
|
||||
boolean ghost = false;
|
||||
|
||||
public MicroCache( OsmFile segfile, int lonIdx80, int latIdx80, byte[] iobuffer ) throws Exception
|
||||
public MicroCache( OsmFile segfile, int lonIdx80, int latIdx80, byte[] iobuffer, boolean readVarLength ) throws Exception
|
||||
{
|
||||
super( null );
|
||||
this.readVarLength = readVarLength;
|
||||
|
||||
int lonDegree = lonIdx80/80;
|
||||
int latDegree = latIdx80/80;
|
||||
|
||||
|
|
@ -55,20 +60,22 @@ final class MicroCache
|
|||
}
|
||||
aboffset = 0;
|
||||
size = readInt();
|
||||
|
||||
|
||||
// get net size
|
||||
int nbytes = 0;
|
||||
for(int i = 0; i<size; i++)
|
||||
{
|
||||
int ilon = readShort();
|
||||
int ilat = readShort();
|
||||
int bodySize = readInt();
|
||||
if ( ilon == Short.MAX_VALUE && ilat == Short.MAX_VALUE )
|
||||
int bodySize = readVarLength ? readVarLengthUnsigned() : readInt();
|
||||
|
||||
// kack for the old format crc
|
||||
if ( !readVarLength && ilon == Short.MAX_VALUE && ilat == Short.MAX_VALUE )
|
||||
{
|
||||
int crc = Crc32.crc( ab, 0, aboffset-8 );
|
||||
int crc = Crc32.crc( ab, 0, aboffset-8 ); // old format crc
|
||||
if ( crc != readInt() )
|
||||
{
|
||||
throw new IOException( "checkum error" );
|
||||
throw new IOException( "checkum-error" );
|
||||
}
|
||||
size = i;
|
||||
break;
|
||||
|
|
@ -77,6 +84,15 @@ final class MicroCache
|
|||
nbytes += bodySize;
|
||||
}
|
||||
|
||||
if ( readVarLength ) // new format crc
|
||||
{
|
||||
int crc = Crc32.crc( ab, 0, aboffset );
|
||||
if ( crc != readInt() )
|
||||
{
|
||||
throw new IOException( "checkum error" );
|
||||
}
|
||||
}
|
||||
|
||||
// new array with only net data
|
||||
byte[] nab = new byte[nbytes];
|
||||
aboffset = 4;
|
||||
|
|
@ -95,7 +111,7 @@ final class MicroCache
|
|||
long nodeId = ((long)ilon)<<32 | ilat;
|
||||
|
||||
faid[i] = nodeId;
|
||||
int bodySize = readInt();
|
||||
int bodySize = readVarLength ? readVarLengthUnsigned() : readInt();
|
||||
fapos[i] = noffset;
|
||||
System.arraycopy( ab, aboffset, nab, noffset, bodySize );
|
||||
aboffset += bodySize;
|
||||
|
|
@ -173,7 +189,7 @@ final class MicroCache
|
|||
long id = node.getIdFromPos();
|
||||
if ( getAndClear( id ) )
|
||||
{
|
||||
node.parseNodeBody( this, nodesMap, dc );
|
||||
node.parseNodeBody( this, nodesMap, dc, readVarLength );
|
||||
}
|
||||
|
||||
if ( doCollect && delcount > size / 2 ) // garbage collection
|
||||
|
|
@ -252,53 +268,6 @@ final class MicroCache
|
|||
return positions;
|
||||
}
|
||||
|
||||
public int readInt()
|
||||
{
|
||||
int i3 = ab[aboffset++]& 0xff;
|
||||
int i2 = ab[aboffset++]& 0xff;
|
||||
int i1 = ab[aboffset++]& 0xff;
|
||||
int i0 = ab[aboffset++]& 0xff;
|
||||
return (i3 << 24) + (i2 << 16) + (i1 << 8) + i0;
|
||||
}
|
||||
|
||||
public long readLong()
|
||||
{
|
||||
long i7 = ab[aboffset++]& 0xff;
|
||||
long i6 = ab[aboffset++]& 0xff;
|
||||
long i5 = ab[aboffset++]& 0xff;
|
||||
long i4 = ab[aboffset++]& 0xff;
|
||||
long i3 = ab[aboffset++]& 0xff;
|
||||
long i2 = ab[aboffset++]& 0xff;
|
||||
long i1 = ab[aboffset++]& 0xff;
|
||||
long i0 = ab[aboffset++]& 0xff;
|
||||
return (i7 << 56) + (i6 << 48) + (i5 << 40) + (i4 << 32) + (i3 << 24) + (i2 << 16) + (i1 << 8) + i0;
|
||||
}
|
||||
|
||||
public boolean readBoolean()
|
||||
{
|
||||
int i0 = ab[aboffset++]& 0xff;
|
||||
return i0 != 0;
|
||||
}
|
||||
|
||||
public byte readByte()
|
||||
{
|
||||
int i0 = ab[aboffset++] & 0xff;
|
||||
return (byte)(i0);
|
||||
}
|
||||
|
||||
public short readShort()
|
||||
{
|
||||
int i1 = ab[aboffset++] & 0xff;
|
||||
int i0 = ab[aboffset++] & 0xff;
|
||||
return (short)( (i1 << 8) | i0);
|
||||
}
|
||||
|
||||
public void readFully( byte[] ta )
|
||||
{
|
||||
System.arraycopy( ab, aboffset, ta, 0, ta.length );
|
||||
aboffset += ta.length;
|
||||
}
|
||||
|
||||
public boolean hasMoreData()
|
||||
{
|
||||
return aboffset < aboffsetEnd;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public final class NodesCache
|
|||
private OsmNodesMap nodesMap;
|
||||
private int lookupVersion;
|
||||
private int lookupMinorVersion;
|
||||
private boolean readVarLength;
|
||||
private boolean carMode;
|
||||
private String currentFileName;
|
||||
|
||||
|
|
@ -33,12 +34,13 @@ public final class NodesCache
|
|||
private long cacheSum = 0;
|
||||
private boolean garbageCollectionEnabled = false;
|
||||
|
||||
public NodesCache( String segmentDir, OsmNodesMap nodesMap, int lookupVersion, int lookupMinorVersion, boolean carMode, NodesCache oldCache )
|
||||
public NodesCache( String segmentDir, OsmNodesMap nodesMap, int lookupVersion, int minorVersion, boolean varLen, boolean carMode, NodesCache oldCache )
|
||||
{
|
||||
this.segmentDir = segmentDir;
|
||||
this.nodesMap = nodesMap;
|
||||
this.lookupVersion = lookupVersion;
|
||||
this.lookupMinorVersion = lookupMinorVersion;
|
||||
this.lookupMinorVersion = minorVersion;
|
||||
this.readVarLength = varLen;
|
||||
this.carMode = carMode;
|
||||
|
||||
if ( oldCache != null )
|
||||
|
|
@ -145,7 +147,7 @@ public final class NodesCache
|
|||
|
||||
checkEnableCacheCleaning();
|
||||
|
||||
segment = new MicroCache( osmf, lonIdx80, latIdx80, iobuffer );
|
||||
segment = new MicroCache( osmf, lonIdx80, latIdx80, iobuffer, readVarLength );
|
||||
cacheSum += segment.getDataSize();
|
||||
osmf.microCaches[subIdx] = segment;
|
||||
segmentList.add( segment );
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ package btools.mapaccess;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import btools.util.ByteDataReader;
|
||||
import btools.util.Crc32;
|
||||
|
||||
final class OsmFile
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ import btools.util.ByteArrayUnifier;
|
|||
|
||||
public class OsmNode implements OsmPos
|
||||
{
|
||||
public static final int EXTERNAL_BITMASK = 0x80;
|
||||
public static final int VARIABLEDESC_BITMASK = 0x40;
|
||||
public static final int EXTERNAL_BITMASK = 0x80; // old semantic
|
||||
public static final int SIGNLON_BITMASK = 0x80;
|
||||
public static final int SIGNLAT_BITMASK = 0x40;
|
||||
public static final int TRANSFERNODE_BITMASK = 0x20;
|
||||
public static final int WRITEDESC_BITMASK = 0x10;
|
||||
public static final int SKIPDETAILS_BITMASK = 0x08;
|
||||
|
|
@ -111,10 +112,10 @@ public class OsmNode implements OsmPos
|
|||
}
|
||||
|
||||
|
||||
public void parseNodeBody( MicroCache is, OsmNodesMap hollowNodes, DistanceChecker dc )
|
||||
public void parseNodeBody( MicroCache is, OsmNodesMap hollowNodes, DistanceChecker dc, boolean readVarLength )
|
||||
{
|
||||
ByteArrayUnifier abUnifier = hollowNodes.getByteArrayUnifier();
|
||||
|
||||
|
||||
selev = is.readShort();
|
||||
|
||||
OsmLink lastlink = null;
|
||||
|
|
@ -124,6 +125,9 @@ public class OsmNode implements OsmPos
|
|||
|
||||
while( is.hasMoreData() )
|
||||
{
|
||||
int ilonref = ilon;
|
||||
int ilatref = ilat;
|
||||
|
||||
OsmLink link = new OsmLink();
|
||||
OsmTransferNode firstTransferNode = null;
|
||||
OsmTransferNode lastTransferNode = null;
|
||||
|
|
@ -133,31 +137,45 @@ public class OsmNode implements OsmPos
|
|||
for(;;)
|
||||
{
|
||||
int bitField = is.readByte();
|
||||
if ( (bitField & EXTERNAL_BITMASK) != 0 )
|
||||
// System.out.println( "parseNodeBody: var=" + readVarLength + " bitField=" + bitField );
|
||||
if ( readVarLength )
|
||||
{
|
||||
// full position for external target
|
||||
linklon = is.readInt();
|
||||
linklat = is.readInt();
|
||||
int dlon = is.readVarLengthUnsigned();
|
||||
int dlat = is.readVarLengthUnsigned();
|
||||
if ( (bitField & SIGNLON_BITMASK) != 0 ) { dlon = -dlon;}
|
||||
if ( (bitField & SIGNLAT_BITMASK) != 0 ) { dlat = -dlat;}
|
||||
linklon = ilonref + dlon;
|
||||
linklat = ilatref + dlat;
|
||||
ilonref = linklon;
|
||||
ilatref = linklat;
|
||||
}
|
||||
else
|
||||
{
|
||||
// reduced position for internal target
|
||||
linklon = is.readShort();
|
||||
linklat = is.readShort();
|
||||
linklon += lonIdx*62500 + 31250;
|
||||
linklat += latIdx*62500 + 31250;
|
||||
if ( (bitField & EXTERNAL_BITMASK) != 0 )
|
||||
{
|
||||
// full position for external target
|
||||
linklon = is.readInt();
|
||||
linklat = is.readInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
// reduced position for internal target
|
||||
linklon = is.readShort();
|
||||
linklat = is.readShort();
|
||||
linklon += lonIdx*62500 + 31250;
|
||||
linklat += latIdx*62500 + 31250;
|
||||
}
|
||||
}
|
||||
// read variable length or old 8 byte fixed, and ensure that 8 bytes is only fixed
|
||||
boolean readFix8 = (bitField & VARIABLEDESC_BITMASK ) == 0; // old, fix length format
|
||||
if ( (bitField & WRITEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
byte[] ab = new byte[readFix8 ? 8 : is.readByte()];
|
||||
byte[] ab = new byte[readVarLength ? is.readByte() : 8 ];
|
||||
is.readFully( ab );
|
||||
description = abUnifier.unify( ab );
|
||||
}
|
||||
if ( (bitField & NODEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
byte[] ab = new byte[readFix8 ? 8 : is.readByte()];
|
||||
byte[] ab = new byte[readVarLength ? is.readByte() : 8 ];
|
||||
is.readFully( ab );
|
||||
nodeDescription = abUnifier.unify( ab );
|
||||
}
|
||||
|
|
@ -185,7 +203,7 @@ public class OsmNode implements OsmPos
|
|||
trans.ilon = linklon;
|
||||
trans.ilat = linklat;
|
||||
trans.descriptionBitmap = description;
|
||||
trans.selev = is.readShort();
|
||||
trans.selev = readVarLength ? (short)(selev + is.readVarLengthSigned()) : is.readShort();
|
||||
if ( lastTransferNode == null )
|
||||
{
|
||||
firstTransferNode = trans;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@
|
|||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
import btools.util.ByteDataReader;
|
||||
import btools.util.ByteDataWriter;
|
||||
|
||||
|
||||
|
||||
public final class OsmTransferNode
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
package btools.mapaccess;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import btools.util.ByteDataReader;
|
||||
import btools.util.Crc32;
|
||||
|
||||
final public class PhysicalFile
|
||||
|
|
@ -37,7 +39,7 @@ final public class PhysicalFile
|
|||
if ( osmf.microCaches != null )
|
||||
for( int lonIdx80=0; lonIdx80<80; lonIdx80++ )
|
||||
for( int latIdx80=0; latIdx80<80; latIdx80++ )
|
||||
new MicroCache( osmf, lonIdx80, latIdx80, iobuffer );
|
||||
new MicroCache( osmf, lonIdx80, latIdx80, iobuffer, true ); // TODO: readVarLength ?
|
||||
}
|
||||
}
|
||||
catch( IllegalArgumentException iae )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue