use of org.openstreetmap.atlas.checks.atlas.OsmPbfFilePathFilter 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;
}
Aggregations