Skip to content

Commit fd61f4a

Browse files
committed
feat: update snap radius and max attempts options in command line parser and tests
1 parent 05f8325 commit fd61f4a

File tree

3 files changed

+74
-16
lines changed

3 files changed

+74
-16
lines changed

docs/technical-details/api-benchmarks/coordinate-generators.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Coordinate Generation Tools
22

3-
The openrouteservice provides tools for generating test coordinates that can be used for benchmarking, testing, and development purposes. These tools allow you to create realistic coordinates that are compatible with the openrouteservice API and suited for different routing profiles.
3+
The openroutes| `-r, --snap-radius` | Search radius in meters for coordinate snapping. | 350 |
4+
| `-ma, --max-attempts` | Maximum number of attempts for coordinate generation. | 100 |vice provides tools for
5+
generating test coordinates that can be used for benchmarking, testing, and development purposes. These tools allow you
6+
to create realistic coordinates that are compatible with the openrouteservice API and suited for different routing
7+
profiles.
48

59
## Prerequisites
610

@@ -43,8 +47,8 @@ The tool generates random coordinates within a specified bounding box and then u
4347
| `-d, --min-distance` | Minimum distance between start and endpoint in an a-to-b routing pair in meters. This is valid for all profiles. | 1 |
4448
| `-m, --max-distances` | Maximum distances in meters **per profile** between the start and endpoint. | (none) |
4549
| `-t, --threads` | Number of threads to use. | Available processors |
46-
| `-sr, --snap-radius` | Search radius in meters for coordinate snapping. | 1000 |
47-
| `-ma, --max-attempts` | Maximum number of attempts for coordinate generation. | 1000 |
50+
| `-sr, --snap-radius` | Search radius in meters for coordinate snapping. | 350 |
51+
| `-ma, --max-attempts` | Maximum number of attempts for coordinate generation. | 100 |
4852

4953
### Route Generator Examples
5054

@@ -101,10 +105,10 @@ The tool generates random coordinates within a specified bounding box and then u
101105
| `-n, --num-points` | Number of points to generate per profile. | (required) |
102106
| `-e, --extent` | Bounding box (minLon,minLat,maxLon,maxLat). | (required) |
103107
| `-p, --profiles` | Comma-separated list of routing profiles. | (required) |
104-
| `-r, --radius` | Search radius in meters. | 350 |
108+
| `-sr, --snap-radius` | Search radius in metersfor coordinate snapping. | 350 |
105109
| `-u, --url` | ORS API base URL. | <http://localhost:8080/ors> |
106110
| `-o, --output` | Output CSV file path. | snapped_coordinates.csv |
107-
| `-ma, --max-attempts` | Maximum number of attempts for coordinate generation. | 1000 |
111+
| `-ma, --max-attempts` | Maximum number of attempts for coordinate generation. | 100 |
108112

109113
### Snapping Generator Examples
110114

