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());
}
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));
}
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);
}
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));
}
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;
}
Aggregations