variable length tag descriptions (first shot)
This commit is contained in:
parent
6768a197ba
commit
a145230e0f
23 changed files with 860 additions and 124 deletions
|
|
@ -56,4 +56,20 @@ final class ByteDataReader
|
|||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,4 +51,19 @@ final class ByteDataWriter
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
|
@ -291,4 +291,10 @@ final class MicroCache
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,13 @@
|
|||
package btools.mapaccess;
|
||||
|
||||
|
||||
public final class OsmLink
|
||||
public class OsmLink
|
||||
{
|
||||
/**
|
||||
* The description bitmap is mainly the way description
|
||||
* used to calculate the costfactor
|
||||
*/
|
||||
public long descriptionBitmap;
|
||||
public byte[] descriptionBitmap;
|
||||
|
||||
/**
|
||||
* The target is either the next link or the target node
|
||||
|
|
@ -29,12 +29,12 @@ public final class OsmLink
|
|||
|
||||
public byte[] firsttransferBytes;
|
||||
|
||||
public OsmTransferNode decodeFirsttransfer()
|
||||
final public OsmTransferNode decodeFirsttransfer()
|
||||
{
|
||||
return firsttransferBytes == null ? null : OsmTransferNode.decode( firsttransferBytes );
|
||||
}
|
||||
|
||||
public void encodeFirsttransfer( OsmTransferNode firsttransfer )
|
||||
final public void encodeFirsttransfer( OsmTransferNode firsttransfer )
|
||||
{
|
||||
if ( firsttransfer == null ) firsttransferBytes = null;
|
||||
else firsttransferBytes = OsmTransferNode.encode( firsttransfer );
|
||||
|
|
@ -44,7 +44,7 @@ public final class OsmLink
|
|||
|
||||
public OsmLinkHolder firstlinkholder = null;
|
||||
|
||||
public void addLinkHolder( OsmLinkHolder holder )
|
||||
final public void addLinkHolder( OsmLinkHolder holder )
|
||||
{
|
||||
if ( firstlinkholder != null ) { holder.setNextForLink( firstlinkholder ); }
|
||||
firstlinkholder = holder;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* Dummy child of OsmLink just to encode the reverse-bit
|
||||
*
|
||||
* @author ab
|
||||
*/
|
||||
package btools.mapaccess;
|
||||
|
||||
|
||||
public class OsmLinkReverse extends OsmLink
|
||||
{
|
||||
}
|
||||
|
|
@ -47,7 +47,7 @@ public class OsmNode implements OsmPos
|
|||
*/
|
||||
public short selev;
|
||||
|
||||
public long nodeDescription;
|
||||
public byte[] nodeDescription;
|
||||
|
||||
// interface OsmPos
|
||||
public int getILat()
|
||||
|
|
@ -124,7 +124,7 @@ public class OsmNode implements OsmPos
|
|||
OsmTransferNode lastTransferNode = null;
|
||||
int linklon;
|
||||
int linklat;
|
||||
long description = 0L;
|
||||
byte[] description = null;
|
||||
for(;;)
|
||||
{
|
||||
int bitField = is.readByte();
|
||||
|
|
@ -147,18 +147,21 @@ public class OsmNode implements OsmPos
|
|||
}
|
||||
if ( (bitField & WRITEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
description = is.readLong();
|
||||
bodySize -= 8;
|
||||
int dlen = is.readByte(); description = new byte[dlen]; is.readFully( description );
|
||||
bodySize -= 1 + dlen;
|
||||
}
|
||||
if ( (bitField & NODEDESC_BITMASK ) != 0 )
|
||||
{
|
||||
nodeDescription = is.readLong();
|
||||
bodySize -= 8;
|
||||
int dlen = is.readByte(); nodeDescription = new byte[dlen]; is.readFully( nodeDescription );
|
||||
bodySize -= 1 + dlen;
|
||||
}
|
||||
if ( (bitField & SKIPDETAILS_BITMASK ) != 0 )
|
||||
{
|
||||
link.counterLinkWritten = true;
|
||||
}
|
||||
|
||||
if ( description == null && !link.counterLinkWritten ) throw new IllegalArgumentException( "internal error: missing way description!" );
|
||||
|
||||
boolean isTransfer = (bitField & TRANSFERNODE_BITMASK ) != 0;
|
||||
if ( isTransfer )
|
||||
{
|
||||
|
|
@ -234,32 +237,30 @@ public class OsmNode implements OsmPos
|
|||
// compute the reverse link
|
||||
if ( !link.counterLinkWritten )
|
||||
{
|
||||
OsmLink rlink = new OsmLink();
|
||||
long rerverseLinkBitmap = link.descriptionBitmap ^ 1L;
|
||||
OsmLink rlink = new OsmLinkReverse();
|
||||
|
||||
rlink.ilonOrigin = tn.ilon;
|
||||
rlink.ilatOrigin = tn.ilat;
|
||||
rlink.targetNode = this;
|
||||
rlink.descriptionBitmap = rerverseLinkBitmap; // default for no transfer-nodes
|
||||
rlink.descriptionBitmap = link.descriptionBitmap; // default for no transfer-nodes
|
||||
OsmTransferNode previous = null;
|
||||
OsmTransferNode rtrans = null;
|
||||
for( OsmTransferNode trans = firstTransferNode; trans != null; trans = trans.next )
|
||||
{
|
||||
long rerverseTransBitmap = trans.descriptionBitmap ^ 1L;
|
||||
if ( previous == null )
|
||||
{
|
||||
rlink.descriptionBitmap = rerverseTransBitmap;
|
||||
rlink.descriptionBitmap = trans.descriptionBitmap;
|
||||
}
|
||||
else
|
||||
{
|
||||
previous.descriptionBitmap = rerverseTransBitmap;
|
||||
previous.descriptionBitmap = trans.descriptionBitmap;
|
||||
}
|
||||
rtrans = new OsmTransferNode();
|
||||
rtrans.ilon = trans.ilon;
|
||||
rtrans.ilat = trans.ilat;
|
||||
rtrans.selev = trans.selev;
|
||||
rtrans.next = previous;
|
||||
rtrans.descriptionBitmap = rerverseLinkBitmap;
|
||||
rtrans.descriptionBitmap = trans.descriptionBitmap;
|
||||
previous = rtrans;
|
||||
}
|
||||
rlink.encodeFirsttransfer(rtrans);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public final class OsmTransferNode
|
|||
* The description bitmap is mainly the way description
|
||||
* used to calculate the costfactor
|
||||
*/
|
||||
public long descriptionBitmap;
|
||||
public byte[] descriptionBitmap;
|
||||
|
||||
public OsmTransferNode next;
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ public final class OsmTransferNode
|
|||
// encode this transfer-node into a byte array
|
||||
public static byte[] encode( OsmTransferNode tn )
|
||||
{
|
||||
long currentDesc = 0;
|
||||
byte[] currentDesc = null;
|
||||
int currentILonHigh = 0;
|
||||
int currentILatHigh = 0;
|
||||
OsmTransferNode n = tn;
|
||||
|
|
@ -39,10 +39,12 @@ public final class OsmTransferNode
|
|||
|
||||
while( n != null )
|
||||
{
|
||||
if ( n.descriptionBitmap == null ) throw new IllegalArgumentException( "transfernode-encode: description is null" );
|
||||
|
||||
if( n.descriptionBitmap != currentDesc )
|
||||
{
|
||||
size += 8;
|
||||
currentDesc = n.descriptionBitmap;
|
||||
size += 1 + currentDesc.length;
|
||||
}
|
||||
if( ( n.ilon >> 16 ) != currentILonHigh )
|
||||
{
|
||||
|
|
@ -61,7 +63,7 @@ public final class OsmTransferNode
|
|||
byte[] ab = new byte[size];
|
||||
ByteDataWriter os = new ByteDataWriter( ab );
|
||||
|
||||
currentDesc = 0;
|
||||
currentDesc = null;
|
||||
currentILonHigh = 0;
|
||||
currentILatHigh = 0;
|
||||
n = tn;
|
||||
|
|
@ -84,7 +86,7 @@ public final class OsmTransferNode
|
|||
currentILatHigh = n.ilat >> 16;
|
||||
}
|
||||
os.writeByte( mode);
|
||||
if ( (mode & BIT_DESC) != 0 ) os.writeLong( currentDesc );
|
||||
if ( (mode & BIT_DESC) != 0 ) { os.writeByte( currentDesc.length ); os.write( currentDesc ); }
|
||||
if ( (mode & BIT_ILONHIGH) != 0 ) os.writeShort( currentILonHigh );
|
||||
if ( (mode & BIT_ILATHIGH) != 0 ) os.writeShort( currentILatHigh );
|
||||
os.writeShort( n.ilon );
|
||||
|
|
@ -103,19 +105,21 @@ public final class OsmTransferNode
|
|||
|
||||
OsmTransferNode firstNode = null;
|
||||
OsmTransferNode lastNode = null;
|
||||
long currentDesc = 0;
|
||||
byte[] currentDesc = null;
|
||||
int currentILonHigh = 0;
|
||||
int currentILatHigh = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
byte mode = is.readByte();
|
||||
if ( (mode & BIT_STOP ) != 0 ) break;
|
||||
|
||||
OsmTransferNode n = new OsmTransferNode();
|
||||
if ( (mode & BIT_DESC) != 0 ) currentDesc = is.readLong();
|
||||
if ( (mode & BIT_DESC) != 0 ) { int dlen = is.readByte(); currentDesc = new byte[dlen]; is.readFully( currentDesc ); }
|
||||
if ( (mode & BIT_ILONHIGH) != 0 ) currentILonHigh = is.readShort();
|
||||
if ( (mode & BIT_ILATHIGH) != 0 ) currentILatHigh = is.readShort();
|
||||
n.descriptionBitmap = currentDesc;
|
||||
if ( n.descriptionBitmap == null ) throw new IllegalArgumentException( "transfernode-decode: description is null" );
|
||||
int ilon = is.readShort() & 0xffff; ilon |= currentILonHigh << 16;
|
||||
int ilat = is.readShort() & 0xffff; ilat |= currentILatHigh << 16;
|
||||
n.ilon = ilon;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue