0

I am using osm2po to generate a routable network (by importing .sql files from osm2po into a PostgreSQL/Postgis database).
This works great using the post process filters PgRoutingWriter and PgVertexWriter.

However, I also want to take elevation data into account.
The first thing I did is to use the osmosis-srtm-plugin to add information about the height to the OSM export that I downloaded. At least when sticking to STRM3 this tool is very easy to use and as far as I can see, it should also be possible to use SRTM3 version 3 data.

The problem is that osm2po simply does not use this information (stored into tag "height" or "ele") at all when generating sql files.
I know that there is a answered question about adding ferry durations to ways, but when it comes to elevation information this does not work, since there is no field that can be used when writing nodes with PgVertexWriter. It might work for ways (although in my eyes it wouldn't be the best/very clean solution since it (mis)uses the osm_meta field), but I also need it for nodes.

There would be two possible solutions (that I can think of):

  • Adding the possibility to add new fields to ways and nodes (maybe a (Sorted)Map called custom_columns)
  • Adding the elevation information into the geom_vertex and geom_way columns

With both approaches the information could be used inside the PgVertexWriter/PgRoutingWriter (or any extending class) while writing the generated sql files.
However, I can not implement one of the suggested solutions, since neither can be implement by extending solely the WayTagResolver or NodeTagResolver classes (I would also need to change the SegmentedWay/Vertex classes that are not open-source).

Can elevation be added to nodes and ways in a different way (a.k.a: is there something else that I am missing)?

Also tried with the now suggested tag "ele" (instead of height)

1

Therefore you'll have to overwrite some of the Default Classes. To get a first impression, look at this here:

import de.cm.osm2po.converter.DefaultWayTagResolver;
import de.cm.osm2po.primitives.Var;
import de.cm.osm2po.primitives.VarNum;

public class CustomWayTagResolver extends DefaultWayTagResolver {

    // VarNum is a special Long which will be compressed for serialisation
    // If you need floats, use VarInt in combination with
    // Float.floatToIntBits()
    private VarNum height;

    @Override
    public void onTags(long entityId) {
        super.onTags(entityId);
        this.height = null; // Use null if zero or empty
    }

    @Override
    public void onTag(String key, String value) {
        super.onTag(key, value);
        if ("ele".equals(key) || "height".equals(key)) {
            // TODO take format and units into account. 1.0m e.g.
            // Avoid passing quasi NULL-Values
            // This example handles integer values only
            long h = Long.parseLong(value);
            this.height = new VarNum(h);
        }
    }

    @Override
    public Var<?> getAny() {
        return this.height;
    }

} // EOC
  • Dont forget to register this class in your osm2po.config or on command line: wayTagResolver.class=my.package.CustomWayTagResolver
  • Also use a modified PostGisWriter instead of postp.0.class = de.cm.osm2po.plugins.postp.PgRoutingWriter - The source can be found in the osm2po-plugins-5.1.x-src.zip
  • The NodeTagResolver works respectively
  • What would be the equivalent to the getAny function for the NodeTagResolver (there is no getAny function to overwrite)? – Nikolaus Krismer Oct 5 '16 at 13:00
  • Oh... please apologize ... this modification came later. Please download a higher version than 5.1.0 – Carsten Oct 6 '16 at 18:26
  • The getAny() method seems to be gone in osm2po 5.2.7. What is the suggested replacement for it? – Nikolaus Krismer Sep 6 '17 at 12:51
  • Just found out that there is a method getCustom() now. Is this the intended replacement? – Nikolaus Krismer Sep 6 '17 at 21:24
  • 1
    oh sorry, yes ... getAny() has been renamed to getCustom(). the name is more intuitive. – Carsten Sep 7 '17 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.