use of com.graphhopper.routing.util.countryrules.CountryRuleFactory 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.util.countryrules.CountryRuleFactory in project graphhopper by graphhopper.
the class CHImportTest method main.
public static void main(String[] args) {
System.out.println("running for args: " + Arrays.toString(args));
PMap map = PMap.read(args);
String vehicle = map.getString("vehicle", "car");
GraphHopperConfig config = new GraphHopperConfig(map);
config.putObject("datareader.file", map.getString("pbf", "map-matching/files/leipzig_germany.osm.pbf"));
config.putObject("graph.location", map.getString("gh", "ch-import-test-gh"));
config.setProfiles(Arrays.asList(new Profile(vehicle).setVehicle(vehicle).setWeighting("fastest")));
config.setCHProfiles(Collections.singletonList(new CHProfile(vehicle)));
config.putObject(CHParameters.PERIODIC_UPDATES, map.getInt("periodic", 0));
config.putObject(CHParameters.LAST_LAZY_NODES_UPDATES, map.getInt("lazy", 100));
config.putObject(CHParameters.NEIGHBOR_UPDATES, map.getInt("neighbor", 100));
config.putObject(CHParameters.NEIGHBOR_UPDATES_MAX, map.getInt("neighbor_max", 2));
config.putObject(CHParameters.CONTRACTED_NODES, map.getInt("contracted", 100));
config.putObject(CHParameters.LOG_MESSAGES, map.getInt("logs", 20));
config.putObject(CHParameters.EDGE_DIFFERENCE_WEIGHT, map.getDouble("edge_diff", 10));
config.putObject(CHParameters.ORIGINAL_EDGE_COUNT_WEIGHT, map.getDouble("orig_edge", 1));
config.putObject(CHParameters.MAX_POLL_FACTOR_HEURISTIC_NODE, map.getDouble("mpf_heur", 5));
config.putObject(CHParameters.MAX_POLL_FACTOR_CONTRACTION_NODE, map.getDouble("mpf_contr", 200));
GraphHopper hopper = new GraphHopper();
hopper.init(config);
if (map.getBool("use_country_rules", false))
// note that using this requires a new import of the base graph!
hopper.setCountryRuleFactory(new CountryRuleFactory());
hopper.importOrLoad();
runQueries(hopper, vehicle);
}
use of com.graphhopper.routing.util.countryrules.CountryRuleFactory 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));
}
use of com.graphhopper.routing.util.countryrules.CountryRuleFactory in project graphhopper by graphhopper.
the class GraphHopperTest method germanyCountryRuleAvoidsTracks.
@Test
public void germanyCountryRuleAvoidsTracks() {
final String profile = "profile";
// first we try without country rules (the default)
GraphHopper hopper = new GraphHopper().setProfiles(new Profile(profile).setVehicle("car").setWeighting("fastest")).setCountryRuleFactory(null).setGraphHopperLocation(GH_LOCATION).setOSMFile(BAYREUTH);
hopper.importOrLoad();
GHRequest request = new GHRequest(50.010373, 11.51792, 50.005146, 11.516633);
request.setProfile(profile);
GHResponse response = hopper.route(request);
assertFalse(response.hasErrors());
double distance = response.getBest().getDistance();
// The route takes a shortcut through the forest
assertEquals(1447, distance, 1);
// this time we enable country rules
hopper.clean();
hopper = new GraphHopper().setProfiles(new Profile(profile).setVehicle("car").setWeighting("fastest")).setGraphHopperLocation(GH_LOCATION).setCountryRuleFactory(new CountryRuleFactory()).setOSMFile(BAYREUTH);
hopper.importOrLoad();
request = new GHRequest(50.010373, 11.51792, 50.005146, 11.516633);
request.setProfile(profile);
response = hopper.route(request);
assertFalse(response.hasErrors());
distance = response.getBest().getDistance();
// since GermanyCountryRule avoids TRACK roads the route will now be much longer as it goes around the forest
assertEquals(4186, distance, 1);
}
Aggregations