问题
Once I have loaded an Atlas object in memory, what is the best way to count the total lake area? Doing a simple tag search finds all the simple Area
lakes but I am missing all the lakes based on type=multipolygon Relations
that are built on "outer" ways that, stitched together, make a full lake.
回答1:
Atlas comes with a ComplexEntity concept that allows the user to construct higher-level entities based on specific concepts. The ComplexWaterEntity
object should fit that need:
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());
来源:https://stackoverflow.com/questions/53199589/how-to-count-the-total-lake-area-in-an-atlas