Search in sources :

Example 1 with OSMReaderConfig

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));
}
Also used : CountryParser(com.graphhopper.routing.util.parsers.CountryParser) OSMReaderConfig(com.graphhopper.routing.OSMReaderConfig) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) File(java.io.File) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 2 with OSMReaderConfig

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));
}
Also used : OSMReaderConfig(com.graphhopper.routing.OSMReaderConfig) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) File(java.io.File) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Aggregations

GraphHopperTest (com.graphhopper.GraphHopperTest)2 OSMReaderConfig (com.graphhopper.routing.OSMReaderConfig)2 CountryRuleFactory (com.graphhopper.routing.util.countryrules.CountryRuleFactory)2 File (java.io.File)2 Test (org.junit.jupiter.api.Test)2 CountryParser (com.graphhopper.routing.util.parsers.CountryParser)1