Search in sources :

Example 1 with CountryBoundaryMapArchiver

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;
}
Also used : CountryBoundaryMapArchiver(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMapArchiver) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap)

Example 2 with CountryBoundaryMapArchiver

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);
}
Also used : AtlasSharding(org.openstreetmap.atlas.generator.sharding.AtlasSharding) Sharding(org.openstreetmap.atlas.geography.sharding.Sharding) MultiMap(org.openstreetmap.atlas.utilities.maps.MultiMap) StringList(org.openstreetmap.atlas.utilities.collections.StringList) Tuple2(scala.Tuple2) CountryBoundaryMapArchiver(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMapArchiver) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) Shard(org.openstreetmap.atlas.geography.sharding.Shard)

Aggregations

CountryBoundaryMap (org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap)2 CountryBoundaryMapArchiver (org.openstreetmap.atlas.geography.boundary.CountryBoundaryMapArchiver)2 AtlasSharding (org.openstreetmap.atlas.generator.sharding.AtlasSharding)1 Shard (org.openstreetmap.atlas.geography.sharding.Shard)1 Sharding (org.openstreetmap.atlas.geography.sharding.Sharding)1 StringList (org.openstreetmap.atlas.utilities.collections.StringList)1 MultiMap (org.openstreetmap.atlas.utilities.maps.MultiMap)1 Tuple2 (scala.Tuple2)1