use of org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundary in project atlas by osmlab.
the class CountryBoundaryMap method resolveOverlappingBorders.
/**
* Filters the given iterable of {@link ComplexBoundary}s to only allow a single country to
* claim an outer boundary polygon.
*
* @param complexBoundaries
* The {@link ComplexBoundary}s to filter duplicate polygons from
* @return An iterable of {@link ComplexBoundary} with no duplicate outer polygons
*/
public Iterable<ComplexBoundary> resolveOverlappingBorders(final Iterable<ComplexBoundary> complexBoundaries) {
final List<ComplexBoundary> deduplicatedComplexBoundaries = new ArrayList<>();
final Set<org.openstreetmap.atlas.geography.Polygon> processedOuters = new HashSet<>();
final List<ComplexBoundary> complexBoundaryList = Lists.newArrayList(complexBoundaries);
Collections.sort(complexBoundaryList, (firstBoundary, secondBoundary) -> {
if (firstBoundary.getIdentifier() > secondBoundary.getIdentifier()) {
return 1;
} else if (secondBoundary.getIdentifier() > firstBoundary.getIdentifier()) {
return -1;
}
return 0;
});
for (final ComplexBoundary currentComplexBoundary : complexBoundaryList) {
final MultiPolygon outline = currentComplexBoundary.getOutline();
if (outline != null) {
for (final org.openstreetmap.atlas.geography.Polygon outer : outline.outers()) {
if (processedOuters.contains(outer)) {
currentComplexBoundary.removeOuter(outer);
} else // ensures that the outer is only claimed once it has been assigned to a country
if (Lists.newArrayList(currentComplexBoundary.getCountries()).size() > 0) {
processedOuters.add(outer);
}
}
deduplicatedComplexBoundaries.add(currentComplexBoundary);
}
}
return deduplicatedComplexBoundaries;
}
use of org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundary in project atlas by osmlab.
the class CountryBoundaryMap method readFromAtlas.
/**
* Read a {@link CountryBoundaryMap} from the {@link ComplexBoundary}(ies) inside an
* {@link Atlas}
*
* @param atlas
* The {@link Atlas} to read from.
*/
public void readFromAtlas(final Atlas atlas) {
final Iterable<ComplexBoundary> deduplicatedComplexBoundaries = resolveOverlappingBorders(new ComplexBoundaryFinder().find(atlas));
for (final ComplexBoundary complexBoundary : deduplicatedComplexBoundaries) {
if (complexBoundary.hasCountryCode()) {
final List<String> countryCodes = new ArrayList<>();
try {
final MultiPolygon outline = complexBoundary.getOutline();
final org.locationtech.jts.geom.MultiPolygon multiPolygon = JTS_MULTI_POLYGON_TO_MULTI_POLYGON_CONVERTER.backwardConvert(outline);
complexBoundary.getCountries().forEach(isoCountry -> this.addCountry(isoCountry.getIso3CountryCode(), multiPolygon));
} catch (final IllegalArgumentException e) {
throw new CoreException("Unable to read country boundary for country codes {}", countryCodes, e);
}
}
}
}
Aggregations