Search in sources :

Example 1 with RawAtlasSlicer

use of org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer in project atlas by osmlab.

the class AbstractAtlas method createAndSaveOsmPbfWithSlicing.

/**
 * Create an {@link Atlas} from an OSM protobuf that has already been sliced and save it to a
 * resource
 *
 * @param osmPbf
 *            The OSM protobuf
 * @param atlasResource
 *            The {@link WritableResource} to save the {@link Atlas} to
 * @param boundaryMap
 *            The {@link CountryBoundaryMap} to use for country-slicing
 * @return The created {@link Atlas}
 */
public static Atlas createAndSaveOsmPbfWithSlicing(final Resource osmPbf, final WritableResource atlasResource, final CountryBoundaryMap boundaryMap) {
    Atlas atlas = new RawAtlasGenerator(osmPbf).build();
    final AtlasLoadingOption loadingOption = AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap);
    atlas = new RawAtlasSlicer(loadingOption, atlas).slice();
    atlas = new WaySectionProcessor(atlas, AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run();
    atlas.save(atlasResource);
    return atlas;
}
Also used : PackedAtlas(org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas) WaySectionProcessor(org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor) AtlasLoadingOption(org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption) RawAtlasSlicer(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer) RawAtlasGenerator(org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator)

Example 2 with RawAtlasSlicer

use of org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer in project atlas by osmlab.

the class RawAtlasIntegrationTest method testStandAloneNodeIngest.

@Ignore
@Test
public void testStandAloneNodeIngest() {
    // Create a raw atlas, slice and section it
    final String pbfPath = RawAtlasIntegrationTest.class.getResource("node-4353689487.pbf").getPath();
    final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(pbfPath));
    final Atlas rawAtlas = rawAtlasGenerator.build();
    final Atlas slicedRawAtlas = new RawAtlasSlicer(loadingOptionAntarctica, rawAtlas).slice();
    final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, loadingOptionAntarctica).run();
    // Verify only a single point exists
    Assert.assertEquals(0, finalAtlas.numberOfNodes());
    Assert.assertEquals(0, finalAtlas.numberOfEdges());
    Assert.assertEquals(0, finalAtlas.numberOfAreas());
    Assert.assertEquals(1, finalAtlas.numberOfPoints());
    Assert.assertEquals(0, finalAtlas.numberOfLines());
    Assert.assertEquals(0, finalAtlas.numberOfRelations());
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) WaySectionProcessor(org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor) RawAtlasSlicer(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer) File(org.openstreetmap.atlas.streaming.resource.File) RawAtlasGenerator(org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator) Ignore(org.junit.Ignore) Test(org.junit.Test) ShardFileOverlapsPolygonTest(org.openstreetmap.atlas.geography.atlas.ShardFileOverlapsPolygonTest)

Example 3 with RawAtlasSlicer

use of org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer in project atlas by osmlab.

the class RawAtlasIntegrationTest method testTwoWaysWithDifferentLayersIntersectingInMiddle.

@Test
public void testTwoWaysWithDifferentLayersIntersectingInMiddle() {
    // Based on https://www.openstreetmap.org/way/467880095 and
    // https://www.openstreetmap.org/way/28247094 having two different layer tag values and
    // having overlapping nodes (https://www.openstreetmap.org/node/4661272336 and
    // https://www.openstreetmap.org/node/5501637097) that should not be merged.
    final Location overlappingLocation = Location.forString("1.3248985,103.6452864");
    final String path = RawAtlasIntegrationTest.class.getResource("twoWaysWithDifferentLayersIntersectingInMiddle.pbf").getPath();
    final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(path));
    final Atlas rawAtlas = rawAtlasGenerator.build();
    // Verify both points made it into the raw atlas
    Assert.assertTrue(Iterables.size(rawAtlas.pointsAt(overlappingLocation)) == 2);
    final Atlas slicedRawAtlas = new RawAtlasSlicer(loadingOptionIntersectionAtMiddle, rawAtlas).slice();
    final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, loadingOptionIntersectionAtMiddle).run();
    // Make sure there is no sectioning happening between the two ways with different layer tag
    // values. There is a one-way overpass and a bi-directional residential street, resulting in
    // 3 total edges and 4 nodes (one on both ends of the two segments)
    Assert.assertEquals(3, finalAtlas.numberOfEdges());
    Assert.assertEquals(4, finalAtlas.numberOfNodes());
    // Again, verify there is no node at the duplicated location
    Assert.assertTrue(Iterables.size(finalAtlas.nodesAt(overlappingLocation)) == 0);
    Assert.assertEquals(0, finalAtlas.numberOfPoints());
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) WaySectionProcessor(org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor) RawAtlasSlicer(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer) File(org.openstreetmap.atlas.streaming.resource.File) Location(org.openstreetmap.atlas.geography.Location) RawAtlasGenerator(org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator) Test(org.junit.Test) ShardFileOverlapsPolygonTest(org.openstreetmap.atlas.geography.atlas.ShardFileOverlapsPolygonTest)

