use of com.graphhopper.routing.OSMReaderConfig in project graphhopper by graphhopper.
the class OSMReaderTest method testCurvedWayAlongBorder.
@Test
public void testCurvedWayAlongBorder() throws IOException {
// see https://discuss.graphhopper.com/t/country-of-way-is-wrong-on-road-near-border-with-curvature/6908/2
EncodingManager em = EncodingManager.start().add(new CarFlagEncoder()).add(new CountryParser()).build();
EnumEncodedValue<Country> countryEnc = em.getEnumEncodedValue(Country.KEY, Country.class);
GraphHopperStorage graph = new GraphBuilder(em).build();
OSMReader reader = new OSMReader(graph, new OSMReaderConfig());
reader.setCountryRuleFactory(new CountryRuleFactory());
reader.setAreaIndex(createCountryIndex());
reader.setFile(new File(getClass().getResource("test-osm12.xml").getFile()));
reader.readGraph();
assertEquals(1, graph.getEdges());
AllEdgesIterator iter = graph.getAllEdges();
iter.next();
assertEquals(Country.BGR, iter.get(countryEnc));
}
use of com.graphhopper.routing.OSMReaderConfig in project graphhopper by graphhopper.
the class OSMReaderTest method testCountries.
@Test
public void testCountries() throws IOException {
EncodingManager em = EncodingManager.create("car");
EnumEncodedValue<RoadAccess> roadAccessEnc = em.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class);
GraphHopperStorage graph = new GraphBuilder(em).build();
OSMReader reader = new OSMReader(graph, new OSMReaderConfig());
reader.setCountryRuleFactory(new CountryRuleFactory());
reader.setAreaIndex(createCountryIndex());
// there are two edges, both with highway=track, one in Berlin, one in Paris
reader.setFile(new File(getClass().getResource("test-osm11.xml").getFile()));
reader.readGraph();
EdgeIteratorState edgeBerlin = graph.getEdgeIteratorState(0, Integer.MIN_VALUE);
EdgeIteratorState edgeParis = graph.getEdgeIteratorState(1, Integer.MIN_VALUE);
assertEquals("berlin", edgeBerlin.getName());
assertEquals("paris", edgeParis.getName());
// for Berlin there is GermanyCountryRule which changes RoadAccess for Tracks
assertEquals(RoadAccess.DESTINATION, edgeBerlin.get(roadAccessEnc));
// for Paris there is no such rule, we just get the default RoadAccess.YES
assertEquals(RoadAccess.YES, edgeParis.get(roadAccessEnc));
}
Aggregations