Search in sources :

Example 1 with ComplexBoundaryFinder

use of org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundaryFinder 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);
            }
        }
    }
}
Also used : CoreException(org.openstreetmap.atlas.exception.CoreException) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) ArrayList(java.util.ArrayList) ComplexBoundaryFinder(org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundaryFinder) ComplexBoundary(org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundary)

Aggregations

ArrayList (java.util.ArrayList)1 CoreException (org.openstreetmap.atlas.exception.CoreException)1 MultiPolygon (org.openstreetmap.atlas.geography.MultiPolygon)1 ComplexBoundary (org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundary)1 ComplexBoundaryFinder (org.openstreetmap.atlas.geography.atlas.items.complex.boundaries.ComplexBoundaryFinder)1