use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class MapMatching2Test method testIssue70.
@Test
public void testIssue70() throws IOException {
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile("../map-matching/files/issue-70.osm.gz");
hopper.setGraphHopperLocation(GH_LOCATION);
hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
hopper.importOrLoad();
MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-70.gpx"), Gpx.class);
MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
assertEquals(Arrays.asList("Милана Видака", "Бранка Радичевића", "Здравка Челара"), fetchStreets(mr.getEdgeMatches()));
for (EdgeMatch edgeMatch : mr.getEdgeMatches()) {
validateEdgeMatch(edgeMatch);
}
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class RoutingAdditivityTest method setup.
@BeforeAll
public static void setup() {
Helper.removeDir(new File(GH_LOCATION));
graphHopper = new GraphHopper();
graphHopper.setOSMFile("../map-matching/files/leipzig_germany.osm.pbf");
graphHopper.setGraphHopperLocation(GH_LOCATION);
graphHopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
graphHopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
graphHopper.importOrLoad();
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperStorageTest method testLoadGraph_implicitEncodedValues_issue1862.
@Test
public void testLoadGraph_implicitEncodedValues_issue1862() {
Helper.removeDir(new File(defaultGraphLoc));
encodingManager = new EncodingManager.Builder().add(createCarFlagEncoder()).add(new BikeFlagEncoder()).build();
graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false).create(defaultSize);
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 12, 23);
na.setNode(1, 8, 13);
na.setNode(2, 2, 10);
na.setNode(3, 5, 9);
GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 2).setDistance(10));
GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 3).setDistance(10));
int nodes = graph.getNodes();
int edges = graph.getAllEdges().length();
graph.flush();
Helper.close(graph);
// load without configured FlagEncoders
GraphHopper hopper = new GraphHopper();
hopper.setProfiles(Arrays.asList(new Profile("p_car").setVehicle("car").setWeighting("fastest"), new Profile("p_bike").setVehicle("bike").setWeighting("fastest")));
hopper.setGraphHopperLocation(defaultGraphLoc);
assertTrue(hopper.load());
graph = hopper.getGraphHopperStorage();
assertEquals(nodes, graph.getNodes());
assertEquals(edges, graph.getAllEdges().length());
Helper.close(graph);
hopper = new GraphHopper();
// load via explicitly configured FlagEncoders then we can define only one profile
hopper.getEncodingManagerBuilder().add(createCarFlagEncoder()).add(new BikeFlagEncoder());
hopper.setProfiles(Collections.singletonList(new Profile("p_car").setVehicle("car").setWeighting("fastest")));
hopper.setGraphHopperLocation(defaultGraphLoc);
assertTrue(hopper.load());
graph = hopper.getGraphHopperStorage();
assertEquals(nodes, graph.getNodes());
assertEquals(edges, graph.getAllEdges().length());
Helper.close(graph);
Helper.removeDir(new File(defaultGraphLoc));
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class GraphHopperStorageLMTest method testLoad.
@Test
public void testLoad() {
String defaultGraphLoc = "./target/ghstorage_lm";
Helper.removeDir(new File(defaultGraphLoc));
CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager.Builder().add(carFlagEncoder).add(Subnetwork.create("my_profile")).build();
GraphHopperStorage graph = GraphBuilder.start(encodingManager).setRAM(defaultGraphLoc, true).create();
// 0-1
ReaderWay way_0_1 = new ReaderWay(27l);
way_0_1.setTag("highway", "primary");
way_0_1.setTag("maxheight", "4.4");
GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(0, 1).setDistance(1));
updateDistancesFor(graph, 0, 0.00, 0.00);
updateDistancesFor(graph, 1, 0.01, 0.01);
graph.getEdgeIteratorState(0, 1).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_0_1));
// 1-2
ReaderWay way_1_2 = new ReaderWay(28l);
way_1_2.setTag("highway", "primary");
way_1_2.setTag("maxweight", "45");
GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(1, 2).setDistance(1));
updateDistancesFor(graph, 2, 0.02, 0.02);
graph.getEdgeIteratorState(1, 2).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_1_2));
graph.flush();
graph.close();
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
// does lm preparation
hopper.importOrLoad();
EncodingManager em = hopper.getEncodingManager();
assertNotNull(em);
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
// just loads the LM data
hopper.importOrLoad();
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class DefaultModule method createGraphHopper.
/**
* @return an initialized GraphHopper instance
*/
protected GraphHopper createGraphHopper(CmdArgs args) {
GraphHopper tmp = new GraphHopperOSM() {
@Override
protected void loadOrPrepareLM() {
if (!getLMFactoryDecorator().isEnabled() || getLMFactoryDecorator().getPreparations().isEmpty())
return;
try {
String location = args.get(Parameters.Landmark.PREPARE + "split_area_location", "");
Reader reader = location.isEmpty() ? new InputStreamReader(LandmarkStorage.class.getResource("map.geo.json").openStream()) : new FileReader(location);
JsonFeatureCollection jsonFeatureCollection = new GHJsonBuilder().create().fromJson(reader, JsonFeatureCollection.class);
if (!jsonFeatureCollection.getFeatures().isEmpty()) {
SpatialRuleLookup ruleLookup = new SpatialRuleLookupBuilder().build("country", new SpatialRuleLookupBuilder.SpatialRuleDefaultFactory(), jsonFeatureCollection, getGraphHopperStorage().getBounds(), 0.1, true);
for (PrepareLandmarks prep : getLMFactoryDecorator().getPreparations()) {
prep.setSpatialRuleLookup(ruleLookup);
}
}
} catch (IOException ex) {
logger.error("Problem while reading border map GeoJSON. Skipping this.", ex);
}
super.loadOrPrepareLM();
}
}.forServer().init(args);
String location = args.get("spatial_rules.location", "");
if (!location.isEmpty()) {
if (!tmp.getEncodingManager().supports(("generic"))) {
logger.warn("spatial_rules.location was specified but 'generic' encoder is missing to utilize the index");
} else
try {
SpatialRuleLookup index = buildIndex(new FileReader(location), tmp.getGraphHopperStorage().getBounds());
if (index != null) {
logger.info("Set spatial rule lookup with " + index.size() + " rules");
((DataFlagEncoder) tmp.getEncodingManager().getEncoder("generic")).setSpatialRuleLookup(index);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
tmp.importOrLoad();
logger.info("loaded graph at:" + tmp.getGraphHopperLocation() + ", data_reader_file:" + tmp.getDataReaderFile() + ", flag_encoders:" + tmp.getEncodingManager() + ", " + tmp.getGraphHopperStorage().toDetailsString());
return tmp;
}
Aggregations