Example 4 with RawAtlasSlicer

use of org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer in project atlas by osmlab.

the class RawAtlasIntegrationTest method testPbfToSlicedRawAtlas.

@Ignore
@Test
public void testPbfToSlicedRawAtlas() {
    // This PBF file contains really interesting data. 1. MultiPolygon with multiple inners and
    // outers spanning 3 countries (http://www.openstreetmap.org/relation/3638082) 2. Multiple
    // nested relations (http://www.openstreetmap.org/relation/3314886)
    final String pbfPath = RawAtlasIntegrationTest.class.getResource("8-122-122-trimmed.osm.pbf").getPath();
    final RawAtlasGenerator rawAtlasGenerator = new RawAtlasGenerator(new File(pbfPath));
    final Atlas rawAtlas = rawAtlasGenerator.build();
    Assert.assertEquals(0, rawAtlas.numberOfNodes());
    Assert.assertEquals(0, rawAtlas.numberOfEdges());
    Assert.assertEquals(0, rawAtlas.numberOfAreas());
    Assert.assertEquals(74342, rawAtlas.numberOfPoints());
    Assert.assertEquals(7818, rawAtlas.numberOfLines());
    Assert.assertEquals(17, rawAtlas.numberOfRelations());
    final Atlas slicedRawAtlas = new RawAtlasSlicer(loadingOptionAll, rawAtlas).slice();
    Assert.assertEquals(0, slicedRawAtlas.numberOfNodes());
    Assert.assertEquals(0, slicedRawAtlas.numberOfEdges());
    Assert.assertEquals(0, slicedRawAtlas.numberOfAreas());
    Assert.assertEquals(74850, slicedRawAtlas.numberOfPoints());
    Assert.assertEquals(8086, slicedRawAtlas.numberOfLines());
    Assert.assertEquals(23, slicedRawAtlas.numberOfRelations());
    // Assert all raw Atlas entities have a country code
    assertAllEntitiesHaveCountryCode(slicedRawAtlas);
    final Atlas ivoryCoast = new RawAtlasSlicer(loadingOptionIvoryCoast, rawAtlas).slice();
    Assert.assertEquals(0, ivoryCoast.numberOfNodes());
    Assert.assertEquals(0, ivoryCoast.numberOfEdges());
    Assert.assertEquals(0, ivoryCoast.numberOfAreas());
    Assert.assertEquals(34962, ivoryCoast.numberOfPoints());
    Assert.assertEquals(3637, ivoryCoast.numberOfLines());
    Assert.assertEquals(12, ivoryCoast.numberOfRelations());
    // Assert all raw Atlas entities have a country code
    assertAllEntitiesHaveCountryCode(ivoryCoast);
    // Test sectioning!
    final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, loadingOptionAll).run();
    Assert.assertEquals(5011, finalAtlas.numberOfNodes());
    Assert.assertEquals(9764, finalAtlas.numberOfEdges());
    Assert.assertEquals(5133, finalAtlas.numberOfAreas());
    Assert.assertEquals(184, finalAtlas.numberOfPoints());
    Assert.assertEquals(326, finalAtlas.numberOfLines());
    Assert.assertEquals(23, finalAtlas.numberOfRelations());
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) WaySectionProcessor(org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor) RawAtlasSlicer(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer) File(org.openstreetmap.atlas.streaming.resource.File) RawAtlasGenerator(org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator) Ignore(org.junit.Ignore) Test(org.junit.Test) ShardFileOverlapsPolygonTest(org.openstreetmap.atlas.geography.atlas.ShardFileOverlapsPolygonTest)

Example 5 with RawAtlasSlicer

use of org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer in project atlas by osmlab.

the class AtlasDebugTool method onRun.

