Search in sources :

Example 16 with CountryBoundaryMap

use of org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap in project atlas by osmlab.

the class WaySectionProcessorTest method testRelationMemberLocationItemInclusion.

@Test
public void testRelationMemberLocationItemInclusion() {
    // Based on https://www.openstreetmap.org/relation/578254 - the Node in the Relation gets
    // created as both an Atlas point and node. Let's verify that the Relation consists of both.
    final Atlas slicedRawAtlas = this.setup.getNodeAndPointAsRelationMemberAtlas();
    final CountryBoundaryMap boundaryMap = CountryBoundaryMap.fromPlainText(new InputStreamResource(() -> WaySectionProcessorTest.class.getResourceAsStream("nodeAndPointRelationMemberBoundaryMap.txt")));
    final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, AtlasLoadingOption.createOptionWithAllEnabled(boundaryMap)).run();
    final RelationMemberList members = finalAtlas.relation(578254000000L).members();
    Assert.assertEquals("Six members - 2 pairs of reverse edges, 1 node and 1 point", 6, members.size());
    Assert.assertEquals("Single point", 1, members.stream().filter(member -> member.getEntity().getType() == ItemType.POINT).count());
    Assert.assertEquals("Single node", 1, members.stream().filter(member -> member.getEntity().getType() == ItemType.NODE).count());
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) RelationMemberList(org.openstreetmap.atlas.geography.atlas.items.RelationMemberList) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) InputStreamResource(org.openstreetmap.atlas.streaming.resource.InputStreamResource) Test(org.junit.Test) RawAtlasSlicingTest(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicingTest)

Example 17 with CountryBoundaryMap

use of org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap in project atlas by osmlab.

the class WaySectionProcessorTest method testWayExceedingSectioningLimit.

@Test
public void testWayExceedingSectioningLimit() {
    // Based on https://www.openstreetmap.org/way/608903805 and
    // https://www.openstreetmap.org/way/608901269. These are stacked, duplicated ways that
    // extend for a long time, causing sectioning to occur more than the allowed 999 times
    final Atlas slicedRawAtlas = this.setup.getWayExceedingSectioningLimitAtlas();
    // Create a dummy country boundary map that contains these ways and call it Afghanistan
    final Set<String> countries = new HashSet<>();
    final String afghanistan = "AFG";
    countries.add(afghanistan);
    final Map<String, MultiPolygon> boundaries = new HashMap<>();
    final Polygon fakePolygon = new Polygon(Location.forString("34.15102284294,66.22764518738"), Location.forString("34.1515910819,66.53388908386"), Location.forString("33.99802783162,66.53045585632"), Location.forString("33.99632001003,66.22558525085"), Location.forString("34.15102284294,66.22764518738"));
    final MultiPolygon boundary = MultiPolygon.forPolygon(fakePolygon);
    boundaries.put(afghanistan, boundary);
    final CountryBoundaryMap countryBoundaryMap = CountryBoundaryMap.fromBoundaryMap(boundaries);
    final Atlas finalAtlas = new WaySectionProcessor(slicedRawAtlas, AtlasLoadingOption.createOptionWithAllEnabled(countryBoundaryMap)).run();
    // Verify maximum number of sections for each edge
    Assert.assertEquals(999, Iterables.size(finalAtlas.edges(edge -> edge.getOsmIdentifier() == 608901269)));
    Assert.assertEquals(999, Iterables.size(finalAtlas.edges(edge -> edge.getOsmIdentifier() == 608903805)));
    // Verify tag presence
    Assert.assertEquals(SyntheticInvalidWaySectionTag.YES.name(), finalAtlas.edge(608901269000999L).tag(SyntheticInvalidWaySectionTag.KEY));
    Assert.assertEquals(SyntheticInvalidWaySectionTag.YES.name(), finalAtlas.edge(608903805000999L).tag(SyntheticInvalidWaySectionTag.KEY));
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) HashMap(java.util.HashMap) Polygon(org.openstreetmap.atlas.geography.Polygon) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) HashSet(java.util.HashSet) Test(org.junit.Test) RawAtlasSlicingTest(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicingTest)

Example 18 with CountryBoundaryMap

use of org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap in project atlas by osmlab.

the class CountryBoundaryMapGeoJsonConverterTest method testConvertToString.

@Test
public void testConvertToString() {
    final String expected = new StringResource(() -> CountryBoundaryMapTest.class.getResourceAsStream("AAA_boundary.expected.json")).all();
    final CountryBoundaryMap mapWithGridIndex = CountryBoundaryMap.fromPlainText(new InputStreamResource(() -> CountryBoundaryMapTest.class.getResourceAsStream("AAA_boundary.txt")));
    final String jsonMap = new CountryBoundaryMapGeoJsonConverter().prettyPrint(true).convertToString(mapWithGridIndex);
    Assert.assertEquals(expected, jsonMap);
}
Also used : StringResource(org.openstreetmap.atlas.streaming.resource.StringResource) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) InputStreamResource(org.openstreetmap.atlas.streaming.resource.InputStreamResource) CountryBoundaryMapTest(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMapTest) Test(org.junit.Test)

Example 19 with CountryBoundaryMap

use of org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap in project atlas by osmlab.

the class OsmPbfIngestIntegrationTest method testWaysSpanningOutsideOfCountry.

