如何计算阿特拉斯湖的总面积

时间:2018-11-07 23:43:57

标签: java openstreetmap

一旦我在内存中加载了Atlas对象,计算总湖泊面积的最佳方法是什么?执行简单的标记搜索会找到所有简单的Area湖泊,但是我错过了所有基于type = multipolygon Relations的湖泊,这些湖泊是基于“外部”方式构建的,这些方式缝合在一起就构成了一个完整的湖泊。

1 个答案:

答案 0 :(得分:0)

Atlas带有ComplexEntity概念,该概念允许用户根据特定概念构造更高级别的实体。 ComplexWaterEntity对象应符合需要:

Atlas atlas;
Iterable<ComplexWaterEntity> waterEntities =
    new ComplexWaterEntityFinder().find(atlas);

// Get all water bodies and keep lakes only.
// This will include the multipolygon ones.
Iterable<ComplexWaterBody> lakes = Iterables.stream(waterEntities)
    .filter(entity -> WaterType.LAKE == entity.getWaterType())
    .map(entity -> (ComplexWaterBody) entity);

// Add all the surface areas
Surface result = Surface.MINIMUM;
for (ComplexWaterBody lake : lakes)
{
    result = result.add(lake.getGeometry().getSurface()));
}
System.out.println(result.asKilometerSquared());