variable length tag encoding (more bugs..)
This commit is contained in:
parent
eba5737739
commit
be24ee7a88
7 changed files with 103 additions and 36 deletions
|
@ -17,7 +17,8 @@ import java.util.Map;
|
|||
import java.util.StringTokenizer;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import btools.util.*;
|
||||
import btools.util.BitCoderContext;
|
||||
import btools.util.Crc32;
|
||||
|
||||
|
||||
public final class BExpressionContext
|
||||
|
@ -122,6 +123,7 @@ public final class BExpressionContext
|
|||
ctx.encodeBit( ld[0] != 0 );
|
||||
|
||||
int skippedTags = 0;
|
||||
int nonNullTags= 0;
|
||||
|
||||
// all others are generic
|
||||
for( int inum = 1; inum < lookupValues.size(); inum++ ) // loop over lookup names
|
||||
|
@ -133,6 +135,7 @@ public final class BExpressionContext
|
|||
continue;
|
||||
}
|
||||
ctx.encodeDistance( skippedTags+1 );
|
||||
nonNullTags++;
|
||||
skippedTags = 0;
|
||||
|
||||
// 0 excluded already, 1 (=unknown) we rotate up to 8
|
||||
|
@ -141,15 +144,53 @@ public final class BExpressionContext
|
|||
ctx.encodeDistance( dd );
|
||||
}
|
||||
ctx.encodeDistance( 0 );
|
||||
|
||||
if ( nonNullTags == 0) return null;
|
||||
|
||||
int len = ctx.getEncodedLength();
|
||||
byte[] ab = new byte[len];
|
||||
System.arraycopy( abBuf, 0, ab, 0, len );
|
||||
|
||||
|
||||
// crosscheck: decode and compare
|
||||
int[] ld2 = new int[lookupValues.size()];
|
||||
decode( ld2, ab );
|
||||
for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names
|
||||
{
|
||||
if ( ld2[inum] != ld[inum] ) throw new RuntimeException( "assertion failed encoding " + getKeyValueDescription(ab) );
|
||||
}
|
||||
|
||||
return ab;
|
||||
}
|
||||
|
||||
private byte[] encodeFix( int[] ld )
|
||||
/**
|
||||
* encode lookup data to a 64-bit word
|
||||
*/
|
||||
public byte[] encodeFix( int[] ld )
|
||||
{
|
||||
throw new IllegalArgumentException( "encoding fixed-length not supporte" );
|
||||
long w = 0;
|
||||
for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names
|
||||
{
|
||||
int n = lookupValues.get(inum).length - 1;
|
||||
int d = ld[inum];
|
||||
if ( n == 2 ) { n = 1; d = d == 2 ? 1 : 0; } // 1-bit encoding for booleans
|
||||
|
||||
while( n != 0 ) { n >>= 1; w <<= 1; }
|
||||
w |= (long)d;
|
||||
}
|
||||
if ( w == 0) return null;
|
||||
|
||||
byte[] ab = new byte[8];
|
||||
int aboffset = 0;
|
||||
ab[aboffset++] = (byte)( (w >> 56) & 0xff );
|
||||
ab[aboffset++] = (byte)( (w >> 48) & 0xff );
|
||||
ab[aboffset++] = (byte)( (w >> 40) & 0xff );
|
||||
ab[aboffset++] = (byte)( (w >> 32) & 0xff );
|
||||
ab[aboffset++] = (byte)( (w >> 24) & 0xff );
|
||||
ab[aboffset++] = (byte)( (w >> 16) & 0xff );
|
||||
ab[aboffset++] = (byte)( (w >> 8) & 0xff );
|
||||
ab[aboffset++] = (byte)( (w ) & 0xff );
|
||||
return ab;
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,7 +227,7 @@ public final class BExpressionContext
|
|||
// see encoder for value rotation
|
||||
int dd = ctx.decodeDistance();
|
||||
int d = dd == 7 ? 1 : ( dd < 7 ? dd + 2 : dd + 1);
|
||||
if ( d >= lookupValues.get(inum).length ) d = 1; // map out-of-range to unkown
|
||||
if ( d >= lookupValues.get(inum).length ) d = 1; // map out-of-range to unknown
|
||||
ld[inum++] = d;
|
||||
}
|
||||
while( inum < ld.length ) ld[inum++] = 0;
|
||||
|
@ -257,10 +298,7 @@ public final class BExpressionContext
|
|||
for( int inum = 0; inum < lookupValues.size(); inum++ ) // loop over lookup names
|
||||
{
|
||||
BExpressionLookupValue[] va = lookupValues.get(inum);
|
||||
int dataIdx = lookupData[inum];
|
||||
if ( dataIdx >= va.length )
|
||||
throw new RuntimeException( "ups, inum=" + inum + " dataIdx=" + dataIdx + " va.length=" + va.length + " sb=" + sb );
|
||||
String value = va[dataIdx].toString();
|
||||
String value = va[lookupData[inum]].toString();
|
||||
if ( value != null && value.length() > 0 )
|
||||
{
|
||||
sb.append( " " + lookupNames.get( inum ) + "=" + value );
|
||||
|
@ -576,7 +614,7 @@ public final class BExpressionContext
|
|||
public boolean getBooleanLookupValue( String name )
|
||||
{
|
||||
Integer num = lookupNumbers.get( name );
|
||||
return num != null && lookupData[num.intValue()] != 0;
|
||||
return num != null && lookupData[num.intValue()] == 2;
|
||||
}
|
||||
|
||||
public void parseFile( File file, String readOnlyContext )
|
||||
|
|
|
@ -82,7 +82,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
|||
return null;
|
||||
}
|
||||
|
||||
public void writeNodeData( DataOutputStream os ) throws IOException
|
||||
public void writeNodeData( DataOutputStream os, boolean writeVarLength ) throws IOException
|
||||
{
|
||||
int lonIdx = ilon/62500;
|
||||
int latIdx = ilat/62500;
|
||||
|
@ -131,45 +131,68 @@ public class OsmNodeP implements Comparable<OsmNodeP>
|
|||
|
||||
OsmNodeP target = link.targetNode;
|
||||
int tranferbit = target.isTransferNode() ? TRANSFERNODE_BITMASK : 0;
|
||||
int writedescbit = link.descriptionBitmap != lastDescription ? WRITEDESC_BITMASK : 0;
|
||||
int nodedescbit = nodeDescription != null ? NODEDESC_BITMASK : 0;
|
||||
|
||||
if ( skipDetailBit != 0 )
|
||||
int writedescbit = 0;
|
||||
if ( skipDetailBit == 0 ) // check if description changed
|
||||
{
|
||||
writedescbit = 0;
|
||||
int inverseBitByteIndex = writeVarLength ? 0 : 7;
|
||||
boolean inverseDirection = link instanceof OsmLinkPReverse;
|
||||
byte[] ab = link.descriptionBitmap;
|
||||
int abLen = ab.length;
|
||||
int lastLen = lastDescription == null ? 0 : lastDescription.length;
|
||||
boolean equalsCurrent = abLen == lastLen;
|
||||
if ( equalsCurrent )
|
||||
{
|
||||
for( int i=0; i<abLen; i++ )
|
||||
{
|
||||
byte b = ab[i];
|
||||
if ( i == inverseBitByteIndex && inverseDirection ) b ^= 1;
|
||||
if ( b != lastDescription[i] ) { equalsCurrent = false; break; }
|
||||
}
|
||||
}
|
||||
if ( !equalsCurrent )
|
||||
{
|
||||
writedescbit = WRITEDESC_BITMASK;
|
||||
lastDescription = new byte[abLen];
|
||||
System.arraycopy( ab, 0, lastDescription, 0 , abLen );
|
||||
if ( inverseDirection ) lastDescription[inverseBitByteIndex] ^= 1;
|
||||
}
|
||||
|
||||
}
|
||||
int targetLonIdx = target.ilon/62500;
|
||||
int targetLatIdx = target.ilat/62500;
|
||||
|
||||
int bm = tranferbit | writedescbit | nodedescbit | skipDetailBit;
|
||||
if ( writeVarLength ) bm |= VARIABLEDESC_BITMASK;
|
||||
|
||||
if ( targetLonIdx == lonIdx && targetLatIdx == latIdx )
|
||||
{
|
||||
// reduced position for internal target
|
||||
os2.writeByte( tranferbit | writedescbit | nodedescbit | skipDetailBit | VARIABLEDESC_BITMASK );
|
||||
os2.writeByte( bm );
|
||||
os2.writeShort( (short)(target.ilon - lonIdx*62500 - 31250) );
|
||||
os2.writeShort( (short)(target.ilat - latIdx*62500 - 31250) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// full position for external target
|
||||
os2.writeByte( tranferbit | writedescbit | nodedescbit | skipDetailBit | EXTERNAL_BITMASK | VARIABLEDESC_BITMASK );
|
||||
os2.writeByte( bm | EXTERNAL_BITMASK );
|
||||
os2.writeInt( target.ilon );
|
||||
os2.writeInt( target.ilat );
|
||||
}
|
||||
if ( writedescbit != 0 )
|
||||
{
|
||||
// write the way description, code direction into the first bit
|
||||
byte[] dbytes = link.descriptionBitmap;
|
||||
int len = dbytes.length;
|
||||
os2.writeByte( len );
|
||||
os2.writeByte( link instanceof OsmLinkPReverse ? dbytes[0] | 1 : dbytes[0] );
|
||||
if ( len > 1 ) os2.write( dbytes, 1, len-1 );
|
||||
int len = lastDescription.length;
|
||||
if ( writeVarLength ) os2.writeByte( len );
|
||||
os2.write( lastDescription, 0, len );
|
||||
}
|
||||
if ( nodedescbit != 0 )
|
||||
{
|
||||
os2.writeByte( nodeDescription.length ); os2.write( nodeDescription );
|
||||
if ( writeVarLength ) os2.writeByte( nodeDescription.length );
|
||||
os2.write( nodeDescription );
|
||||
nodeDescription = null;
|
||||
}
|
||||
lastDescription = link.descriptionBitmap;
|
||||
|
||||
if ( tranferbit == 0)
|
||||
{
|
||||
|
|
|
@ -40,6 +40,7 @@ public class WayLinker extends MapCreatorBase
|
|||
private CompactLongSet borderSet;
|
||||
private short lookupVersion;
|
||||
private short lookupMinorVersion;
|
||||
private boolean writeVarLength;
|
||||
|
||||
private long creationTimeStamp;
|
||||
|
||||
|
@ -81,6 +82,7 @@ public class WayLinker extends MapCreatorBase
|
|||
expctxWay.readMetaData( lookupFile );
|
||||
lookupVersion = expctxWay.lookupVersion;
|
||||
lookupMinorVersion = expctxWay.lookupMinorVersion;
|
||||
writeVarLength = expctxWay.readVarLength;
|
||||
expctxWay.parseFile( profileFile, "global" );
|
||||
|
||||
creationTimeStamp = System.currentTimeMillis();
|
||||
|
@ -268,7 +270,7 @@ public class WayLinker extends MapCreatorBase
|
|||
for( int ni=0; ni<subList.size(); ni++ )
|
||||
{
|
||||
OsmNodeP n = subList.get(ni);
|
||||
n.writeNodeData( dos );
|
||||
n.writeNodeData( dos, writeVarLength );
|
||||
}
|
||||
dos.close();
|
||||
byte[] subBytes = bos.toByteArray();
|
||||
|
|
|
@ -40,10 +40,10 @@ assign caraccess
|
|||
switch or highway=residential highway=living_street 1
|
||||
switch highway=service 1
|
||||
0
|
||||
or access=yes or access=designated access=destination
|
||||
or access=yes or access=permissive or access=designated access=destination
|
||||
or vehicle=yes or vehicle=designated vehicle=destination
|
||||
or motor_vehicle=yes or motor_vehicle=designated motor_vehicle=destination
|
||||
or motorcar=yes or motorcar=designated motorcar=destination
|
||||
or motor_vehicle=yes or motor_vehicle=permissive or motor_vehicle=designated motor_vehicle=destination
|
||||
or motorcar=yes or motorcar=permissive or motorcar=designated motorcar=destination
|
||||
|
||||
assign accesspenalty
|
||||
switch caraccess
|
||||
|
@ -97,10 +97,10 @@ assign caraccess
|
|||
switch barrier=lift_gate 0
|
||||
switch barrier=cycle_barrier 0
|
||||
1
|
||||
or access=yes or access=designated access=destination
|
||||
or vehicle=yes or vehicle=designated vehicle=destination
|
||||
or motor_vehicle=yes or motor_vehicle=designated motor_vehicle=destination
|
||||
or motorcar=yes or motorcar=designated motorcar=destination
|
||||
or access=yes access=permissive or access=designated access=destination
|
||||
or vehicle=yes or vehicle=permissive or vehicle=designated vehicle=destination
|
||||
or motor_vehicle=yes or motor_vehicle=permissive or motor_vehicle=designated motor_vehicle=destination
|
||||
or motorcar=yes or motorcar=permissive or motorcar=designated motorcar=destination
|
||||
|
||||
assign initialcost
|
||||
switch caraccess
|
||||
|
|
|
@ -29,7 +29,8 @@ assign uphillcutoff 1.5
|
|||
|
||||
---context:way # following code refers to way-tags
|
||||
|
||||
|
||||
assign any_cycleroute or route_bicycle_icn=yes or route_bicycle_ncn=yes or route_bicycle_rcn=yes route_bicycle_lcn=yes
|
||||
assign nodeaccessgranted or any_cycleroute lcn=yes
|
||||
|
||||
assign ispaved or surface=paved or surface=asphalt or surface=concrete surface=paving_stones
|
||||
assign isunpaved not or surface= or ispaved or surface=fine_gravel surface=cobblestone
|
||||
|
@ -53,7 +54,7 @@ assign defaultaccess
|
|||
# calculate logical bike access
|
||||
#
|
||||
assign bikeaccess
|
||||
or longdistancecycleway=yes
|
||||
or any_cycleroute
|
||||
switch bicycle=
|
||||
switch vehicle=
|
||||
defaultaccess
|
||||
|
@ -140,7 +141,7 @@ assign defaultaccess
|
|||
1
|
||||
|
||||
assign bikeaccess
|
||||
or or longdistancecycleway=yes lcn=yes
|
||||
or nodeaccessgranted=yes
|
||||
switch bicycle=
|
||||
switch vehicle=
|
||||
defaultaccess
|
||||
|
|
|
@ -11,6 +11,9 @@ assign validForFoot 1
|
|||
|
||||
---context:way # following code refers to way-tags
|
||||
|
||||
assign any_cycleroute or route_bicycle_icn=yes or route_bicycle_ncn=yes or route_bicycle_rcn=yes route_bicycle_lcn=yes
|
||||
assign nodeaccessgranted or any_cycleroute lcn=yes
|
||||
|
||||
assign turncost 0
|
||||
|
||||
assign initialcost switch highway=ferry 10000 0
|
||||
|
@ -30,7 +33,7 @@ assign defaultaccess
|
|||
# calculate logical bike access
|
||||
#
|
||||
assign bikeaccess
|
||||
or longdistancecycleway=yes
|
||||
or any_cycleroute
|
||||
switch bicycle=
|
||||
switch vehicle=
|
||||
defaultaccess
|
||||
|
@ -69,7 +72,7 @@ assign defaultaccess
|
|||
1
|
||||
|
||||
assign bikeaccess
|
||||
or or longdistancecycleway=yes lcn=yes
|
||||
or nodeaccessgranted=yes
|
||||
switch bicycle=
|
||||
switch vehicle=
|
||||
defaultaccess
|
||||
|
|
|
@ -34,7 +34,7 @@ assign any_cycleroute or route_bicycle_icn=yes or route_bicycle_ncn=yes or route
|
|||
assign nodeaccessgranted or any_cycleroute lcn=yes
|
||||
|
||||
assign is_ldcr and any_cycleroute not ignore_cycleroutes
|
||||
assign isbike or bicycle=yes or bicycle=designated lcn=yes
|
||||
assign isbike or bicycle=yes or or bicycle=permissive bicycle=designated lcn=yes
|
||||
assign ispaved or surface=paved or surface=asphalt or surface=concrete surface=paving_stones
|
||||
assign isunpaved not or surface= or ispaved or surface=fine_gravel surface=cobblestone
|
||||
assign probablyGood or ispaved and isbike not isunpaved
|
||||
|
|
Loading…
Reference in a new issue