Added pbf-parser + mapcreation-scripts
This commit is contained in:
parent
eebba6eb8d
commit
309b9b3bbc
17 changed files with 612 additions and 164 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
target/
|
||||
*.BAK
|
|
@ -88,7 +88,7 @@ public class WayLinker extends MapCreatorBase
|
|||
|
||||
// read this tile's nodes
|
||||
readingBorder = false;
|
||||
new NodeIterator( this, false ).processFile( nodeFile );
|
||||
new NodeIterator( this, true ).processFile( nodeFile );
|
||||
|
||||
// freeze the nodes-map
|
||||
FrozenLongMap<OsmNodeP> nodesMapFrozen = new FrozenLongMap<OsmNodeP>( nodesMap );
|
||||
|
|
1
brouter-routing-app/.gitignore
vendored
Normal file
1
brouter-routing-app/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
gen/
|
|
@ -1,5 +0,0 @@
|
|||
package btools.routingapp;
|
||||
|
||||
public final class BuildConfig {
|
||||
public static final boolean DEBUG = true;
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/*
|
||||
* This file is auto-generated. DO NOT MODIFY.
|
||||
* Original file: C:\\brouter\\brouter-routing-app\\src\\main\\java\\btools\\routingapp\\IBRouterService.aidl
|
||||
*/
|
||||
package btools.routingapp;
|
||||
public interface IBRouterService extends android.os.IInterface
|
||||
{
|
||||
/** Local-side IPC implementation stub class. */
|
||||
public static abstract class Stub extends android.os.Binder implements btools.routingapp.IBRouterService
|
||||
{
|
||||
private static final java.lang.String DESCRIPTOR = "btools.routingapp.IBRouterService";
|
||||
/** Construct the stub at attach it to the interface. */
|
||||
public Stub()
|
||||
{
|
||||
this.attachInterface(this, DESCRIPTOR);
|
||||
}
|
||||
/**
|
||||
* Cast an IBinder object into an btools.routingapp.IBRouterService interface,
|
||||
* generating a proxy if needed.
|
||||
*/
|
||||
public static btools.routingapp.IBRouterService asInterface(android.os.IBinder obj)
|
||||
{
|
||||
if ((obj==null)) {
|
||||
return null;
|
||||
}
|
||||
android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
|
||||
if (((iin!=null)&&(iin instanceof btools.routingapp.IBRouterService))) {
|
||||
return ((btools.routingapp.IBRouterService)iin);
|
||||
}
|
||||
return new btools.routingapp.IBRouterService.Stub.Proxy(obj);
|
||||
}
|
||||
@Override public android.os.IBinder asBinder()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case INTERFACE_TRANSACTION:
|
||||
{
|
||||
reply.writeString(DESCRIPTOR);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getTrackFromParams:
|
||||
{
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.os.Bundle _arg0;
|
||||
if ((0!=data.readInt())) {
|
||||
_arg0 = android.os.Bundle.CREATOR.createFromParcel(data);
|
||||
}
|
||||
else {
|
||||
_arg0 = null;
|
||||
}
|
||||
java.lang.String _result = this.getTrackFromParams(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeString(_result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onTransact(code, data, reply, flags);
|
||||
}
|
||||
private static class Proxy implements btools.routingapp.IBRouterService
|
||||
{
|
||||
private android.os.IBinder mRemote;
|
||||
Proxy(android.os.IBinder remote)
|
||||
{
|
||||
mRemote = remote;
|
||||
}
|
||||
@Override public android.os.IBinder asBinder()
|
||||
{
|
||||
return mRemote;
|
||||
}
|
||||
public java.lang.String getInterfaceDescriptor()
|
||||
{
|
||||
return DESCRIPTOR;
|
||||
}
|
||||
//param params--> Map of params:
|
||||
// "pathToFileResult"-->String with the path to where the result must be saved, including file name and extension
|
||||
// -->if null, the track is passed via the return argument
|
||||
// "maxRunningTime"-->String with a number of seconds for the routing timeout, default = 60
|
||||
// "trackFormat"-->[kml|gpx] default = gpx
|
||||
// "lats"-->double[] array of latitudes; 2 values at least.
|
||||
// "lons"-->double[] array of longitudes; 2 values at least.
|
||||
// "nogoLats"-->double[] array of nogo latitudes; may be null.
|
||||
// "nogoLons"-->double[] array of nogo longitudes; may be null.
|
||||
// "nogoRadi"-->double[] array of nogo radius in meters; may be null.
|
||||
// "fast"-->[0|1]
|
||||
// "v"-->[motorcar|bicycle|foot]
|
||||
//return null if all ok and no path given, the track if ok and path given, an error message if it was wrong
|
||||
//call in a background thread, heavy task!
|
||||
|
||||
@Override public java.lang.String getTrackFromParams(android.os.Bundle params) throws android.os.RemoteException
|
||||
{
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
java.lang.String _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
if ((params!=null)) {
|
||||
_data.writeInt(1);
|
||||
params.writeToParcel(_data, 0);
|
||||
}
|
||||
else {
|
||||
_data.writeInt(0);
|
||||
}
|
||||
mRemote.transact(Stub.TRANSACTION_getTrackFromParams, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.readString();
|
||||
}
|
||||
finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
}
|
||||
static final int TRANSACTION_getTrackFromParams = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
|
||||
}
|
||||
//param params--> Map of params:
|
||||
// "pathToFileResult"-->String with the path to where the result must be saved, including file name and extension
|
||||
// -->if null, the track is passed via the return argument
|
||||
// "maxRunningTime"-->String with a number of seconds for the routing timeout, default = 60
|
||||
// "trackFormat"-->[kml|gpx] default = gpx
|
||||
// "lats"-->double[] array of latitudes; 2 values at least.
|
||||
// "lons"-->double[] array of longitudes; 2 values at least.
|
||||
// "nogoLats"-->double[] array of nogo latitudes; may be null.
|
||||
// "nogoLons"-->double[] array of nogo longitudes; may be null.
|
||||
// "nogoRadi"-->double[] array of nogo radius in meters; may be null.
|
||||
// "fast"-->[0|1]
|
||||
// "v"-->[motorcar|bicycle|foot]
|
||||
//return null if all ok and no path given, the track if ok and path given, an error message if it was wrong
|
||||
//call in a background thread, heavy task!
|
||||
|
||||
public java.lang.String getTrackFromParams(android.os.Bundle params) throws android.os.RemoteException;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package btools.routingapp;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int icon=0x7f020000;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int main=0x7f030000;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int app_name=0x7f040000;
|
||||
}
|
||||
}
|
2
misc/pbfparser/.gitignore
vendored
Normal file
2
misc/pbfparser/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.jar
|
||||
btools/
|
270
misc/pbfparser/BPbfBlobDecoder.java
Normal file
270
misc/pbfparser/BPbfBlobDecoder.java
Normal file
|
@ -0,0 +1,270 @@
|
|||
package btools.mapcreator;
|
||||
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import org.openstreetmap.osmosis.osmbinary.Fileformat;
|
||||
import org.openstreetmap.osmosis.osmbinary.Osmformat;
|
||||
import btools.util.LongList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.zip.DataFormatException;
|
||||
import java.util.zip.Inflater;
|
||||
|
||||
/**
|
||||
* Converts PBF block data into decoded entities ready to be passed into an Osmosis pipeline. This
|
||||
* class is designed to be passed into a pool of worker threads to allow multi-threaded decoding.
|
||||
* <p/>
|
||||
* @author Brett Henderson
|
||||
*/
|
||||
public class BPbfBlobDecoder
|
||||
{
|
||||
private String blobType;
|
||||
private byte[] rawBlob;
|
||||
|
||||
private OsmParser parser;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* <p/>
|
||||
* @param blobType The type of blob.
|
||||
* @param rawBlob The raw data of the blob.
|
||||
* @param listener The listener for receiving decoding results.
|
||||
*/
|
||||
public BPbfBlobDecoder( String blobType, byte[] rawBlob, OsmParser parser )
|
||||
{
|
||||
this.blobType = blobType;
|
||||
this.rawBlob = rawBlob;
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public void process() throws Exception
|
||||
{
|
||||
if ("OSMHeader".equals(blobType))
|
||||
{
|
||||
processOsmHeader(readBlobContent());
|
||||
|
||||
} else if ("OSMData".equals(blobType))
|
||||
{
|
||||
processOsmPrimitives(readBlobContent());
|
||||
|
||||
} else
|
||||
{
|
||||
System.out.println("Skipping unrecognised blob type " + blobType);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] readBlobContent() throws IOException
|
||||
{
|
||||
Fileformat.Blob blob = Fileformat.Blob.parseFrom(rawBlob);
|
||||
byte[] blobData;
|
||||
|
||||
if (blob.hasRaw())
|
||||
{
|
||||
blobData = blob.getRaw().toByteArray();
|
||||
} else if (blob.hasZlibData())
|
||||
{
|
||||
Inflater inflater = new Inflater();
|
||||
inflater.setInput(blob.getZlibData().toByteArray());
|
||||
blobData = new byte[blob.getRawSize()];
|
||||
try
|
||||
{
|
||||
inflater.inflate(blobData);
|
||||
} catch (DataFormatException e)
|
||||
{
|
||||
throw new RuntimeException("Unable to decompress PBF blob.", e);
|
||||
}
|
||||
if (!inflater.finished())
|
||||
{
|
||||
throw new RuntimeException("PBF blob contains incomplete compressed data.");
|
||||
}
|
||||
} else
|
||||
{
|
||||
throw new RuntimeException("PBF blob uses unsupported compression, only raw or zlib may be used.");
|
||||
}
|
||||
|
||||
return blobData;
|
||||
}
|
||||
|
||||
private void processOsmHeader( byte[] data ) throws InvalidProtocolBufferException
|
||||
{
|
||||
Osmformat.HeaderBlock header = Osmformat.HeaderBlock.parseFrom(data);
|
||||
|
||||
// Build the list of active and unsupported features in the file.
|
||||
List<String> supportedFeatures = Arrays.asList("OsmSchema-V0.6", "DenseNodes");
|
||||
List<String> activeFeatures = new ArrayList<String>();
|
||||
List<String> unsupportedFeatures = new ArrayList<String>();
|
||||
for (String feature : header.getRequiredFeaturesList())
|
||||
{
|
||||
if (supportedFeatures.contains(feature))
|
||||
{
|
||||
activeFeatures.add(feature);
|
||||
} else
|
||||
{
|
||||
unsupportedFeatures.add(feature);
|
||||
}
|
||||
}
|
||||
|
||||
// We can't continue if there are any unsupported features. We wait
|
||||
// until now so that we can display all unsupported features instead of
|
||||
// just the first one we encounter.
|
||||
if (unsupportedFeatures.size() > 0)
|
||||
{
|
||||
throw new RuntimeException("PBF file contains unsupported features " + unsupportedFeatures);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Map<String, String> buildTags( List<Integer> keys, List<Integer> values, BPbfFieldDecoder fieldDecoder )
|
||||
{
|
||||
|
||||
Iterator<Integer> keyIterator = keys.iterator();
|
||||
Iterator<Integer> valueIterator = values.iterator();
|
||||
if (keyIterator.hasNext())
|
||||
{
|
||||
Map<String, String> tags = new HashMap<String, String>();
|
||||
while (keyIterator.hasNext())
|
||||
{
|
||||
String key = fieldDecoder.decodeString(keyIterator.next());
|
||||
String value = fieldDecoder.decodeString(valueIterator.next());
|
||||
tags.put(key, value);
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processNodes( List<Osmformat.Node> nodes, BPbfFieldDecoder fieldDecoder )
|
||||
{
|
||||
for (Osmformat.Node node : nodes)
|
||||
{
|
||||
Map<String, String> tags = buildTags(node.getKeysList(), node.getValsList(), fieldDecoder);
|
||||
|
||||
parser.addNode( node.getId(), tags, fieldDecoder.decodeLatitude(node
|
||||
.getLat()), fieldDecoder.decodeLatitude(node.getLon()));
|
||||
}
|
||||
}
|
||||
|
||||
private void processNodes( Osmformat.DenseNodes nodes, BPbfFieldDecoder fieldDecoder )
|
||||
{
|
||||
List<Long> idList = nodes.getIdList();
|
||||
List<Long> latList = nodes.getLatList();
|
||||
List<Long> lonList = nodes.getLonList();
|
||||
|
||||
Iterator<Integer> keysValuesIterator = nodes.getKeysValsList().iterator();
|
||||
|
||||
long nodeId = 0;
|
||||
long latitude = 0;
|
||||
long longitude = 0;
|
||||
|
||||
for (int i = 0; i < idList.size(); i++)
|
||||
{
|
||||
// Delta decode node fields.
|
||||
nodeId += idList.get(i);
|
||||
latitude += latList.get(i);
|
||||
longitude += lonList.get(i);
|
||||
|
||||
// Build the tags. The key and value string indexes are sequential
|
||||
// in the same PBF array. Each set of tags is delimited by an index
|
||||
// with a value of 0.
|
||||
Map<String, String> tags = null;
|
||||
while (keysValuesIterator.hasNext())
|
||||
{
|
||||
int keyIndex = keysValuesIterator.next();
|
||||
if (keyIndex == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
int valueIndex = keysValuesIterator.next();
|
||||
|
||||
if (tags == null)
|
||||
{
|
||||
tags = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
tags.put(fieldDecoder.decodeString(keyIndex), fieldDecoder.decodeString(valueIndex));
|
||||
}
|
||||
|
||||
parser.addNode( nodeId, tags, ((double) latitude) / 10000000, ((double) longitude) / 10000000);
|
||||
}
|
||||
}
|
||||
|
||||
private void processWays( List<Osmformat.Way> ways, BPbfFieldDecoder fieldDecoder )
|
||||
{
|
||||
for (Osmformat.Way way : ways)
|
||||
{
|
||||
Map<String, String> tags = buildTags(way.getKeysList(), way.getValsList(), fieldDecoder);
|
||||
|
||||
// Build up the list of way nodes for the way. The node ids are
|
||||
// delta encoded meaning that each id is stored as a delta against
|
||||
// the previous one.
|
||||
long nodeId = 0;
|
||||
LongList wayNodes = new LongList( 16 );
|
||||
for (long nodeIdOffset : way.getRefsList())
|
||||
{
|
||||
nodeId += nodeIdOffset;
|
||||
wayNodes.add(nodeId);
|
||||
}
|
||||
|
||||
parser.addWay( way.getId(), tags, wayNodes );
|
||||
}
|
||||
}
|
||||
|
||||
private LongList buildRelationMembers(
|
||||
List<Long> memberIds, List<Integer> memberRoles, List<Osmformat.Relation.MemberType> memberTypes,
|
||||
BPbfFieldDecoder fieldDecoder )
|
||||
{
|
||||
LongList wayIds = new LongList( 16 );
|
||||
|
||||
|
||||
Iterator<Long> memberIdIterator = memberIds.iterator();
|
||||
Iterator<Integer> memberRoleIterator = memberRoles.iterator();
|
||||
Iterator<Osmformat.Relation.MemberType> memberTypeIterator = memberTypes.iterator();
|
||||
|
||||
// Build up the list of relation members for the way. The member ids are
|
||||
// delta encoded meaning that each id is stored as a delta against
|
||||
// the previous one.
|
||||
long refId = 0;
|
||||
while (memberIdIterator.hasNext())
|
||||
{
|
||||
Osmformat.Relation.MemberType memberType = memberTypeIterator.next();
|
||||
refId += memberIdIterator.next();
|
||||
|
||||
String role = fieldDecoder.decodeString( memberRoleIterator.next() );
|
||||
|
||||
if ( memberType == Osmformat.Relation.MemberType.WAY ) // currently just waymembers
|
||||
{
|
||||
wayIds.add( refId );
|
||||
}
|
||||
}
|
||||
return wayIds;
|
||||
}
|
||||
|
||||
private void processRelations( List<Osmformat.Relation> relations, BPbfFieldDecoder fieldDecoder )
|
||||
{
|
||||
for (Osmformat.Relation relation : relations)
|
||||
{
|
||||
Map<String, String> tags = buildTags(relation.getKeysList(), relation.getValsList(), fieldDecoder);
|
||||
|
||||
LongList wayIds = buildRelationMembers( relation.getMemidsList(), relation.getRolesSidList(),
|
||||
relation.getTypesList(), fieldDecoder);
|
||||
|
||||
parser.addRelation( relation.getId(), tags, wayIds );
|
||||
}
|
||||
}
|
||||
|
||||
private void processOsmPrimitives( byte[] data ) throws InvalidProtocolBufferException
|
||||
{
|
||||
Osmformat.PrimitiveBlock block = Osmformat.PrimitiveBlock.parseFrom(data);
|
||||
BPbfFieldDecoder fieldDecoder = new BPbfFieldDecoder(block);
|
||||
|
||||
for (Osmformat.PrimitiveGroup primitiveGroup : block.getPrimitivegroupList())
|
||||
{
|
||||
processNodes(primitiveGroup.getDense(), fieldDecoder);
|
||||
processNodes(primitiveGroup.getNodesList(), fieldDecoder);
|
||||
processWays(primitiveGroup.getWaysList(), fieldDecoder);
|
||||
processRelations(primitiveGroup.getRelationsList(), fieldDecoder);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
85
misc/pbfparser/BPbfFieldDecoder.java
Normal file
85
misc/pbfparser/BPbfFieldDecoder.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package btools.mapcreator;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.openstreetmap.osmosis.osmbinary.Osmformat;
|
||||
|
||||
/**
|
||||
* Manages decoding of the lower level PBF data structures.
|
||||
* <p/>
|
||||
* @author Brett Henderson
|
||||
* <p/>
|
||||
*/
|
||||
public class BPbfFieldDecoder
|
||||
{
|
||||
private static final double COORDINATE_SCALING_FACTOR = 0.000000001;
|
||||
private String[] strings;
|
||||
private int coordGranularity;
|
||||
private long coordLatitudeOffset;
|
||||
private long coordLongitudeOffset;
|
||||
private int dateGranularity;
|
||||
|
||||
/**
|
||||
* Creates a new instance.
|
||||
* <p/>
|
||||
* @param primitiveBlock The primitive block containing the fields to be decoded.
|
||||
*/
|
||||
public BPbfFieldDecoder( Osmformat.PrimitiveBlock primitiveBlock )
|
||||
{
|
||||
this.coordGranularity = primitiveBlock.getGranularity();
|
||||
this.coordLatitudeOffset = primitiveBlock.getLatOffset();
|
||||
this.coordLongitudeOffset = primitiveBlock.getLonOffset();
|
||||
this.dateGranularity = primitiveBlock.getDateGranularity();
|
||||
|
||||
Osmformat.StringTable stringTable = primitiveBlock.getStringtable();
|
||||
strings = new String[stringTable.getSCount()];
|
||||
for (int i = 0; i < strings.length; i++)
|
||||
{
|
||||
strings[i] = stringTable.getS(i).toStringUtf8();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a raw latitude value into degrees.
|
||||
* <p/>
|
||||
* @param rawLatitude The PBF encoded value.
|
||||
* @return The latitude in degrees.
|
||||
*/
|
||||
public double decodeLatitude( long rawLatitude )
|
||||
{
|
||||
return COORDINATE_SCALING_FACTOR * (coordLatitudeOffset + (coordGranularity * rawLatitude));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a raw longitude value into degrees.
|
||||
* <p/>
|
||||
* @param rawLongitude The PBF encoded value.
|
||||
* @return The longitude in degrees.
|
||||
*/
|
||||
public double decodeLongitude( long rawLongitude )
|
||||
{
|
||||
return COORDINATE_SCALING_FACTOR * (coordLongitudeOffset + (coordGranularity * rawLongitude));
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a raw timestamp value into a Date.
|
||||
* <p/>
|
||||
* @param rawTimestamp The PBF encoded timestamp.
|
||||
* @return The timestamp as a Date.
|
||||
*/
|
||||
public Date decodeTimestamp( long rawTimestamp )
|
||||
{
|
||||
return new Date(dateGranularity * rawTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a raw string into a String.
|
||||
* <p/>
|
||||
* @param rawString The PBF encoding string.
|
||||
* @return The string as a String.
|
||||
*/
|
||||
public String decodeString( int rawString )
|
||||
{
|
||||
return strings[rawString];
|
||||
}
|
||||
}
|
110
misc/pbfparser/OsmParser.java
Normal file
110
misc/pbfparser/OsmParser.java
Normal file
|
@ -0,0 +1,110 @@
|
|||
package btools.mapcreator;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
import btools.util.*;
|
||||
|
||||
import org.openstreetmap.osmosis.osmbinary.Fileformat;
|
||||
|
||||
/**
|
||||
* Parser for OSM data
|
||||
*
|
||||
* @author ab
|
||||
*/
|
||||
public class OsmParser extends MapCreatorBase
|
||||
{
|
||||
private BufferedReader _br;
|
||||
|
||||
private NodeListener nListener;
|
||||
private WayListener wListener;
|
||||
private RelationListener rListener;
|
||||
|
||||
public void readMap( File mapFile,
|
||||
NodeListener nListener,
|
||||
WayListener wListener,
|
||||
RelationListener rListener ) throws Exception
|
||||
{
|
||||
this.nListener = nListener;
|
||||
this.wListener = wListener;
|
||||
this.rListener = rListener;
|
||||
|
||||
System.out.println( "*** PBF Parsing: " + mapFile );
|
||||
|
||||
// once more for testing
|
||||
int rawBlobCount = 0;
|
||||
DataInputStream dis = new DataInputStream( new BufferedInputStream ( new FileInputStream( mapFile ) ) );
|
||||
for(;;)
|
||||
{
|
||||
int headerLength;
|
||||
try
|
||||
{
|
||||
headerLength = dis.readInt();
|
||||
}
|
||||
catch (EOFException e)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
byte[] headerBuffer = new byte[headerLength];
|
||||
dis.readFully(headerBuffer);
|
||||
Fileformat.BlobHeader blobHeader = Fileformat.BlobHeader.parseFrom(headerBuffer);
|
||||
|
||||
byte[] blobData = new byte[blobHeader.getDatasize()];
|
||||
dis.readFully(blobData);
|
||||
|
||||
new BPbfBlobDecoder( blobHeader.getType(), blobData, this ).process();
|
||||
|
||||
rawBlobCount++;
|
||||
}
|
||||
dis.close();
|
||||
System.out.println( "read raw blobs: " + rawBlobCount );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void addNode( long nid, Map<String, String> tags, double lat, double lon )
|
||||
{
|
||||
NodeData n = new NodeData( nid, lon, lat );
|
||||
n.setTags( (HashMap<String,String>)tags );
|
||||
try
|
||||
{
|
||||
nListener.nextNode( n );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
throw new RuntimeException( "error writing node: " + e );
|
||||
}
|
||||
}
|
||||
|
||||
public void addWay( long wid, Map<String, String> tags, LongList nodes )
|
||||
{
|
||||
WayData w = new WayData( wid, nodes );
|
||||
w.setTags( (HashMap<String,String>)tags );
|
||||
|
||||
try
|
||||
{
|
||||
wListener.nextWay( w );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
throw new RuntimeException( "error writing way: " + e );
|
||||
}
|
||||
}
|
||||
|
||||
public void addRelation( long rid, Map<String, String> tags, LongList wayIds )
|
||||
{
|
||||
RelationData r = new RelationData( rid, wayIds );
|
||||
r.setTags( (HashMap<String,String>)tags );
|
||||
|
||||
try
|
||||
{
|
||||
rListener.nextRelation( r );
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
throw new RuntimeException( "error writing relation: " + e );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
17
misc/pbfparser/README.txt
Normal file
17
misc/pbfparser/README.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
The pbf-parse is not included in the regular source tree
|
||||
to avoid the library dependencies to "osmosis" and "protobuf"
|
||||
|
||||
In order to run the mapcreator from a pbf-file (as it is
|
||||
done in the process_pbf_planet.sh script included in
|
||||
the git-repo), you have to build yourself the "pbfparser.jar"
|
||||
by doing the following:
|
||||
|
||||
-> get osmosis.jar
|
||||
-> get protobuf.jar
|
||||
-> copy the brouter...with_dependencies.jar and name it brouter.jar
|
||||
-> compile the PBF-Parser using:
|
||||
javac -d . -cp protobuf.jar;osmosis.jar;brouter.jar *.java
|
||||
-> pack protobuf.jar + osmosis.jar + btools/**.class alltogether in a jar "pbfparser.jar"
|
||||
|
||||
Alternativly, you can run the Mapcreator against a *xml.bz2 Database-Extract,
|
||||
then you don't need the pbf-parser.
|
1
misc/pbfparser/compile_parser.bat
Normal file
1
misc/pbfparser/compile_parser.bat
Normal file
|
@ -0,0 +1 @@
|
|||
javac -d . -cp protobuf.jar;osmosis.jar;brouter.jar BPbfFieldDecoder.java BPbfBlobDecoder.java OsmParser.java
|
28
misc/scripts/mapcreation/BRouterTests.java
Normal file
28
misc/scripts/mapcreation/BRouterTests.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
import java.io.*;
|
||||
|
||||
public class BRouterTests
|
||||
{
|
||||
public static void main( String[] args ) throws Exception
|
||||
{
|
||||
BufferedReader br = new BufferedReader( new FileReader( args[0] ) );
|
||||
|
||||
String lastname = "ups";
|
||||
for(;;)
|
||||
{
|
||||
|
||||
String line = br.readLine();
|
||||
if ( line == null ) break;
|
||||
line = line.trim();
|
||||
if ( line.length() == 0 ) continue;
|
||||
if ( !Character.isDigit( line.charAt( 0 ) ) )
|
||||
{
|
||||
lastname = line;
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println( "/java/bin/java -Xmx32m -jar brouter.jar segments " + line + " /var/www/brouter/profiles2/trekking.brf" );
|
||||
System.out.println( "mv mytrack0.gpx gpx/" + lastname + ".gpx" );
|
||||
System.out.println( "mv mylog0.csv csv/" + lastname + ".csv" );
|
||||
}
|
||||
}
|
||||
}
|
18
misc/scripts/mapcreation/all.brf
Normal file
18
misc/scripts/mapcreation/all.brf
Normal file
|
@ -0,0 +1,18 @@
|
|||
---context:global # following code refers to global config
|
||||
|
||||
# the elevation parameters
|
||||
|
||||
assign downhillcost 0
|
||||
assign downhillcutoff 1.5
|
||||
assign uphillcost 0
|
||||
assign uphillcutoff 1.5
|
||||
|
||||
---context:way # following code refers to way-tags
|
||||
|
||||
assign turncost 0
|
||||
assign initialcost 0
|
||||
assign costfactor 1
|
||||
|
||||
---context:node # following code refers to node tags
|
||||
|
||||
assign initialcost 0
|
3
misc/scripts/mapcreation/cronjob.sh
Normal file
3
misc/scripts/mapcreation/cronjob.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
cd /root/osm
|
||||
nohup ./process_pbf_planet.sh &
|
46
misc/scripts/mapcreation/process_pbf_planet.sh
Normal file
46
misc/scripts/mapcreation/process_pbf_planet.sh
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
wget -N http://planet.openstreetmap.org/pbf/planet-latest.osm.pbf
|
||||
|
||||
if test lastmaprun.date -nt planet-latest.osm.pbf; then
|
||||
echo "no osm update, exiting"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
touch lastmaprun.date
|
||||
|
||||
rm -rf /var/www/brouter/segments2_lastrun
|
||||
|
||||
mkdir tmp
|
||||
cd tmp
|
||||
mkdir nodetiles
|
||||
/java/bin/java -Xmx256m -Xms256m -Xmn32m -cp ../pbfparser.jar:../brouter.jar btools.mapcreator.OsmCutter ../lookups.dat nodetiles ways.dat cycleways.dat ../planet-latest.osm.pbf
|
||||
|
||||
mkdir ftiles
|
||||
/java/bin/java -Xmx512M -Xms512M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.NodeFilter nodetiles ways.dat ftiles
|
||||
|
||||
mkdir waytiles
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.WayCutter ftiles ways.dat waytiles cycleways.dat
|
||||
|
||||
mkdir waytiles55
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.WayCutter5 ftiles waytiles waytiles55 bordernids.dat
|
||||
|
||||
mkdir nodes55
|
||||
/java/bin/java -Xmx128M -Xms128M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.NodeCutter ftiles nodes55
|
||||
|
||||
mkdir unodes55
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.PosUnifier nodes55 unodes55 bordernids.dat bordernodes.dat /private-backup/srtm
|
||||
|
||||
mkdir segments
|
||||
mkdir segments/carsubset
|
||||
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -DuseDenseMaps=true btools.mapcreator.WayLinker unodes55 waytiles55 bordernodes.dat ../lookups.dat ../car-test.brf segments/carsubset cd5
|
||||
/java/bin/java -Xmx2600M -Xms2600M -Xmn32M -cp ../brouter.jar -Ddeletetmpfiles=true -DuseDenseMaps=true btools.mapcreator.WayLinker unodes55 waytiles55 bordernodes.dat ../lookups.dat ../all.brf segments rd5
|
||||
|
||||
cd ..
|
||||
rm -rf segments
|
||||
mv tmp/segments segments
|
||||
rm -rf tmp
|
||||
cp /var/www/brouter/segments2/.htaccess segments
|
||||
mv /var/www/brouter/segments2 /var/www/brouter/segments2_lastrun
|
||||
mv segments /var/www/brouter/segments2
|
29
misc/scripts/mapcreation/routetest.sh
Normal file
29
misc/scripts/mapcreation/routetest.sh
Normal file
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
set -e
|
||||
/java/bin/javac -d . BRouterTests.java
|
||||
rm -rf troutes
|
||||
mkdir troutes
|
||||
cd troutes
|
||||
mkdir gpxold
|
||||
mkdir gpxnew
|
||||
mkdir csvold
|
||||
mkdir csvnew
|
||||
/java/bin/javac -d . ../BRouterTests.java
|
||||
/java/bin/java -cp . BRouterTests ../examples.txt > dotests.sh
|
||||
chmod +x dotests.sh
|
||||
ln -s gpxnew gpx
|
||||
ln -s csvnew csv
|
||||
ln -s /var/www/brouter/segments2_lastrun segments
|
||||
cp /usr/lib/cgi-bin/brouter64.jar brouter.jar
|
||||
./dotests.sh
|
||||
rm gpx
|
||||
rm csv
|
||||
rm segments
|
||||
ln -s gpxold gpx
|
||||
ln -s csvold csv
|
||||
ln -s /var/www/brouter/segments2 segments
|
||||
./dotests.sh
|
||||
rm gpx
|
||||
rm csv
|
||||
rm segments
|
||||
rm *.class
|
Loading…
Reference in a new issue