I have succeded in creating a WayTagResolver that parses the duration and puts it into the osm_meta column. I therefore share the solution here, for others to use this or deveelop futher on it.
- Download osm2po
- In the plugins folder, extract osm2po-plugins-4.7.7-src.zip
- Enter the extracted folder, and STAY there :)
- Create a java file for storing the WayTagResolver in e.g. de/cm/osm2po/samples/FerryDurationResolver.java - code for this file will be shown below.
- Compile the Java file:
javac -d . -classpath ../../osm2po-core-4.7.7-signed.jar de/cm/osm2po/samples/FerryDurationResolver.java
- Create a new Jar file:
jar cf ../osm2po-plugins-4.7.7_custom.jar *
- in your osm2po.config file, add
wayTagResolver.class=de.cm.osm2po.samples.FerryDurationResolver
- When running osm2po (back to main folder), remember to include the newly created jar file in your classpath. I personally execute:
java -Xmx 4g -classpath osm2po-core-4.7.7-signed.jar:osm2po-plugins/osm2po-plugins-4.7.7_custom.jar:de.cm.osm2po.Main cmd=tjsp prefix=some_name "url"
And here is the code for my FerryDurationResolver.java
:
package de.cm.osm2po.samples;
import de.cm.osm2po.converter.DefaultWayTagResolver;
public class FerryDurationResolver extends DefaultWayTagResolver {
private String metadata;
@Override
public void onTags(long entityId) {
this.metadata = null;
super.onTags(entityId);
}
@Override
public void onTag(String key, String value) {
if ("duration".equals(key)){
String[] durations = value.split(":");
if (durations.length == 2){
this.metadata = new Integer(Integer.parseInt(durations[0])*60+Integer.parseInt(durations[1])).toString();
}
}
super.onTag(key, value);
}
@Override
public String getMeta() {
return this.metadata;
}
}
What the code does is to read the duration tag and translate the hh:mm into minutes only. Please be aware, that duration MIGHT take other formats:
http://wiki.openstreetmap.org/wiki/Key:duration
I hope I haven't missed anything, and this could be useful for others, if they want to import duration (or other variables) into the osm_meta field of the SQL output.