@Test(expected = CoreException.class) public void testGridIndexReconstructionWithMissingCountryCode() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final Set<String> countries = new HashSet<>( Arrays.asList("HTI", "DOM", /* Not there on purpose */"CIV")); // This is expected to throw a CoreException listing the missing country, versus a NPE. map.initializeGridIndex(countries); }
@Test public void testBigNodeWithNoRestrictions() { final Atlas atlas = new TextAtlasBuilder().read(new InputStreamResource( () -> ComplexTurnRestrictionTest.class.getResourceAsStream("bigNode.txt.gz")) .withDecompressor(Decompressor.GZIP).withName("bigNode.txt.gz")); final List<BigNode> bigNodes = Iterables.asList(new BigNodeFinder().find(atlas)); final Optional<BigNode> possibleBigNode = bigNodes.stream() .filter(bigNode -> bigNode.getOsmIdentifier() == 3717537957L).findAny(); Assert.assertTrue(possibleBigNode.isPresent()); final BigNode bigNode = possibleBigNode.get(); Assert.assertTrue(!bigNode.allPaths().isEmpty()); Assert.assertTrue(bigNode.turnRestrictions().isEmpty()); }
@Test public void testFeatureCrossingCountryBoundary() throws ParseException { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final WKTReader reader = new WKTReader(); final Geometry geometry = reader.read( "POLYGON (( -71.7424191 18.7499411097, -71.730485136 18.749848501, -71.730081575 18.749979671, -71.730142154 18.749575218, -71.730486015 18.7498444, -71.7424191 18.7499411097 ))"); final List<Geometry> pieces = map.slice(1000000L, geometry); logger.info(pieces.toString()); Assert.assertEquals(2, pieces.size()); }
private static void testAndValidateGridIndexConsistency(final Set<String> countries, final String filename) { // Generate grid index for the first time final CountryBoundaryMap firstMap = CountryBoundaryMap.fromPlainText( new InputStreamResource(CountryBoundaryMapTest.class.getResourceAsStream(filename)) .withDecompressor(Decompressor.GZIP)); firstMap.initializeGridIndex(countries); // Generate grid index for the second time final CountryBoundaryMap secondMap = CountryBoundaryMap.fromPlainText( new InputStreamResource(CountryBoundaryMapTest.class.getResourceAsStream(filename)) .withDecompressor(Decompressor.GZIP)); secondMap.initializeGridIndex(countries); // Compare Assert.assertTrue(CountryBoundaryMapCompareCommand.areSTRtreesEqual(firstMap.getGridIndex(), secondMap.getGridIndex())); }
@Test public void testForceSlicing() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final Set<String> countries = new HashSet<>(); countries.add("HTI"); countries.add("DOM"); map.initializeGridIndex(countries); // Crosses HTI only and falls in the international waters on both sides final LineString lineString = (LineString) TestUtility.createJtsGeometryFromWKT( "LINESTRING(-72.62310537054378 16.33562831580734,-73.54595693304378 18.890373956748753)"); final List<Geometry> sliced1 = map.slice(123, lineString); map.setShouldAlwaysSlicePredicate( taggable -> taggable.getTag("IShouldBeSliced").isPresent()); final List<Geometry> sliced2 = map.slice(123, lineString); final List<Geometry> sliced3 = map.slice(123, lineString, Taggable.with("IShouldBeSliced", "yes")); final List<Geometry> sliced4 = map.slice(123, lineString, Taggable.with("ShouldIBeSliced", "no")); Assert.assertEquals(1, sliced1.size()); Assert.assertEquals(1, sliced2.size()); Assert.assertEquals(3, sliced3.size()); Assert.assertEquals(1, sliced4.size()); }
@Test public void testOnDemandIndexAndIndexFromFileViaCountryList() { final Set<String> countries = new HashSet<>(); countries.add("AIA"); countries.add("MAF"); // Generate grid index for the first time final CountryBoundaryMap firstMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(firstMap.hasGridIndex()); firstMap.initializeGridIndex(countries); Assert.assertTrue(firstMap.hasGridIndex()); // Read grid index from file final CountryBoundaryMap secondMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries_with_grid_index.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertTrue(secondMap.hasGridIndex()); // Compare Assert.assertTrue(CountryBoundaryMapCompareCommand.areSTRtreesEqual(firstMap.getGridIndex(), secondMap.getGridIndex())); }
.withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); map.initializeGridIndex(countries);
@Test public void testAntiMeridian() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); final LineString lineString = (LineString) TestUtility .createJtsGeometryFromWKT("LINESTRING ( -179 18.84927, 179 18.84927 )"); // HTI is the closest to the line Assert.assertEquals("HTI", map.getCountryCodeISO3(lineString).getIso3CountryCode()); }
@Test public void testMultiPolygonBoundary() { final StringList countries = new StringList(); countries.add("ZAF"); final CountryBoundaryMap boundaries = CountryBoundaryMap .fromPlainText(new InputStreamResource(() -> CountryShardListingTest.class .getResourceAsStream("ZAF_osm_boundary.txt.gz")) .withDecompressor(Decompressor.GZIP)); final Sharding sharding = Sharding.forString("dynamic@" + CountryShardListingTest.class.getResource("tree-6-14-100000.txt.gz").getPath()); final MultiMapWithSet<String, Shard> shardSetPerCountry = CountryShardListing .countryToShardList(countries, boundaries, sharding); final Resource expectedShardList = new InputStreamResource( () -> CountryShardListingTest.class .getResourceAsStream("ZAF_osm_shards_with_14.txt")); Assert.assertEquals(Iterables.size(expectedShardList.lines()), shardSetPerCountry.get(countries.get(0)).size()); expectedShardList.lines().forEach(line -> { final CountryShard expected = CountryShard.forName(line); Assert.assertTrue( shardSetPerCountry.get(countries.get(0)).contains(expected.getShard())); }); }
@Test public void testSmallCountry() { final StringList countries = new StringList(); countries.add("DMA"); final CountryBoundaryMap boundaries = CountryBoundaryMap .fromPlainText(new InputStreamResource(CountryShardListingTest.class .getResourceAsStream("DMA_as_world_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); final Sharding sharding = Sharding.forString("dynamic@" + CountryShardListingTest.class.getResource("tree-6-13-100000.txt.gz").getPath()); final MultiMapWithSet<String, Shard> shardSetPerCountry = CountryShardListing .countryToShardList(countries, boundaries, sharding); Assert.assertEquals(4, shardSetPerCountry.get(countries.get(0)).size()); StringList.split("DMA_9-168-233,DMA_9-169-233,DMA_9-168-234,DMA_10-338-468", ",") .forEach(line -> { final CountryShard expected = CountryShard.forName(line); Assert.assertTrue( shardSetPerCountry.get(countries.get(0)).contains(expected.getShard())); }); } }
@Test public void testOnDemandIndexAndIndexFromFileViaArea() { // Generate grid index for the first time final CountryBoundaryMap firstMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(firstMap.hasGridIndex()); firstMap.initializeGridIndex( new JtsMultiPolygonToMultiPolygonConverter().backwardConvert(MultiPolygon.MAXIMUM)); Assert.assertTrue(firstMap.hasGridIndex()); // Read grid index from file final CountryBoundaryMap secondMap = CountryBoundaryMap .fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries_with_grid_index.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertTrue(secondMap.hasGridIndex()); // Compare Assert.assertTrue(CountryBoundaryMapCompareCommand.areSTRtreesEqual(firstMap.getGridIndex(), secondMap.getGridIndex())); }
.withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); Assert.assertEquals("CIV", firstCountryName(map));
.fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries_with_grid_index.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertTrue(mapWithGridIndex.hasGridIndex()); .fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(mapFromOsmTextFile.hasGridIndex()); mapFromOsmTextFile.initializeGridIndex(mapFromOsmTextFile.getLoadedCountries());
.withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex());
.fromPlainText(new InputStreamResource(CountryBoundaryMapTest.class .getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); final Envelope maxEnvelope = new Envelope(Longitude.MIN_VALUE, Longitude.MAX_VALUE, Latitude.MINIMUM.asDegrees(), Latitude.MAXIMUM.asDegrees());
.withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex());
@Test public void testPartialLoad() { final Rectangle rectangleInStMartin = Rectangle.forLocations( Location.forString("18.0298609, -63.0665379"), Location.forString("18.0298052, -63.0663907")); final CountryBoundaryMap partialStMartinMap = new CountryBoundaryMap(rectangleInStMartin); partialStMartinMap.readFromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(partialStMartinMap.hasGridIndex()); Assert.assertEquals(1, partialStMartinMap.size()); Assert.assertEquals("MAF", firstCountryName(partialStMartinMap)); Assert.assertNotNull(partialStMartinMap.countryBoundary("MAF")); Assert.assertNull(partialStMartinMap.countryBoundary("AIA")); final Rectangle rectangleInAIA = Rectangle.forLocations( Location.forString("18.096068, -63.0643537"), Location.forString("18.0927713, -63.0612415")); final CountryBoundaryMap partialAIAMap = new CountryBoundaryMap(rectangleInAIA); partialAIAMap.readFromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("MAF_AIA_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(partialAIAMap.hasGridIndex()); Assert.assertEquals(1, partialAIAMap.size()); Assert.assertEquals("AIA", firstCountryName(partialAIAMap)); Assert.assertNotNull(partialAIAMap.countryBoundary("AIA")); Assert.assertNull(partialAIAMap.countryBoundary("MAF")); }
@Test public void testGetCountryCode() { final CountryBoundaryMap map = CountryBoundaryMap.fromPlainText(new InputStreamResource( CountryBoundaryMapTest.class.getResourceAsStream("HTI_DOM_osm_boundaries.txt.gz")) .withDecompressor(Decompressor.GZIP)); Assert.assertFalse(map.hasGridIndex()); Point point = JTS_POINT_CONVERTER .convert(Location.forString("19.068387997775737, -71.7029007844633")); CountryCodeProperties countryDetails = map.getCountryCodeISO3(point); Assert.assertEquals("DOM", countryDetails.getIso3CountryCode()); point = JTS_POINT_CONVERTER .convert(Location.forString("19.069172931560374, -71.70712929872246")); countryDetails = map.getCountryCodeISO3(point); Assert.assertEquals("HTI", countryDetails.getIso3CountryCode()); point = JTS_POINT_CONVERTER.convert(Location.forString("19.0681781, -71.7075623")); countryDetails = map.getCountryCodeISO3(point, false); Assert.assertEquals("HTI,DOM", countryDetails.getIso3CountryCode()); }
.load(new InputStreamResource(() -> AtlasResourceLoaderTest.class .getResourceAsStream("NZL_9-506-316.atlas.gz")) .withDecompressor(Decompressor.GZIP) .withName("NZL_9-506-316.atlas.gz")); .withDecompressor(Decompressor.GZIP).withName("NZL_9-506-316.atlas.gz")); .load(new InputStreamResource(() -> AtlasResourceLoaderTest.class .getResourceAsStream("NZL_9-506-316.atlas.gz")) .withDecompressor(Decompressor.GZIP) .withName("NZL_9-506-316.atlas.gz"));