Search in sources :

Example 1 with SlippyTile

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;
}
Also used : SlippyTile(org.openstreetmap.atlas.geography.sharding.SlippyTile) CoreException(org.openstreetmap.atlas.exception.CoreException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with SlippyTile

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();
    }
}
Also used : PackedAtlasBuilder(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder) SlippyTile(org.openstreetmap.atlas.geography.sharding.SlippyTile) PackedAtlas(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas) Resource(org.openstreetmap.atlas.streaming.resource.Resource) SlippyTilePersistenceScheme(org.openstreetmap.atlas.generator.persistence.scheme.SlippyTilePersistenceScheme) File(org.openstreetmap.atlas.streaming.resource.File) Test(org.junit.Test)

Example 3 with SlippyTile

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();
    }
}
Also used : PackedAtlasBuilder(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasBuilder) SlippyTile(org.openstreetmap.atlas.geography.sharding.SlippyTile) PackedAtlas(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas) Resource(org.openstreetmap.atlas.streaming.resource.Resource) SlippyTilePersistenceScheme(org.openstreetmap.atlas.generator.persistence.scheme.SlippyTilePersistenceScheme) File(org.openstreetmap.atlas.streaming.resource.File) Test(org.junit.Test)

Example 4 with SlippyTile

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;
}
Also used : SlippyTile(org.openstreetmap.atlas.geography.sharding.SlippyTile) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) Polygon(org.openstreetmap.atlas.geography.Polygon) HashSet(java.util.HashSet)

Example 5 with SlippyTile

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;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SlippyTile(org.openstreetmap.atlas.geography.sharding.SlippyTile) Time(org.openstreetmap.atlas.utilities.time.Time) Geometry(org.locationtech.jts.geom.Geometry) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) JtsMultiPolygonConverter(org.openstreetmap.atlas.geography.converters.jts.JtsMultiPolygonConverter) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Aggregations

SlippyTile (org.openstreetmap.atlas.geography.sharding.SlippyTile)33 Test (org.junit.Test)14 Shard (org.openstreetmap.atlas.geography.sharding.Shard)10 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)9 File (org.openstreetmap.atlas.streaming.resource.File)9 Resource (org.openstreetmap.atlas.streaming.resource.Resource)7 HashMap (java.util.HashMap)5 CoreException (org.openstreetmap.atlas.exception.CoreException)5 SlippyTilePersistenceScheme (org.openstreetmap.atlas.generator.persistence.scheme.SlippyTilePersistenceScheme)5 MultiPolygon (org.openstreetmap.atlas.geography.MultiPolygon)5 HashSet (java.util.HashSet)4 Location (org.openstreetmap.atlas.geography.Location)4 Rectangle (org.openstreetmap.atlas.geography.Rectangle)4 PackedAtlas (org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas)4 Assert (org.junit.Assert)3 Before (org.junit.Before)3 BareAtlas (org.openstreetmap.atlas.geography.atlas.BareAtlas)3 MultiAtlas (org.openstreetmap.atlas.geography.atlas.multi.MultiAtlas)3 RawAtlasGenerator (org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator)3 WaySectionProcessor (org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor)3