use of org.openstreetmap.atlas.geography.sharding.SlippyTile in project atlas-generator by osmlab.
the class HadoopAtlasFileCache method getURIFromCountryAndShard.
private URI getURIFromCountryAndShard(final String country, final Shard shard) {
String compiledAtlasScheme = "";
if (shard instanceof SlippyTile) {
compiledAtlasScheme = this.atlasScheme.compile((SlippyTile) shard);
}
final String atlasName = String.format("%s_%s", country, shard.getName());
final String atlasURIString = SparkFileHelper.combine(this.parentAtlasPath, country, compiledAtlasScheme, atlasName + FileSuffix.ATLAS.toString());
final URI atlasURI;
try {
atlasURI = new URI(atlasURIString);
} catch (final URISyntaxException exception) {
throw new CoreException("Bad URI syntax: {}", atlasURIString, exception);
}
return atlasURI;
}
use of org.openstreetmap.atlas.geography.sharding.SlippyTile in project atlas-generator by osmlab.
the class HadoopAtlasFileCacheTest method testCache.
@Test
public void testCache() {
final File parent = File.temporaryFolder();
final File parentAtlas = new File(parent + "/atlas");
final File parentAtlasCountry = new File(parentAtlas + "/AAA");
final String fullParentPathURI = "file://" + parentAtlas.toString();
final HadoopAtlasFileCache cache = new HadoopAtlasFileCache(fullParentPathURI, new SlippyTilePersistenceScheme(SlippyTilePersistenceSchemeType.ZZ_SUBFOLDER), new HashMap<>());
parentAtlasCountry.mkdirs();
try {
final PackedAtlasBuilder builder1 = new PackedAtlasBuilder();
builder1.addPoint(1L, Location.CENTER, Maps.hashMap());
final PackedAtlas atlas1 = (PackedAtlas) builder1.get();
final PackedAtlasBuilder builder2 = new PackedAtlasBuilder();
builder2.addPoint(2L, Location.CENTER, Maps.hashMap());
final PackedAtlas atlas2 = (PackedAtlas) builder2.get();
final File atlasFile1 = parentAtlasCountry.child("1/AAA_1-1-1.atlas");
atlas1.save(atlasFile1);
final File atlasFile2 = parentAtlasCountry.child("2/AAA_2-2-2.atlas");
atlas2.save(atlasFile2);
// cache miss, this will create the cached copy
final Resource resource1 = cache.get("AAA", new SlippyTile(1, 1, 1)).get();
final Resource resource2 = cache.get("AAA", new SlippyTile(2, 2, 2)).get();
Assert.assertEquals(atlas1, PackedAtlas.load(resource1));
Assert.assertEquals(atlas2, PackedAtlas.load(resource2));
// cache hit, using cached copy
final Resource resource3 = cache.get("AAA", new SlippyTile(1, 1, 1)).get();
final Resource resource4 = cache.get("AAA", new SlippyTile(2, 2, 2)).get();
Assert.assertEquals(atlas1, PackedAtlas.load(resource3));
Assert.assertEquals(atlas2, PackedAtlas.load(resource4));
} finally {
cache.invalidate();
parent.deleteRecursively();
}
}
use of org.openstreetmap.atlas.geography.sharding.SlippyTile in project atlas-generator by osmlab.
the class HadoopAtlasFileCacheTest method testCacheWithFetcher.
@Test
public void testCacheWithFetcher() {
final File parent = File.temporaryFolder();
final File parentAtlas = new File(parent + "/atlas");
final File parentAtlasCountry = new File(parentAtlas + "/AAA");
final String fullParentPathURI = "file://" + parentAtlas.toString();
final HadoopAtlasFileCache cache = new HadoopAtlasFileCache(fullParentPathURI, "namespace", new SlippyTilePersistenceScheme(SlippyTilePersistenceSchemeType.ZZ_SUBFOLDER), uri -> Optional.ofNullable(FileSystemHelper.resource(uri.toString(), new HashMap<>())));
parentAtlasCountry.mkdirs();
try {
final PackedAtlasBuilder builder1 = new PackedAtlasBuilder();
builder1.addPoint(1L, Location.CENTER, Maps.hashMap());
final PackedAtlas atlas1 = (PackedAtlas) builder1.get();
final PackedAtlasBuilder builder2 = new PackedAtlasBuilder();
builder2.addPoint(2L, Location.CENTER, Maps.hashMap());
final PackedAtlas atlas2 = (PackedAtlas) builder2.get();
final File atlasFile1 = parentAtlasCountry.child("1/AAA_1-1-1.atlas");
atlas1.save(atlasFile1);
final File atlasFile2 = parentAtlasCountry.child("2/AAA_2-2-2.atlas");
atlas2.save(atlasFile2);
// cache miss, this will create the cached copy
final Resource resource1 = cache.get("AAA", new SlippyTile(1, 1, 1)).get();
final Resource resource2 = cache.get("AAA", new SlippyTile(2, 2, 2)).get();
Assert.assertEquals(atlas1, PackedAtlas.load(resource1));
Assert.assertEquals(atlas2, PackedAtlas.load(resource2));
// cache hit, using cached copy
final Resource resource3 = cache.get("AAA", new SlippyTile(1, 1, 1)).get();
final Resource resource4 = cache.get("AAA", new SlippyTile(2, 2, 2)).get();
Assert.assertEquals(atlas1, PackedAtlas.load(resource3));
Assert.assertEquals(atlas2, PackedAtlas.load(resource4));
} finally {
cache.invalidate();
parent.deleteRecursively();
}
}
use of org.openstreetmap.atlas.geography.sharding.SlippyTile in project atlas by osmlab.
the class CountryBoundary method tiles.
/**
* Iterate through outers of country boundary to avoid unnecessary overlap checks
*
* @param zoom
* The zoom level of slippy tiles
* @return A set of slippy tiles
*/
public Set<SlippyTile> tiles(final int zoom) {
final Set<SlippyTile> validTiles = new HashSet<>();
for (final Polygon subBoundary : this.boundary.outers()) {
final List<SlippyTile> tiles = Iterables.asList(SlippyTile.allTiles(zoom, subBoundary.bounds()));
validTiles.addAll(tiles.stream().filter(tile -> subBoundary.overlaps(tile.bounds())).collect(Collectors.toList()));
}
return validTiles;
}
use of org.openstreetmap.atlas.geography.sharding.SlippyTile in project atlas by osmlab.
the class CountryBoundaryMapArchiver method generateOceanBoundaryMap.
protected CountryBoundaryMap generateOceanBoundaryMap(final CountryBoundaryMap boundaryMap, final Iterable<SlippyTile> allTiles) {
final CountryBoundaryMap finalBoundaryMap = new CountryBoundaryMap();
int oceanCountryCount = 0;
// add all ocean boundaries to the new boundary map
logger.info("Calculating ocean boundaries...");
for (final SlippyTile tile : allTiles) {
final Time start = Time.now();
final String countryCode = String.format("O%02d", oceanCountryCount);
final Geometry countryGeometry = geometryForShard(tile.bounds(), boundaryMap);
if (!countryGeometry.isEmpty()) {
if (countryGeometry instanceof Polygon) {
finalBoundaryMap.addCountry(countryCode, (Polygon) countryGeometry);
}
if (countryGeometry instanceof MultiPolygon) {
finalBoundaryMap.addCountry(countryCode, (MultiPolygon) countryGeometry);
}
logger.info("Added Ocean Country {} in {}", countryCode, start.elapsedSince());
oceanCountryCount++;
} else {
logger.info("Skipped Ocean Country {} in {}. It is land covered.", tile.getName(), start.elapsedSince());
}
}
// add all countries from the input boundary map to the new boundary map
logger.info("Adding back country boundaries to the new ocean boundary map");
final JtsMultiPolygonConverter multiPolyConverter = new JtsMultiPolygonConverter();
for (final String country : boundaryMap.allCountryNames()) {
for (final CountryBoundary countryBoundary : boundaryMap.countryBoundary(country)) {
final GeometryFactory factory = new GeometryFactory();
final Set<org.locationtech.jts.geom.Polygon> boundaryPolygons = multiPolyConverter.convert(countryBoundary.getBoundary());
final org.locationtech.jts.geom.MultiPolygon countryGeometry = factory.createMultiPolygon(boundaryPolygons.toArray(new Polygon[boundaryPolygons.size()]));
finalBoundaryMap.addCountry(country, countryGeometry);
}
}
return finalBoundaryMap;
}
Aggregations