use of org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas in project atlas-generator by osmlab.
the class ShardedAtlasRDDLoaderTest method addTextAtlasResource.
private static void addTextAtlasResource(final String path, final String name) {
final TextAtlasBuilder builder = new TextAtlasBuilder();
final PackedAtlas packedAtlas = builder.read(new InputStreamResource(() -> ShardedAtlasRDDLoaderTest.class.getResourceAsStream(name)));
final WritableResource packedAtlasResource = new ByteArrayResource();
packedAtlas.save(packedAtlasResource);
ResourceFileSystem.addResource(path, packedAtlasResource);
}
use of org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas in project atlas-generator by osmlab.
the class WorldAtlasGeneratorIntegrationTest method testWorldAtlasGenerator.
@Test
public void testWorldAtlasGenerator() {
ResourceFileSystem.addResource(PBF_RESOURCE, new InputStreamResource(() -> AtlasGeneratorIntegrationTest.class.getResourceAsStream("DMA_cutout.osm.pbf")));
final String[] args = { "-pbf=" + PBF_RESOURCE, "-atlas=" + ATLAS_RESOURCE };
final WorldAtlasGenerator worldAtlasGenerator = new WorldAtlasGenerator();
WorldAtlasGenerator.setHadoopFileSystemConfiguration(ResourceFileSystem.simpleconfiguration());
ResourceFileSystem.printContents();
worldAtlasGenerator.runWithoutQuitting(args);
ResourceFileSystem.printContents();
final Optional<PackedAtlas> atlasOptional = ResourceFileSystem.getAtlas(ATLAS_RESOURCE);
Assert.assertTrue(atlasOptional.isPresent());
// NOSONAR
final Atlas atlas = atlasOptional.get();
Assert.assertEquals(112, atlas.numberOfNodes());
Assert.assertEquals(240, atlas.numberOfEdges());
Assert.assertEquals(327, atlas.numberOfAreas());
Assert.assertEquals(10, atlas.numberOfLines());
Assert.assertEquals(12, atlas.numberOfPoints());
Assert.assertEquals(2, atlas.numberOfRelations());
}
use of org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas in project atlas-generator by osmlab.
the class AtlasProtoOutputFormat method save.
@Override
protected void save(final Atlas value, final AbstractWritableResource out) {
final PackedAtlas packedValue = (PackedAtlas) value;
packedValue.setSaveSerializationFormat(AtlasSerializationFormat.PROTOBUF);
packedValue.save(out);
}
use of org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas 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.atlas.packed.PackedAtlas 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();
}
}
Aggregations