@Test
public void testWaysSpanningOutsideOfCountry() {
    final Resource pbf = new InputStreamResource(() -> OsmPbfIngestIntegrationTest.class.getResourceAsStream("CUB_72-111.pbf"));
    final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource(() -> OsmPbfIngestIntegrationTest.class.getResourceAsStream("CUB_osm_boundaries.txt.gz")).withDecompressor(Decompressor.GZIP));
    final SlippyTile tile = SlippyTile.forName("8-72-111");
    final MultiPolygon boundary = map.countryBoundary("CUB").get(0).getBoundary();
    final MultiPolygon loadingArea = tile.bounds().clip(boundary, ClipType.AND).getClipMultiPolygon();
    final AtlasLoadingOption loadingOption = AtlasLoadingOption.createOptionWithAllEnabled(map);
    Atlas atlas = new RawAtlasGenerator(pbf, loadingOption, loadingArea).build();
    atlas = new RawAtlasSlicer(loadingOption, atlas).slice();
    atlas = new WaySectionProcessor(atlas, loadingOption).run();
    // Make sure that the big bridge over water made it to the Atlas
    Assert.assertNotNull(atlas.edge(308541861000000L));
}
Also used : Atlas(org.openstreetmap.atlas.geography.atlas.Atlas) WaySectionProcessor(org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor) SlippyTile(org.openstreetmap.atlas.geography.sharding.SlippyTile) MultiPolygon(org.openstreetmap.atlas.geography.MultiPolygon) Resource(org.openstreetmap.atlas.streaming.resource.Resource) InputStreamResource(org.openstreetmap.atlas.streaming.resource.InputStreamResource) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) RawAtlasSlicer(org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer) InputStreamResource(org.openstreetmap.atlas.streaming.resource.InputStreamResource) RawAtlasGenerator(org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator) AtlasIntegrationTest(org.openstreetmap.atlas.geography.atlas.AtlasIntegrationTest) Test(org.junit.Test)

Example 20 with CountryBoundaryMap

use of org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap in project atlas by osmlab.

the class WKTShardCommand method execute.

@Override
public int execute() {
    final List<String> inputWktOrShard = new ArrayList<>();
    if (this.optionAndArgumentDelegate.hasOption(INPUT_FILE_OPTION_LONG)) {
        inputWktOrShard.addAll(readInputsFromFile(this.optionAndArgumentDelegate.getOptionArgument(INPUT_FILE_OPTION_LONG).orElse(null)));
    }
    inputWktOrShard.addAll(this.optionAndArgumentDelegate.getVariadicArgument(INPUT_WKT_SHARD));
    if (inputWktOrShard.isEmpty()) {
        this.outputDelegate.printlnWarnMessage("no input WKTs were found");
        return 0;
    }
    Sharding sharding = null;
    CountryBoundaryMap countryBoundaryMap = null;
    if (this.optionAndArgumentDelegate.getParserContext() == SHARDING_CONTEXT) {
        sharding = Sharding.forString(this.optionAndArgumentDelegate.getOptionArgument(SHARDING_OPTION_LONG).orElseThrow(AtlasShellToolsException::new), this.getFileSystem());
    } else if (this.optionAndArgumentDelegate.getParserContext() == COUNTRY_BOUNDARY_CONTEXT) {
        final Optional<CountryBoundaryMap> mapOptional = loadCountryBoundaryMap();
        if (mapOptional.isEmpty()) {
            this.outputDelegate.printlnErrorMessage("failed to load country boundary");
            return 1;
        }
        countryBoundaryMap = mapOptional.get();
    } else {
        throw new AtlasShellToolsException();
    }
    for (int i = 0; i < inputWktOrShard.size(); i++) {
        final String wktOrShard = inputWktOrShard.get(i);
        parseWktOrShardAndPrintOutput(wktOrShard, sharding, countryBoundaryMap);
        // Only print a separating newline if there were multiple entries
        if (i < inputWktOrShard.size() - 1) {
            this.outputDelegate.printlnStdout("");
        }
    }
    return 0;
}
Also used : Sharding(org.openstreetmap.atlas.geography.sharding.Sharding) AtlasShellToolsException(org.openstreetmap.atlas.utilities.command.AtlasShellToolsException) Optional(java.util.Optional) ArrayList(java.util.ArrayList) LineString(org.locationtech.jts.geom.LineString) CountryBoundaryMap(org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap) Point(org.locationtech.jts.geom.Point)

Aggregations

CountryBoundaryMap (org.openstreetmap.atlas.geography.boundary.CountryBoundaryMap)27 Test (org.junit.Test)11 Atlas (org.openstreetmap.atlas.geography.atlas.Atlas)11 File (org.openstreetmap.atlas.streaming.resource.File)10 InputStreamResource (org.openstreetmap.atlas.streaming.resource.InputStreamResource)9 MultiPolygon (org.openstreetmap.atlas.geography.MultiPolygon)6 RawAtlasGenerator (org.openstreetmap.atlas.geography.atlas.raw.creation.RawAtlasGenerator)6 RawAtlasSlicer (org.openstreetmap.atlas.geography.atlas.raw.slicing.RawAtlasSlicer)6 StringList (org.openstreetmap.atlas.utilities.collections.StringList)6 AtlasLoadingOption (org.openstreetmap.atlas.geography.atlas.pbf.AtlasLoadingOption)5 WaySectionProcessor (org.openstreetmap.atlas.geography.atlas.raw.sectioning.WaySectionProcessor)5 StandardConfiguration (org.openstreetmap.atlas.utilities.configuration.StandardConfiguration)5 Time (org.openstreetmap.atlas.utilities.time.Time)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Optional (java.util.Optional)4 CountryShard (org.openstreetmap.atlas.geography.sharding.CountryShard)4 Resource (org.openstreetmap.atlas.streaming.resource.Resource)4 StringResource (org.openstreetmap.atlas.streaming.resource.StringResource)4 HashMap (java.util.HashMap)3