aggregate similar way-descriptions
This commit is contained in:
parent
740d171813
commit
c38f9048de
4 changed files with 62 additions and 19 deletions
|
@ -5,10 +5,9 @@
|
|||
*/
|
||||
package btools.router;
|
||||
|
||||
import btools.expressions.BExpressionContext;
|
||||
|
||||
|
||||
final class MessageData
|
||||
final class MessageData implements Cloneable
|
||||
{
|
||||
int linkdist = 0;
|
||||
int linkelevationcost = 0;
|
||||
|
@ -44,5 +43,25 @@ final class MessageData
|
|||
+ "\t" + wayKeyValues
|
||||
+ "\t" + ( nodeKeyValues == null ? "" : nodeKeyValues );
|
||||
}
|
||||
|
||||
|
||||
void add( MessageData d )
|
||||
{
|
||||
linkdist += d.linkdist;
|
||||
linkelevationcost += d.linkelevationcost;
|
||||
linkturncost += d.linkturncost;
|
||||
linknodecost += d.linknodecost;
|
||||
linkinitcost+= d.linkinitcost;
|
||||
}
|
||||
|
||||
MessageData copy()
|
||||
{
|
||||
try
|
||||
{
|
||||
return (MessageData)clone();
|
||||
}
|
||||
catch( CloneNotSupportedException e )
|
||||
{
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ final class OsmPath implements OsmLinkHolder
|
|||
// the costfactor of the segment just before this paths position
|
||||
public float lastClassifier;
|
||||
|
||||
public String message;
|
||||
public MessageData message;
|
||||
|
||||
OsmPath()
|
||||
{
|
||||
|
@ -122,7 +122,7 @@ final class OsmPath implements OsmLinkHolder
|
|||
// if way description changed, store message
|
||||
if ( msgData.wayKeyValues != null && !sameData )
|
||||
{
|
||||
originElement.message = msgData.toMessage();
|
||||
originElement.message = msgData;
|
||||
msgData = new MessageData();
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ final class OsmPath implements OsmLinkHolder
|
|||
{
|
||||
originElement = new OsmPathElement( rc.ilonshortest, rc.ilatshortest, ele2, originElement );
|
||||
originElement.cost = cost;
|
||||
originElement.message = msgData.toMessage();
|
||||
originElement.message = msgData;
|
||||
}
|
||||
if ( rc.nogomatch )
|
||||
{
|
||||
|
@ -356,7 +356,7 @@ final class OsmPath implements OsmLinkHolder
|
|||
}
|
||||
}
|
||||
|
||||
message = msgData.toMessage();
|
||||
message = msgData;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ public final class OsmPathElement implements OsmPos
|
|||
private int ilon; // longitude
|
||||
private short selev; // longitude
|
||||
|
||||
public String message = null; // description
|
||||
public MessageData message = null; // description
|
||||
|
||||
public int cost;
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import btools.util.FrozenLongMap;
|
|||
public final class OsmTrack
|
||||
{
|
||||
// csv-header-line
|
||||
private static final String MESSAGES_HEADER = "Longitude\tLatitude\tElevation\tDistance\tCostPerKm\tElevCost\tTurnCost\tNodeCost\tInitialCost\tOsmTags";
|
||||
private static final String MESSAGES_HEADER = "Longitude\tLatitude\tElevation\tDistance\tCostPerKm\tElevCost\tTurnCost\tNodeCost\tInitialCost\tWayTags\tNodeTags";
|
||||
|
||||
public MatchedWaypoint endPoint;
|
||||
public long[] nogoChecksums;
|
||||
|
@ -78,6 +78,36 @@ public final class OsmTrack
|
|||
nodesMap = new FrozenLongMap<OsmPathElementHolder>( nodesMap );
|
||||
}
|
||||
|
||||
private ArrayList<String> aggregateMessages()
|
||||
{
|
||||
ArrayList<String> res = new ArrayList<String>();
|
||||
MessageData current = null;
|
||||
for( OsmPathElement n : nodes )
|
||||
{
|
||||
if ( n.message != null )
|
||||
{
|
||||
MessageData md = n.message.copy();
|
||||
if ( current != null )
|
||||
{
|
||||
if ( current.nodeKeyValues != null || !current.wayKeyValues.equals( md.wayKeyValues ) )
|
||||
{
|
||||
res.add( current.toMessage() );
|
||||
}
|
||||
else
|
||||
{
|
||||
md.add( current );
|
||||
}
|
||||
}
|
||||
current = md;
|
||||
}
|
||||
}
|
||||
if ( current != null )
|
||||
{
|
||||
res.add( current.toMessage() );
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* writes the track in binary-format to a file
|
||||
* @param filename the filename to write to
|
||||
|
@ -310,12 +340,9 @@ public final class OsmTrack
|
|||
sb.append( " \"cost\": \"" ).append( cost ).append( "\",\n" );
|
||||
sb.append( " \"messages\": [\n" );
|
||||
sb.append( " [\"").append( MESSAGES_HEADER.replaceAll("\t", "\", \"") ).append( "\"],\n" );
|
||||
for( OsmPathElement n : nodes )
|
||||
for( String m : aggregateMessages() )
|
||||
{
|
||||
if ( n.message != null )
|
||||
{
|
||||
sb.append( " [\"").append( n.message.replaceAll("\t", "\", \"") ).append( "\"],\n" );
|
||||
}
|
||||
sb.append( " [\"").append( m.replaceAll("\t", "\", \"") ).append( "\"],\n" );
|
||||
}
|
||||
sb.deleteCharAt( sb.lastIndexOf( "," ) );
|
||||
sb.append( " ]\n" );
|
||||
|
@ -377,12 +404,9 @@ public final class OsmTrack
|
|||
public void writeMessages( BufferedWriter bw, RoutingContext rc ) throws Exception
|
||||
{
|
||||
dumpLine( bw, MESSAGES_HEADER );
|
||||
for( OsmPathElement n : nodes )
|
||||
for( String m : aggregateMessages() )
|
||||
{
|
||||
if ( n.message != null )
|
||||
{
|
||||
dumpLine( bw, n.message );
|
||||
}
|
||||
dumpLine( bw, m );
|
||||
}
|
||||
if ( bw != null ) bw.close();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue