Search in sources :

Example 1 with AtlasResourceLoader

use of org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader in project atlas-checks by osmlab.

the class AtlasDataSource method load.

/**
 * Loads an {@link Atlas} from the input location. Intermediate {@link Atlas}es created are
 * submitted to the provided {@link Consumer} to allow for any additional handling.
 *
 * @param input
 *            location of the {@link Atlas} source
 * @param country
 *            country of the {@link Atlas}
 * @param intermediateAtlasHandler
 *            handler given intermediate {@link Atlas} files when created
 * @return {@link Atlas} representation of the data source
 */
public Atlas load(final String input, final String country, final Consumer<Atlas> intermediateAtlasHandler) {
    // Path filters for supported file types
    final PathFilter pbfFilter = new OsmPbfFilePathFilter();
    final PathFilter atlasFilter = new CountrySpecificAtlasFilePathFilter(country);
    final Optional<Resource> resource = this.loadHelper.collectSourceFile(input, pbfFilter, atlasFilter);
    if (resource.isPresent()) {
        final Resource dataSource = resource.get();
        if (Atlas.isAtlas(dataSource)) {
            return new AtlasResourceLoader().load(dataSource);
        } else if (FileSuffix.resourceFilter(FileSuffix.PBF).test(dataSource)) {
            this.logger.info("Loading Atlas from OSM protobuf {}", input);
            final Atlas atlas = this.loadPbf(dataSource, country);
            intermediateAtlasHandler.accept(atlas);
            return atlas;
        }
    } else {
        final String directory = this.pathResolver.resolvePath(input, country);
        final List<Resource> atlasResources = this.loadHelper.collectSourceFiles(directory, true, atlasFilter);
        if (atlasResources.size() > 0) {
            return new AtlasResourceLoader().load(atlasResources);
        } else {
            final List<Resource> pbfResources = this.loadHelper.collectSourceFiles(directory, true, pbfFilter);
            final int pbfCount = pbfResources.size();
            if (pbfCount > 0) {
                this.logger.info("Loading Atlas from {} OSM protobuf(s) found in {}", pbfCount, input);
                final List<Atlas> atlases = pbfResources.parallelStream().map(dataSource -> this.loadPbf(dataSource, country)).peek(intermediateAtlasHandler).collect(Collectors.toList());
                return new MultiAtlas(atlases);
            }
        }
    }
    return null;
}
Also used : AtlasResourceLoader(org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader) Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) MultiAtlas(org.openstreetmap.atlas.geography.atlas.multi.MultiAtlas) CountrySpecificAtlasFilePathFilter(org.openstreetmap.atlas.checks.atlas.CountrySpecificAtlasFilePathFilter) PathFilter(org.apache.hadoop.fs.PathFilter) OsmPbfFilePathFilter(org.openstreetmap.atlas.checks.atlas.OsmPbfFilePathFilter) CountrySpecificAtlasFilePathFilter(org.openstreetmap.atlas.checks.atlas.CountrySpecificAtlasFilePathFilter) MultiAtlas(org.openstreetmap.atlas.geography.atlas.multi.MultiAtlas) Resource(org.openstreetmap.atlas.streaming.resource.Resource) OsmPbfFilePathFilter(org.openstreetmap.atlas.checks.atlas.OsmPbfFilePathFilter)

Aggregations

PathFilter (org.apache.hadoop.fs.PathFilter)1 CountrySpecificAtlasFilePathFilter (org.openstreetmap.atlas.checks.atlas.CountrySpecificAtlasFilePathFilter)1 OsmPbfFilePathFilter (org.openstreetmap.atlas.checks.atlas.OsmPbfFilePathFilter)1 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)1 AtlasResourceLoader (org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader)1 MultiAtlas (org.openstreetmap.atlas.geography.atlas.multi.MultiAtlas)1 Resource (org.openstreetmap.atlas.streaming.resource.Resource)1