public void start(CmdArgs cmdArgs) { String logfile = cmdArgs.get("logfile", ""); int workers = cmdArgs.getInt("workers", 1); baseUrl = cmdArgs.get("baseurl", ""); tooShortDistance = cmdArgs.getDouble("too_short_distance", 50d); maxQueries = cmdArgs.getLong("maxqueries", 1000L); timeout = cmdArgs.getInt("timeout", 3000); logRequest = cmdArgs.getBool("log_request", false); statusUpdateCnt = maxQueries / 10; if (Helper.isEmpty(baseUrl))
public static CmdArgs readFromSystemProperties() { CmdArgs cmdArgs = new CmdArgs(); for (Entry<Object, Object> e : System.getProperties().entrySet()) { String k = ((String) e.getKey()); String v = ((String) e.getValue()); if (k.startsWith("graphhopper.")) { k = k.substring("graphhopper.".length()); cmdArgs.put(k, v); } } return cmdArgs; }
args.merge(CmdArgs.readFromSystemProperties()); if (args.has("osmreader.osm")) throw new IllegalArgumentException("Instead osmreader.osm use datareader.file, for other changes see core/files/changelog.txt"); String tmpOsmFile = args.get("datareader.file", ""); if (!isEmpty(tmpOsmFile)) dataReaderFile = tmpOsmFile; String graphHopperFolder = args.get("graph.location", ""); if (isEmpty(graphHopperFolder) && isEmpty(ghLocation)) { if (isEmpty(dataReaderFile)) defaultSegmentSize = args.getInt("graph.dataaccess.segment_size", defaultSegmentSize); String graphDATypeStr = args.get("graph.dataaccess", "RAM_STORE"); dataAccessType = DAType.fromString(graphDATypeStr); sortGraph = args.getBool("graph.do_sort", sortGraph); removeZipped = args.getBool("graph.remove_zipped", removeZipped); int bytesForFlags = args.getInt("graph.bytes_for_flags", 4); String flagEncodersStr = args.get("graph.flag_encoders", ""); if (!flagEncodersStr.isEmpty()) setEncodingManager(new EncodingManager(flagEncoderFactory, flagEncodersStr, bytesForFlags)); if (args.get("graph.locktype", "native").equals("simple")) lockFactory = new SimpleFSLockFactory(); else String eleProviderStr = toLowerCase(args.get("graph.elevation.provider", "noop"));
@Override public void init(CmdArgs args) { setPreparationThreads(args.getInt(Parameters.Landmark.PREPARE + "threads", getPreparationThreads())); landmarkCount = args.getInt(Parameters.Landmark.COUNT, landmarkCount); activeLandmarkCount = args.getInt(Landmark.ACTIVE_COUNT_DEFAULT, Math.min(8, landmarkCount)); logDetails = args.getBool(Landmark.PREPARE + "log_details", false); minNodes = args.getInt(Landmark.PREPARE + "min_network_size", -1); for (String loc : args.get(Landmark.PREPARE + "suggestions_location", "").split(",")) { if (!loc.trim().isEmpty()) lmSuggestionsLocations.add(loc.trim()); } String lmWeightingsStr = args.get(Landmark.PREPARE + "weightings", ""); if (!lmWeightingsStr.isEmpty() && !lmWeightingsStr.equalsIgnoreCase("no")) { List<String> tmpLMWeightingList = Arrays.asList(lmWeightingsStr.split(",")); setWeightingsAsStrings(tmpLMWeightingList); } boolean enableThis = !weightingsAsStrings.isEmpty(); setEnabled(enableThis); if (enableThis) setDisablingAllowed(args.getBool(Landmark.INIT_DISABLING_ALLOWED, isDisablingAllowed())); }
args = CmdArgs.readFromConfigAndMerge(args, "config", "graphhopper.config"); if (args.has("osmreader.osm")) throw new IllegalArgumentException("Instead osmreader.osm use datareader.file, for other changes see core/files/changelog.txt"); String tmpOsmFile = args.get("datareader.file", ""); if (!Helper.isEmpty(tmpOsmFile)) dataReaderFile = tmpOsmFile; String graphHopperFolder = args.get("graph.location", ""); if (Helper.isEmpty(graphHopperFolder) && Helper.isEmpty(ghLocation)) { if (Helper.isEmpty(dataReaderFile)) defaultSegmentSize = args.getInt("graph.dataaccess.segment_size", defaultSegmentSize); String graphDATypeStr = args.get("graph.dataaccess", "RAM_STORE"); dataAccessType = DAType.fromString(graphDATypeStr); sortGraph = args.getBool("graph.do_sort", sortGraph); removeZipped = args.getBool("graph.remove_zipped", removeZipped); int bytesForFlags = args.getInt("graph.bytes_for_flags", 4); String flagEncodersStr = args.get("graph.flag_encoders", ""); if (!flagEncodersStr.isEmpty()) setEncodingManager(new EncodingManager(flagEncoderFactory, flagEncodersStr, bytesForFlags)); if (args.get("graph.locktype", "native").equals("simple")) lockFactory = new SimpleFSLockFactory(); else String eleProviderStr = args.get("graph.elevation.provider", "noop").toLowerCase();
private void start(CmdArgs args) { String action = args.get("action", "").toLowerCase(); args.put("graph.location", "./graph-cache"); if (action.equals("import")) { String vehicle = args.get("vehicle", "car").toLowerCase(); args.put("graph.flag_encoders", vehicle); args.put("osmreader.osm", args.get("datasource", "")); args.put("prepare.min_network_size", 200); args.put("prepare.min_one_way_network_size", 200); GraphHopper hopper = new GraphHopper().init(args); hopper.getCHFactoryDecorator().setEnabled(false); int gpxAccuracy = args.getInt("gpx_accuracy", 15); String instructions = args.get("instructions", ""); logger.info("Setup lookup index. Accuracy filter is at " + gpxAccuracy + "m"); LocationIndexMatch locationIndex = new LocationIndexMatch(graph, (LocationIndexTree) hopper.getLocationIndex(), gpxAccuracy); MapMatching mapMatching = new MapMatching(graph, locationIndex, firstEncoder); mapMatching.setSeparatedSearchDistance(args.getInt("separated_search_distance", 500)); mapMatching.setMaxVisitedNodes(args.getInt("max_visited_nodes", 1000)); mapMatching.setForceRepair(args.getBool("force_repair", false)); String gpxLocation = args.get("gpx", ""); File[] files = getFiles(gpxLocation); String gpxLocation = args.get("gpx", ""); File[] files = getFiles(gpxLocation); BBox bbox = BBox.createInverse(false);
/** * @param fileStr the file name of config.properties * @param systemProperty the property name of the configuration. E.g. -Dgraphhopper.config */ public static CmdArgs readFromConfig(String fileStr, String systemProperty) throws IOException { if (systemProperty.startsWith("-D")) systemProperty = systemProperty.substring(2); String configLocation = System.getProperty(systemProperty); if (Helper.isEmpty(configLocation)) configLocation = fileStr; Map<String, String> map = new LinkedHashMap<String, String>(); Helper.loadProperties(map, new InputStreamReader(new FileInputStream( new File(configLocation).getAbsoluteFile()), Helper.UTF_CS)); CmdArgs args = new CmdArgs(); args.merge(map); // overwrite with system settings Properties props = System.getProperties(); for (Entry<Object, Object> e : props.entrySet()) { String k = ((String) e.getKey()); String v = ((String) e.getValue()); if (k.startsWith("graphhopper.")) { k = k.substring("graphhopper.".length()); args.put(k, v); } } return args; }
/** * Command line configuration overwrites the ones in the config file. * <p> * * @return a new CmdArgs object if necessary. */ public static CmdArgs readFromConfigAndMerge(CmdArgs args, String configKey, String configSysAttr) { String configVal = args.get(configKey, ""); if (!Helper.isEmpty(configVal)) { try { CmdArgs tmp = CmdArgs.readFromConfig(configVal, configSysAttr); tmp.merge(args); return tmp; } catch (Exception ex) { throw new RuntimeException(ex); } } return args; }
@Override public void run(Bootstrap bootstrap, Namespace args) { CmdArgs graphHopperConfiguration = new CmdArgs(); graphHopperConfiguration.put("graph.location", "graph-cache"); GraphHopper hopper = new GraphHopperOSM().init(graphHopperConfiguration); hopper.getCHFactoryDecorator().setEnabled(false); System.out.println("loading graph from cache"); hopper.load(graphHopperConfiguration.get("graph.location", "graph-cache"));
public GraphHopperManaged(CmdArgs configuration, ObjectMapper objectMapper) { String splitAreaLocation = configuration.get(Parameters.Landmark.PREPARE + "split_area_location", ""); JsonFeatureCollection landmarkSplittingFeatureCollection; try (Reader reader = splitAreaLocation.isEmpty() ? new InputStreamReader(LandmarkStorage.class.getResource("map.geo.json").openStream(), UTF_CS) : new InputStreamReader(new FileInputStream(splitAreaLocation), UTF_CS)) { landmarkSplittingFeatureCollection = objectMapper.readValue(reader, JsonFeatureCollection.class); } catch (IOException e1) { logger.error("Problem while reading border map GeoJSON. Skipping this.", e1); landmarkSplittingFeatureCollection = null; } graphHopper = new GraphHopperOSM(landmarkSplittingFeatureCollection).forServer(); String spatialRuleLocation = configuration.get("spatial_rules.location", ""); if (!spatialRuleLocation.isEmpty()) { final BBox maxBounds = BBox.parseBBoxString(configuration.get("spatial_rules.max_bbox", "-180, 180, -90, 90")); try (final InputStreamReader reader = new InputStreamReader(new FileInputStream(spatialRuleLocation), UTF_CS)) { JsonFeatureCollection jsonFeatureCollection = objectMapper.readValue(reader, JsonFeatureCollection.class); SpatialRuleLookupHelper.buildAndInjectSpatialRuleIntoGH(graphHopper, maxBounds, jsonFeatureCollection); } catch (IOException e) { throw new RuntimeException(e); } } graphHopper.init(configuration); }
@Override public CmdArgs deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { jsonParser.setCodec(new ObjectMapper()); Map<String, String> args = jsonParser.readValueAs(MAP_STRING_STRING); return new CmdArgs(args); } }
private void runPtGraphHopper(CmdArgs configuration, Environment environment) { final PtFlagEncoder ptFlagEncoder = new PtFlagEncoder(); final GHDirectory ghDirectory = GraphHopperGtfs.createGHDirectory(configuration.get("graph.location", "target/tmp")); final GtfsStorage gtfsStorage = GraphHopperGtfs.createGtfsStorage(); final EncodingManager encodingManager = new EncodingManager(Arrays.asList(ptFlagEncoder, new FootFlagEncoder(), new CarFlagEncoder()), 8); final GraphHopperStorage graphHopperStorage = GraphHopperGtfs.createOrLoad(ghDirectory, encodingManager, ptFlagEncoder, gtfsStorage, configuration.has("gtfs.file") ? Arrays.asList(configuration.get("gtfs.file", "").split(",")) : Collections.emptyList(), configuration.has("datareader.file") ? Arrays.asList(configuration.get("datareader.file", "").split(",")) : Collections.emptyList()); final TranslationMap translationMap = GraphHopperGtfs.createTranslationMap(); final LocationIndex locationIndex = GraphHopperGtfs.createOrLoadIndex(ghDirectory, graphHopperStorage);
@Override public void run(GraphHopperBundleConfiguration configuration, Environment environment) { configuration.getGraphHopperConfiguration().merge(CmdArgs.readFromSystemProperties()); // If the "?type=gpx" parameter is present, sets a corresponding media type header environment.jersey().register(new TypeGPXFilter()); // Together, these two take care that MultiExceptions thrown from RouteResource // come out as JSON or GPX, depending on the media type environment.jersey().register(new MultiExceptionMapper()); environment.jersey().register(new MultiExceptionGPXMessageBodyWriter()); environment.jersey().register(new IllegalArgumentExceptionMapper()); environment.jersey().register(new GHPointConverterProvider()); if (configuration.getGraphHopperConfiguration().has("gtfs.file")) { // switch to different API implementation when using Pt runPtGraphHopper(configuration.getGraphHopperConfiguration(), environment); } else { runRegularGraphHopper(configuration.getGraphHopperConfiguration(), environment); } }
private void runRegularGraphHopper(CmdArgs configuration, Environment environment) { final GraphHopperManaged graphHopperManaged = new GraphHopperManaged(configuration, environment.getObjectMapper()); environment.lifecycle().manage(graphHopperManaged); environment.jersey().register(new AbstractBinder() { @Override protected void configure() { bind(configuration).to(CmdArgs.class); bind(graphHopperManaged).to(GraphHopperManaged.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopper.class); bind(graphHopperManaged.getGraphHopper()).to(GraphHopperAPI.class); bindFactory(HasElevation.class).to(Boolean.class).named("hasElevation"); bindFactory(LocationIndexFactory.class).to(LocationIndex.class); bindFactory(TranslationMapFactory.class).to(TranslationMap.class); bindFactory(EncodingManagerFactory.class).to(EncodingManager.class); bindFactory(GraphHopperStorageFactory.class).to(GraphHopperStorage.class); bindFactory(RasterHullBuilderFactory.class).to(DelaunayTriangulationIsolineBuilder.class); } }); if (configuration.getBool("web.change_graph.enabled", false)) { environment.jersey().register(ChangeGraphResource.class); } environment.jersey().register(NearestResource.class); environment.jersey().register(RouteResource.class); environment.jersey().register(IsochroneResource.class); environment.jersey().register(I18NResource.class); environment.jersey().register(InfoResource.class); environment.healthChecks().register("graphhopper", new GraphHopperHealthCheck(graphHopperManaged.getGraphHopper())); }
@Override public void init(CmdArgs args) { // throw explicit error for deprecated configs if (!args.get("prepare.threads", "").isEmpty()) throw new IllegalStateException("Use " + CH.PREPARE + "threads instead of prepare.threads"); if (!args.get("prepare.chWeighting", "").isEmpty() || !args.get("prepare.chWeightings", "").isEmpty()) throw new IllegalStateException("Use " + CH.PREPARE + "weightings and a comma separated list instead of prepare.chWeighting or prepare.chWeightings"); setPreparationThreads(args.getInt(CH.PREPARE + "threads", getPreparationThreads())); // default is enabled & fastest String chWeightingsStr = args.get(CH.PREPARE + "weightings", ""); if ("no".equals(chWeightingsStr) || "false".equals(chWeightingsStr)) { // default is fastest and we need to clear this explicitly weightingsAsStrings.clear(); } else if (!chWeightingsStr.isEmpty()) { List<String> tmpCHWeightingList = Arrays.asList(chWeightingsStr.split(",")); setWeightingsAsStrings(tmpCHWeightingList); } boolean enableThis = !weightingsAsStrings.isEmpty(); setEnabled(enableThis); if (enableThis) setDisablingAllowed(args.getBool(CH.INIT_DISABLING_ALLOWED, isDisablingAllowed())); pMap = args; }
args = CmdArgs.readFromConfigAndMerge(args, "config", "graphhopper.config"); String tmpOsmFile = args.get("osmreader.osm", ""); if (!Helper.isEmpty(tmpOsmFile)) osmFile = tmpOsmFile; String graphHopperFolder = args.get("graph.location", ""); if (Helper.isEmpty(graphHopperFolder) && Helper.isEmpty(ghLocation)) defaultSegmentSize = args.getInt("graph.dataaccess.segment_size", defaultSegmentSize); String graphDATypeStr = args.get("graph.dataaccess", "RAM_STORE"); dataAccessType = DAType.fromString(graphDATypeStr); sortGraph = args.getBool("graph.do_sort", sortGraph); removeZipped = args.getBool("graph.remove_zipped", removeZipped); int bytesForFlags = args.getInt("graph.bytes_for_flags", 4); String flagEncodersStr = args.get("graph.flag_encoders", ""); if (!flagEncodersStr.isEmpty()) setEncodingManager(new EncodingManager(flagEncoderFactory, flagEncodersStr, bytesForFlags)); if (args.get("graph.locktype", "native").equals("simple")) lockFactory = new SimpleFSLockFactory(); else String eleProviderStr = args.get("graph.elevation.provider", "noop").toLowerCase(); boolean eleCalcMean = args.has("graph.elevation.calcmean") ? args.getBool("graph.elevation.calcmean", false) : args.getBool("graph.elevation.calc_mean", false);
/** * @param fileStr the file name of config.properties * @param systemProperty the property name of the configuration. E.g. -Dgraphhopper.config */ public static CmdArgs readFromConfig( String fileStr, String systemProperty ) throws IOException { if (systemProperty.startsWith("-D")) systemProperty = systemProperty.substring(2); String configLocation = System.getProperty(systemProperty); if (Helper.isEmpty(configLocation)) configLocation = fileStr; Map<String, String> map = new LinkedHashMap<String, String>(); Helper.loadProperties(map, new InputStreamReader(new FileInputStream( new File(configLocation).getAbsoluteFile()), Helper.UTF_CS)); CmdArgs args = new CmdArgs(); args.merge(map); // overwrite with system settings Properties props = System.getProperties(); for (Entry<Object, Object> e : props.entrySet()) { String k = ((String) e.getKey()); String v = ((String) e.getValue()); if (k.startsWith("graphhopper.")) { k = k.substring("graphhopper.".length()); args.put(k, v); } } return args; }
/** * Command line configuration overwrites the ones in the config file. * <p> * @return a new CmdArgs object if necessary. */ public static CmdArgs readFromConfigAndMerge( CmdArgs args, String configKey, String configSysAttr ) { String configVal = args.get(configKey, ""); if (!Helper.isEmpty(configVal)) { try { CmdArgs tmp = CmdArgs.readFromConfig(configVal, configSysAttr); tmp.merge(args); return tmp; } catch (Exception ex) { throw new RuntimeException(ex); } } return args; } }