variable length tag descriptions (second thought)

This commit is contained in:
Arndt 2014-05-22 20:26:20 +02:00
parent a145230e0f
commit ba867b4779
20 changed files with 372 additions and 1334 deletions

View file

@ -168,8 +168,9 @@ public class OsmCutter extends MapCreatorBase
relsParsed++;
checkStats();
String route = r.getTag( "route" );
// filter out non-cycle relations
if ( ! "bicycle".equals( r.getTag( "route" ) ) )
if ( route == null )
{
return;
}
@ -177,6 +178,7 @@ public class OsmCutter extends MapCreatorBase
String network = r.getTag( "network" );
if ( network == null ) network = "";
writeId( cyclewayDos, r.rid );
cyclewayDos.writeUTF( route );
cyclewayDos.writeUTF( network );
for ( int i=0; i<r.ways.size();i++ )
{

View file

@ -42,6 +42,8 @@ public class OsmNodeP implements Comparable<OsmNodeP>
public boolean isBorder = false;
public final static int BRIDGE_AND_BIT = 1;
public final static int TUNNEL_AND_BIT = 2;
public byte wayAndBits = -1; // use for bridge/tunnel logic
@ -59,7 +61,7 @@ public class OsmNodeP implements Comparable<OsmNodeP>
public short getSElev()
{
// if all bridge or all tunnel, elevation=no-data
return (wayAndBits & 24) == 0 ? selev : Short.MIN_VALUE;
return (wayAndBits & ( BRIDGE_AND_BIT | TUNNEL_AND_BIT ) ) == 0 ? selev : Short.MIN_VALUE;
}
public double getElev()

View file

@ -0,0 +1,136 @@
package btools.mapcreator;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.File;
import java.util.HashMap;
import btools.expressions.BExpressionContext;
import btools.util.CompactLongSet;
import btools.util.FrozenLongSet;
/**
* RelationMerger does 1 step in map processing:
*
* - enrich ways with relation information
*
* @author ab
*/
public class RelationMerger extends MapCreatorBase
{
private HashMap<String,CompactLongSet> routesets;
private CompactLongSet routesetall;
private BExpressionContext expctxReport;
private BExpressionContext expctxCheck;
private DataOutputStream wayOutStream;
public static void main(String[] args) throws Exception
{
System.out.println("*** RelationMerger: merge relation bits into ways" );
if (args.length != 6)
{
System.out.println("usage: java RelationMerger <way-file-in> <way-file-out> <relation-file> <lookup-file> <report-profile> <check-profile>" );
return;
}
new RelationMerger().process( new File( args[0] ), new File( args[1] ), new File( args[2] ), new File( args[3] ), new File( args[4] ), new File( args[5] ) );
}
public void process( File wayFileIn, File wayFileOut, File relationFileIn, File lookupFile, File reportProfile, File checkProfile ) throws Exception
{
// read lookup + profile for relation access-check
expctxReport = new BExpressionContext("way");
expctxReport.readMetaData( lookupFile );
expctxReport.parseFile( reportProfile, "global" );
expctxCheck = new BExpressionContext("way");
expctxCheck.readMetaData( lookupFile );
expctxCheck.parseFile( checkProfile, "global" );
// *** read the relation file into sets for each processed tag
routesets = new HashMap<String,CompactLongSet>();
routesetall = new CompactLongSet();
DataInputStream dis = createInStream( relationFileIn );
try
{
for(;;)
{
long rid = readId( dis );
String route = dis.readUTF();
String network = dis.readUTF();
String tagname = "route_" + route + "_" + network;
CompactLongSet routeset = null;
if ( expctxCheck.getLookupNameIdx(tagname) >= 0 )
{
routeset = routesets.get( tagname );
if ( routeset == null )
{
routeset = new CompactLongSet();
routesets.put( tagname, routeset );
}
}
for(;;)
{
long wid = readId( dis );
if ( wid == -1 ) break;
if ( routeset != null && !routeset.contains( wid ) )
{
routeset.add( wid );
routesetall.add( wid );
}
}
}
}
catch( EOFException eof )
{
dis.close();
}
for( String tagname : routesets.keySet() )
{
CompactLongSet routeset = new FrozenLongSet( routesets.get( tagname ) );
routesets.put( tagname, routeset );
System.out.println( "marked " + routeset.size() + " ways for tag: " + tagname );
}
// *** finally process the way-file
wayOutStream = createOutStream( wayFileOut );
new WayIterator( this, true ).processFile( wayFileIn );
wayOutStream.close();
}
@Override
public void nextWay( WayData data ) throws Exception
{
// propagate the route-bits
if ( routesetall.contains( data.wid ) )
{
boolean ok = true;
// check access and log a warning for conflicts
expctxReport.evaluate( false, data.description, null );
boolean warn = expctxReport.getCostfactor() >= 10000.;
if ( warn )
{
expctxCheck.evaluate( false, data.description, null );
ok = expctxCheck.getCostfactor() < 10000.;
System.out.println( "** relation access conflict for wid = " + data.wid + " tags:" + expctxReport.getKeyValueDescription( data.description ) + " (ok=" + ok + ")" );
}
if ( ok )
{
for( String tagname : routesets.keySet() )
{
CompactLongSet routeset = routesets.get( tagname );
if ( routeset.contains( data.wid ) ) expctxReport.addLookupValue( tagname, 2 );
}
data.description = expctxReport.encode();
}
}
data.writeTo( wayOutStream );
}
}

View file

@ -1,13 +1,8 @@
package btools.mapcreator;
import java.io.DataInputStream;
import java.io.EOFException;
import java.io.File;
import btools.expressions.BExpressionContext;
import btools.util.CompactLongSet;
import btools.util.DenseLongMap;
import btools.util.FrozenLongSet;
import btools.util.TinyDenseLongMap;
/**
@ -20,63 +15,24 @@ import btools.util.TinyDenseLongMap;
*/
public class WayCutter extends MapCreatorBase
{
private CompactLongSet cyclewayset;
private DenseLongMap tileIndexMap;
private BExpressionContext expctxReport;
private BExpressionContext expctxCheck;
public static void main(String[] args) throws Exception
{
System.out.println("*** WayCutter: Soft-Cut way-data into tiles");
if (args.length != 7)
if (args.length != 4)
{
System.out.println("usage: java WayCutter <node-tiles-in> <way-file-in> <way-tiles-out> <relation-file> <lookup-file> <report-profile> <check-profile>" );
System.out.println("usage: java WayCutter <node-tiles-in> <way-file-in> <way-tiles-out> <relation-file>" );
return;
}
new WayCutter().process( new File( args[0] ), new File( args[1] ), new File( args[2] ), new File( args[3] ), new File( args[4] ), new File( args[5] ), new File( args[6] ) );
new WayCutter().process( new File( args[0] ), new File( args[1] ), new File( args[2] ), new File( args[3] ) );
}
public void process( File nodeTilesIn, File wayFileIn, File wayTilesOut, File relationFileIn, File lookupFile, File reportProfile, File checkProfile ) throws Exception
public void process( File nodeTilesIn, File wayFileIn, File wayTilesOut, File relationFileIn ) throws Exception
{
this.outTileDir = wayTilesOut;
// read lookup + profile for relation access-check
expctxReport = new BExpressionContext("way");
expctxReport.readMetaData( lookupFile );
expctxReport.parseFile( reportProfile, "global" );
expctxCheck = new BExpressionContext("way");
expctxCheck.readMetaData( lookupFile );
expctxCheck.parseFile( checkProfile, "global" );
// *** read the relation file into a set (currently cycleway processing only)
cyclewayset = new CompactLongSet();
DataInputStream dis = createInStream( relationFileIn );
try
{
for(;;)
{
long rid = readId( dis );
String network = dis.readUTF();
boolean goodNetwork = "lcn".equals( network ) || "rcn".equals( network ) || "ncn".equals( network ) || "icn".equals( network );
for(;;)
{
long wid = readId( dis );
if ( wid == -1 ) break;
if ( goodNetwork && !cyclewayset.contains( wid ) ) cyclewayset.add( wid );
}
}
}
catch( EOFException eof )
{
dis.close();
}
cyclewayset = new FrozenLongSet( cyclewayset );
System.out.println( "marked cycleways: " + cyclewayset.size() );
// *** read all nodes into tileIndexMap
tileIndexMap = Boolean.getBoolean( "useDenseMaps" ) ? new DenseLongMap( 6 ) : new TinyDenseLongMap();
new NodeIterator( this, false ).processDir( nodeTilesIn, ".tlf" );
@ -95,28 +51,6 @@ public class WayCutter extends MapCreatorBase
@Override
public void nextWay( WayData data ) throws Exception
{
// propagate the cycleway-bit
if ( cyclewayset.contains( data.wid ) )
{
boolean ok = true;
// check access and log a warning for conflicts
expctxReport.evaluate( false, data.description, null );
boolean warn = expctxReport.getCostfactor() >= 10000.;
if ( warn )
{
expctxCheck.evaluate( false, data.description, null );
ok = expctxCheck.getCostfactor() < 10000.;
System.out.println( "** relation access conflict for wid = " + data.wid + " tags:" + expctxReport.getKeyValueDescription( data.description ) + " (ok=" + ok + ")" );
}
if ( ok )
{
expctxReport.addLookupValue( "longdistancecycleway", 2 );
data.description = expctxReport.encode();
}
}
long waytileset = 0;
int nnodes = data.nodes.size();

View file

@ -1,11 +1,19 @@
package btools.mapcreator;
import java.io.*;
import java.util.*;
import btools.util.*;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.RandomAccessFile;
import java.util.Collections;
import java.util.List;
import btools.expressions.BExpressionContext;
import btools.util.CompactLongMap;
import btools.util.CompactLongSet;
import btools.util.Crc32;
import btools.util.FrozenLongMap;
import btools.util.FrozenLongSet;
import btools.util.LazyArrayOfLists;
/**
* WayLinker finally puts the pieces together
@ -139,11 +147,13 @@ public class WayLinker extends MapCreatorBase
boolean ok = expctxWay.getCostfactor() < 10000.;
expctxWay.evaluate( true, description, null );
ok |= expctxWay.getCostfactor() < 10000.;
byte bridgeTunnel = 0;
if ( expctxWay.getBooleanLookupValue( "bridge" ) ) bridgeTunnel |= OsmNodeP.BRIDGE_AND_BIT;
if ( expctxWay.getBooleanLookupValue( "tunnel" ) ) bridgeTunnel |= OsmNodeP.TUNNEL_AND_BIT;
if ( !ok ) return;
// byte lowbyte = (byte)description;
OsmNodeP n1 = null;
OsmNodeP n2 = null;
for (int i=0; i<way.nodes.size(); i++)
@ -166,7 +176,7 @@ public class WayLinker extends MapCreatorBase
}
if ( n2 != null )
{
// n2.wayAndBits &= lowbyte;
n2.wayAndBits &= bridgeTunnel;
// if ( n2 instanceof OsmNodePT ) ((OsmNodePT)n2).wayOrBits |= lowbyte;
}
}