0

I am trying to use openstreetmap osmosis to read a pbf file of an airport and extract features like gates and runways.

I am using code similar to: http://www.javaoptimum.com/how-to-read-osm-pbf-files-programmatically-java/

When the code encounters a Node instance, it returns reasonable values from getLatitude and getLongitude...

However when the code encounters a Way instance the coordinates appear to be zero. Here is the code that I am using:

    Sink sinkImplementation = new Sink() {

        public void process(EntityContainer entityContainer) {

            Entity entity = entityContainer.getEntity();
            entity.getTags().forEach((tag) -> {
                if ("aeroway".equals(tag.getKey())) {
                    if (entity instanceof Node) {
                        if ("holding_position".equals(tag.getValue())) {
                            installPointHook(airportIcaoCode, entity, tag);
                        } else if ("gate".equals(tag.getValue())) {
                            installPointHook(airportIcaoCode, entity, tag);
                        } else {
                            LOGGER.info("Ignoring unrecognized tag value " + tag.getValue());
                        }
                    } else if (entity instanceof Way) {
                        Way way = (Way)entity;
                        if ("runway".equals(tag.getValue())) {
                            way.getWayNodes().forEach((it) -> System.out.println(it + " : " + it.getLatitude()+","+it.getLongitude()));
                        } else if ("taxiway".equals(tag.getValue())) {
                            way.getWayNodes().forEach((it) -> System.out.println(it + " : " + it.getLatitude()+","+it.getLongitude()));
                        } else if ("apron".equals(tag.getValue())) {
                            way.getWayNodes().forEach((it) -> System.out.println(it + " : " + it.getLatitude()+","+it.getLongitude()));
                        } else if ("hangar".equals(tag.getValue())) {
                            way.getWayNodes().forEach((it) -> System.out.println(it + " : " + it.getLatitude()+","+it.getLongitude()));
                        } else {
                            LOGGER.info("Ignoring unrecognized tag value " + tag.getValue());
                        }
                    } else if (entity instanceof Relation) {
                        LOGGER.info("Ignoring unrecognized tag value " + tag.getValue());
                    }
                }
            });
        }

        public void initialize(Map<String, Object> arg0) {
        }

        public void complete() {
        }

        @Override
        public void close() {
        }

    };

Is there some other processing I need to do in order to get the coordinates for Ways?

spierepf
  • 2,774
  • 2
  • 30
  • 52

2 Answers2

0

Turns out that ways don't have coordinates themselves, instead they have lists of WayNodes that have coordinates:

        public void process(EntityContainer entityContainer) {

            Entity entity = entityContainer.getEntity();
            entity.getTags().forEach((tag) -> {
                if (tag.getKey().equals("aeroway") && tag.getValue().equals("runway")
                        && entity instanceof Way) {
                    final List<WayNode> wayNodes = ((Way) entity).getWayNodes();
                    Runway runway = new Runway(entity.getId(), nodes.get(wayNodes.get(0).getNodeId()),
                            nodes.get(wayNodes.get(wayNodes.size() - 1).getNodeId()));
                    runways.add(runway);
                }
            });
        }
spierepf
  • 2,774
  • 2
  • 30
  • 52
0

You could enhance the WayNodes with coordinates using the following snippets:

private static class MySink implements Sink {
    public void process(EntityContainer entityContainer) {
        if (entityContainer.getEntity() instanceof Node) {
            Node node = (Node) entityContainer.getEntity();
            nodes.put(node.getId(), node);
        }
        
        ...
    }
    
    ...
}


for (int i = 0; i < way.getWayNodes().size(); i++) {
    WayNode wayNode = way.getWayNodes().get(i);
    Node node = sink.nodes.get(wayNode.getNodeId());
    way.getWayNodes().set(i, new WayNode(wayNode.getNodeId(), node.getLatitude(), node.getLongitude()));
}
André
  • 308
  • 2
  • 17