use of org.openstreetmap.atlas.geography.boundary.CountryBoundaryMapArchiver in project atlas-generator by osmlab.
the class AtlasGenerator method boundaries.
private CountryBoundaryMap boundaries(final List<String> countries, final CommandMap command) {
final String countryShapes = (String) command.get(AtlasGeneratorParameters.COUNTRY_SHAPES);
final CountryBoundaryMap boundaries;
if (countryShapes == null) {
boundaries = persistenceTools().boundaries((String) command.get(AtlasGeneratorParameters.PBF_PATH));
} else {
boundaries = new CountryBoundaryMapArchiver().read(resource(countryShapes));
}
if (!boundaries.hasGridIndex()) {
logger.warn("Given country boundary file didn't have grid index. Initializing grid index for {}.", countries);
boundaries.initializeGridIndex(new HashSet<>(countries));
}
return boundaries;
}
use of org.openstreetmap.atlas.geography.boundary.CountryBoundaryMapArchiver in project atlas-generator by osmlab.
the class ShardedSparkJob method start.
@Override
public void start(final CommandMap command) {
final StringList countries = (StringList) command.get(COUNTRIES);
final String shardingType = (String) command.get(SHARDING_TYPE);
final Sharding sharding = AtlasSharding.forString(shardingType, configuration());
final String countryShapes = (String) command.get(COUNTRY_SHAPES);
logger.info("Reading country boundaries from {}", countryShapes);
final CountryBoundaryMap worldBoundaries = new CountryBoundaryMapArchiver().read(resource(countryShapes));
logger.info("Done Reading {} country boundaries from {}", worldBoundaries.size(), countryShapes);
// The code below is as parallel as there are countries...
final JavaRDD<String> countriesRDD = getContext().parallelize(Iterables.asList(countries), countries.size());
// Stage 0 (parallelize on countries)
final JavaPairRDD<String, Shard> preCountryShardsRDD = countriesRDD.flatMapToPair(countryToShards(worldBoundaries, sharding));
// Collect The country to shard map
final List<Tuple2<String, Shard>> countryShards = preCountryShardsRDD.collect();
final MultiMap<String, Shard> countryToShardMap = new MultiMap<>();
countryShards.forEach(tuple -> countryToShardMap.add(tuple._1(), tuple._2()));
// Call the rest!
start2(command, sharding, countryToShardMap);
}
Aggregations