@Override
protected int onRun(final CommandMap command) {
    final File pbf = (File) command.get(PBF);
    final File atlasFile = (File) command.get(ATLAS);
    final File geojson = (File) command.get(GEOJSON);
    final File text = (File) command.get(TEXT);
    final java.io.File boundaryFile = (java.io.File) command.get(BOUNDARY);
    final String country = (String) command.get(COUNTRY);
    final Rectangle bound = (Rectangle) command.get(BOUND);
    final MultiPolygon inputMultipolygon = (MultiPolygon) command.get(MULTIPOLYGON);
    @SuppressWarnings("unchecked") final List<Location> startEndRoute = (List<Location>) command.get(ROUTE);
    Atlas atlas;
    if (pbf != null && pbf.exists()) {
        final AtlasLoadingOption option;
        MultiPolygon multiPolygon = MultiPolygon.forPolygon(Rectangle.MAXIMUM);
        if (boundaryFile != null) {
            final CountryBoundaryMap boundaryMap = CountryBoundaryMap.fromShapeFile(boundaryFile);
            option = AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap);
            if (country != null) {
                if (new CountryListTwoWayStringConverter().convert(country).size() == 1) {
                    multiPolygon = boundaryMap.countryBoundary(country).get(0).getBoundary();
                }
                option.setCountryCode(country);
            }
        } else {
            option = AtlasLoadingOption.createOptionWithNoSlicing();
        }
        if (bound != null) {
            multiPolygon = MultiPolygon.forPolygon(bound);
        }
        if (inputMultipolygon != null) {
            multiPolygon = inputMultipolygon;
        }
        atlas = new RawAtlasGenerator(pbf, option, multiPolygon).build();
        if (option.isCountrySlicing()) {
            atlas = new RawAtlasSlicer(option, atlas).slice();
        }
        atlas = new WaySectionProcessor(atlas, option).run();
        atlas.save(atlasFile);
    } else if (atlasFile != null && atlasFile.exists()) {
        atlas = new AtlasResourceLoader().load(atlasFile);
    } else {
        logger.error("Must have at least one source, -pbf or -atlas");
        atlas = null;
        System.exit(1);
    }
    logger.info("Loaded {}", atlas.summary());
    if (geojson != null) {
        atlas.saveAsGeoJson(geojson);
    }
    if (text != null) {
        atlas.saveAsText(text);
    }
    if (startEndRoute != null) {
        logger.info("Route between {} and {} = {}", startEndRoute.get(0), startEndRoute.get(1), AStarRouter.dijkstra(atlas, Distance.TEN_MILES).route(startEndRoute.get(0), startEndRoute.get(1)));
    }
    return 0;
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) WaySectionProcessor(org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor) Rectangle(org.openstreetmap.atlas.geography.Rectangle) RawAtlasGenerator(org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator) AtlasResourceLoader(org.openstreetmap.atlas.geography.atlas.AtlasResourceLoader) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) ArrayList(java.util.ArrayList) List(java.util.List) StringList(org.openstreetmap.atlas.utilities.collections.StringList) AtlasLoadingOption(org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) CountryListTwoWayStringConverter(org.openstreetmap.atlas.geography.boundary.converters.CountryListTwoWayStringConverter) RawAtlasSlicer(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer) File(org.openstreetmap.atlas.streaming.resource.File) Location(org.openstreetmap.atlas.geography.Location)

Aggregations

RawAtlasSlicer (org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer)20 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)18 RawAtlasGenerator (org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator)16 WaySectionProcessor (org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor)15 Test (org.junit.Test)14 File (org.openstreetmap.atlas.streaming.resource.File)10 AtlasLoadingOption (org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption)8 InputStreamResource (org.openstreetmap.atlas.streaming.resource.InputStreamResource)8 CountryBoundaryMap (org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap)7 Location (org.openstreetmap.atlas.geography.Location)6 MultiPolygon (org.openstreetmap.atlas.geography.MultiPolygon)6 ShardFileOverlapsPolygonTest (org.openstreetmap.atlas.geography.atlas.ShardFileOverlapsPolygonTest)6 Ignore (org.junit.Ignore)4 Resource (org.openstreetmap.atlas.streaming.resource.Resource)4 StringResource (org.openstreetmap.atlas.streaming.resource.StringResource)4 HashMap (java.util.HashMap)3 LineString (org.locationtech.jts.geom.LineString)3 Shard (org.openstreetmap.atlas.geography.sharding.Shard)3 Time (org.openstreetmap.atlas.utilities.time.Time)3 HashSet (java.util.HashSet)2