Skip to content

Commit 540fea6

Browse files
committed
Add --output option to osrm-extract for custom output base path
1 parent d8ff021 commit 540fea6

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Thumbs.db
4343
#######################
4444
/_build*
4545
/build/
46-
/test/data/monaco.osrm*
46+
/test/data/monaco*.osrm*
4747
/test/data/ch
4848
/test/data/mld
4949
/cmake/postinst

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- FIXED: Work around compilation error due to a false-positive of array-bounds check in sol2 [#7317](https://github.com/Project-OSRM/osrm-backend/pull/7317)
1818
- FIXED: Fix compilation with gcc >14 in release with LTO. [#7268](https://github.com/Project-OSRM/osrm-backend/issues/7268)
1919
- Misc:
20+
- ADDED: `--output` / `-o` option to osrm-extract for specifying custom output base path [#4930](https://github.com/Project-OSRM/osrm-backend/issues/4930)
2021
- ADDED: `--max-header-size` to override the (automatically) configured maximum header size for osrm-routed [#7336](https://github.com/Project-OSRM/osrm-backend/pull/7336)
2122
- CHANGED: Use boost::beast instead of own HTTP code for osrm-routed [#7328](https://github.com/Project-OSRM/osrm-backend/pull/7328)
2223
- ADDED: `SHM_LOCK_DIR` environment variable for shared memory lock file directory [#7312](https://github.com/Project-OSRM/osrm-backend/pull/7312)

docs/profiles.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ When running OSRM preprocessing commands you specify the profile with the --prof
1212

1313
`osrm-extract --profile ../profiles/car.lua planet-latest.osm.pbf`
1414

15+
### Using Multiple Profiles with the Same Input
16+
17+
You can extract the same OSM file with different profiles by specifying an output path:
18+
19+
```bash
20+
osrm-extract --profile profiles/car.lua planet.osm.pbf --output /data/car
21+
osrm-extract --profile profiles/bicycle.lua planet.osm.pbf --output /data/bicycle
22+
osrm-extract --profile profiles/foot.lua planet.osm.pbf --output /data/foot
23+
```
24+
25+
This avoids the need to create symbolic links to the input file.
26+
1527
## Processing flow
1628
It's important to understand that profiles are used when preprocessing the OSM data, NOT at query time when routes are computed.
1729

include/extractor/extractor_config.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct ExtractorConfig final : storage::IOConfig
7777
std::filesystem::path input_path;
7878
std::filesystem::path profile_path;
7979
std::vector<std::filesystem::path> location_dependent_data_paths;
80+
std::filesystem::path output_path;
8081
std::string data_version;
8182

8283
unsigned requested_num_threads = 0;

src/tools/extract.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ return_code parseArguments(int argc,
7878
boost::program_options::bool_switch(&extractor_config.dump_nbg_graph)
7979
->implicit_value(true)
8080
->default_value(false),
81-
"Dump raw node-based graph to *.osrm file for debug purposes.");
81+
"Dump raw node-based graph to *.osrm file for debug purposes.")(
82+
"output,o",
83+
boost::program_options::value<std::filesystem::path>(&extractor_config.output_path),
84+
"Output base path for generated files (default: derived from input file name)");
8285

8386
bool dummy;
8487
// hidden options, will be allowed on command line, but will not be
@@ -166,7 +169,14 @@ try
166169

167170
util::LogPolicy::GetInstance().SetLevel(verbosity);
168171

169-
extractor_config.UseDefaultOutputNames(extractor_config.input_path);
172+
if (!extractor_config.output_path.empty())
173+
{
174+
extractor_config.UseDefaultOutputNames(extractor_config.output_path);
175+
}
176+
else
177+
{
178+
extractor_config.UseDefaultOutputNames(extractor_config.input_path);
179+
}
170180

171181
if (1 > extractor_config.requested_num_threads)
172182
{

unit_tests/library/extract.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "osrm/extractor_config.hpp"
66

77
#include <boost/algorithm/string.hpp>
8+
#include <filesystem>
89
#include <thread>
910

1011
// utility class to redirect stderr so we can test it
@@ -48,6 +49,21 @@ BOOST_AUTO_TEST_CASE(test_extract_with_valid_config)
4849
BOOST_CHECK_NO_THROW(osrm::extract(config));
4950
}
5051

52+
BOOST_AUTO_TEST_CASE(test_extract_with_custom_output_path)
53+
{
54+
osrm::ExtractorConfig config;
55+
config.input_path = OSRM_TEST_DATA_DIR "/monaco.osm.pbf";
56+
// Use custom output path instead of deriving from input
57+
config.UseDefaultOutputNames(OSRM_TEST_DATA_DIR "/monaco-custom-output");
58+
config.profile_path = OSRM_TEST_DATA_DIR "/../../profiles/car.lua";
59+
config.small_component_size = 1000;
60+
config.requested_num_threads = std::thread::hardware_concurrency();
61+
BOOST_CHECK_NO_THROW(osrm::extract(config));
62+
63+
// Verify output files exist at custom path
64+
BOOST_CHECK(std::filesystem::exists(OSRM_TEST_DATA_DIR "/monaco-custom-output.osrm.names"));
65+
}
66+
5167
BOOST_AUTO_TEST_CASE(test_setup_runtime_error)
5268
{
5369
osrm::ExtractorConfig config;

0 commit comments

Comments
 (0)