gpt4 book ai didi

java - Osmosis WayNode 实例始终从 getLatitude 和 getLongitude 返回 0

转载 作者:行者123 更新时间:2023-12-02 00:16:39 25 4
gpt4 key购买 nike

我正在尝试使用 openstreetmap osmosis 读取机场的 pbf 文件并提取登机口和跑道等特征。

我使用的代码类似于:http://www.javaoptimum.com/how-to-read-osm-pbf-files-programmatically-java/

当代码遇到 Node 实例时,它会从 getLatitude 和 getLongitude 返回合理的值...

但是,当代码遇到 Way 实例时,坐标显示为零。这是我正在使用的代码:

    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() {
}

};

为了获取 Way 的坐标,我还需要做一些其他处理吗?

最佳答案

事实证明,这些路径本身没有坐标,而是具有具有坐标的 WayNode 列表:

        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);
}
});
}

关于java - Osmosis WayNode 实例始终从 getLatitude 和 getLongitude 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58085823/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com