@@ -119,7 +123,7 @@ Generate 100 snapped points for the driving-car profile with a search radius of
119123
-n 100 \
120124
-e 8.6,49.3,8.7,49.4 \
121125
-p driving-car \
122-
-r 500 \
126+
-sr 500 \
123127
-u http://localhost:8080/ors \
124128
-o snapped.csv"
125129
```
@@ -135,7 +139,7 @@ Generate 50 snapped points for both driving-car and cycling-regular profiles:
135139
--num-points 50 \
136140
--extent 8.681495,49.411721,8.695485,49.419365 \
137141
--profiles driving-car,cycling-regular \
138-
--radius 250 \
142+
--snap-radius 250 \
139143
--max-attempts 1500 \
140144
--url http://localhost:8080/ors \
141145
--output snapped.csv"

ors-benchmark/src/main/java/org/heigit/ors/coordinates_generator/cli/SnappingCommandLineParser.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ protected void setupOptions() {
3636
.desc("Bounding box (minLon minLat maxLon maxLat)")
3737
.build());
3838

39-
options.addOption(Option.builder("r")
40-
.longOpt("radius")
39+
options.addOption(Option.builder("sr")
40+
.longOpt("snap-radius")
4141
.hasArg()
4242
.type(Number.class)
4343
.desc("Search radius in meters (default: 350)")
@@ -66,7 +66,7 @@ protected void setupOptions() {
6666
.longOpt(OPT_MAX_ATTEMPTS)
6767
.hasArg()
6868
.type(Number.class)
69-
.desc("Maximum number of attempts for coordinate generation (default: 1000)")
69+
.desc("Maximum number of attempts for coordinate generation (default: 100)")
7070
.build());
7171
}
7272

@@ -94,16 +94,16 @@ public CoordinateGeneratorSnapping createGenerator() {
9494
int numPoints = Integer.parseInt(cmd.getOptionValue("n"));
9595
double[] extent = parseExtent(cmd.getOptionValue("e"));
9696
String[] profiles = parseProfiles(cmd.getOptionValue("p"));
97-
double radius = Double.parseDouble(cmd.getOptionValue("r", "350"));
97+
double snapRadius = Double.parseDouble(cmd.getOptionValue("sr", "350"));
9898
String baseUrl = cmd.getOptionValue("u", "http://localhost:8080/ors");
9999
int maxAttempts = Integer.parseInt(
100100
cmd.getOptionValue(OPT_MAX_ATTEMPTS, "100"));
101101

102102
LOGGER.info(
103-
"Creating CoordinateGeneratorSnapping with numPoints={}, extent={}, radius={}, profiles={}, baseUrl={}, maxAttempts={}",
104-
numPoints, extent, radius, profiles, baseUrl, maxAttempts);
103+
"Creating CoordinateGeneratorSnapping with numPoints={}, extent={}, snapRadius={}, profiles={}, baseUrl={}, maxAttempts={}",
104+
numPoints, extent, snapRadius, profiles, baseUrl, maxAttempts);
105105

106-
CoordinateGeneratorSnapping generator = new CoordinateGeneratorSnapping(numPoints, extent, radius, profiles,
106+
CoordinateGeneratorSnapping generator = new CoordinateGeneratorSnapping(numPoints, extent, snapRadius, profiles,
107107
baseUrl, maxAttempts);
108108
generator.generate();
109109
return generator;

ors-benchmark/src/test/java/org/heigit/ors/coordinates_generator/cli/SnappingCommandLineParserTest.java

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import org.heigit.ors.benchmark.exceptions.CommandLineParsingException;
44
import org.heigit.ors.coordinates_generator.generators.CoordinateGeneratorSnapping;
5+
import org.heigit.ors.coordinates_generator.service.CoordinateSnapper;
56
import org.junit.jupiter.api.Test;
67
import org.junit.jupiter.params.ParameterizedTest;
78
import org.junit.jupiter.params.provider.CsvSource;
89
import org.junit.jupiter.params.provider.ValueSource;
910

11+
import java.lang.reflect.Field;
12+
1013
import static org.junit.jupiter.api.Assertions.*;
1114

1215
class SnappingCommandLineParserTest {
@@ -17,8 +20,8 @@ void testValidCliArguments() {
1720
"-n", "100",
1821
"-e", "8.6,49.3,8.7,49.4",
1922
"-p", "driving-car,cycling-regular",
20-
"-r", "350",
21-
"-u", "http://localhost:8080/ors"
23+
"-sr", "350",
24+
"-u", "http://localhost:8080/ors"
2225
};
2326

2427
SnappingCommandLineParser cli = new SnappingCommandLineParser(args);
@@ -200,4 +203,55 @@ void testMaxAttempts() {
200203
// We're verifying that the CLI parser correctly reads the value and the
201204
// generator is created successfully
202205
}
206+
207+
@Test
208+
void testSnapRadius() {
209+
String[] args = {
210+
"-n", "100",
211+
"-e", "8.6 49.3 8.7 49.4",
212+
"-p", "driving-car",
213+
"-sr", "500"
214+
};
215+
216+
SnappingCommandLineParser cli = new SnappingCommandLineParser(args);
217+
CoordinateGeneratorSnapping generator = cli.createGenerator();
218+
assertNotNull(generator);
219+
220+
// Test snapRadius using reflection to verify it was correctly passed to the
221+
// coordinate snapper
222+
assertDoesNotThrow(() -> {
223+
Field coordinateSnapperField = CoordinateGeneratorSnapping.class.getDeclaredField("coordinateSnapper");
224+
coordinateSnapperField.setAccessible(true);
225+
CoordinateSnapper snapper = (CoordinateSnapper) coordinateSnapperField.get(generator);
226+
227+
Field snapRadiusField = CoordinateSnapper.class.getDeclaredField("snapRadius");
228+
snapRadiusField.setAccessible(true);
229+
assertEquals(500.0, snapRadiusField.getDouble(snapper), 0.001, "Snap radius should be set correctly");
230+
});
231+
}
232+
233+
@Test
234+
void testDefaultSnapRadius() {
235+
String[] args = {
236+
"-n", "100",
237+
"-e", "8.6 49.3 8.7 49.4",
238+
"-p", "driving-car"
239+
// No -sr parameter, should use default value
240+
};
241+
242+
SnappingCommandLineParser cli = new SnappingCommandLineParser(args);
243+
CoordinateGeneratorSnapping generator = cli.createGenerator();
244+
assertNotNull(generator);
245+
246+
// Test snapRadius using reflection to verify the default value was used
247+
assertDoesNotThrow(() -> {
248+
Field coordinateSnapperField = CoordinateGeneratorSnapping.class.getDeclaredField("coordinateSnapper");
249+
coordinateSnapperField.setAccessible(true);
250+
CoordinateSnapper snapper = (CoordinateSnapper) coordinateSnapperField.get(generator);
251+
252+
Field snapRadiusField = CoordinateSnapper.class.getDeclaredField("snapRadius");
253+
snapRadiusField.setAccessible(true);
254+
assertEquals(350.0, snapRadiusField.getDouble(snapper), 0.001, "Default snap radius should be 350");
255+
});
256+
}
203257
}

0 commit comments

Comments
 (0)