Skip to content

Commit fa993dd

Browse files
Merge pull request opentripplanner#7376 from ibi-group/datum
Make URL of NED datum configurable
2 parents 7ce859d + 0786ef1 commit fa993dd

4 files changed

Lines changed: 45 additions & 11 deletions

File tree

application/src/main/java/org/opentripplanner/graph_builder/module/configure/GraphBuilderModules.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,11 @@ private static ElevationGridCoverageFactory createNedElevationFactory(
380380
awsTileSource.awsSecretKey = config.elevationBucket.secretKey;
381381
awsTileSource.awsBucketName = config.elevationBucket.bucketName;
382382

383-
return new NEDGridCoverageFactoryImpl(nedCacheDirectory, awsTileSource);
383+
return new NEDGridCoverageFactoryImpl(
384+
nedCacheDirectory,
385+
config.elevationBucket.datumUrl,
386+
awsTileSource
387+
);
384388
}
385389

386390
private static List<ElevationGridCoverageFactory> createDemGeotiffGridCoverageFactories(

application/src/main/java/org/opentripplanner/graph_builder/module/ned/NEDGridCoverageFactoryImpl.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.FileOutputStream;
77
import java.io.IOException;
88
import java.io.OutputStream;
9+
import java.net.MalformedURLException;
10+
import java.net.URI;
911
import java.net.URL;
1012
import java.util.ArrayList;
1113
import java.util.List;
@@ -34,18 +36,19 @@ public class NEDGridCoverageFactoryImpl implements ElevationGridCoverageFactory
3436
"g2012u00.gtx",
3537
};
3638
private final File cacheDirectory;
37-
public final NEDTileSource tileSource;
39+
private final NEDTileSource tileSource;
3840
private final List<GridCoverage2D> regionCoverages = new ArrayList<>();
41+
private final URL datumUrl;
3942
private List<VerticalDatum> datums;
4043

41-
public NEDGridCoverageFactoryImpl(File cacheDirectory) {
42-
this.cacheDirectory = cacheDirectory;
43-
this.tileSource = new DegreeGridNEDTileSource();
44-
}
45-
46-
public NEDGridCoverageFactoryImpl(File cacheDirectory, NEDTileSource tileSource) {
44+
public NEDGridCoverageFactoryImpl(File cacheDirectory, URI datumUrl, NEDTileSource tileSource) {
4745
this.cacheDirectory = cacheDirectory;
4846
this.tileSource = tileSource;
47+
try {
48+
this.datumUrl = datumUrl.toURL();
49+
} catch (MalformedURLException e) {
50+
throw new RuntimeException(e);
51+
}
4952
}
5053

5154
/**
@@ -182,7 +185,6 @@ private void loadVerticalDatum() {
182185
*/
183186
private void fetchDatum() throws Exception {
184187
LOG.info("Attempting to fetch datum files from OTP project web server...");
185-
URL datumUrl = new URL("http://dev.opentripplanner.org/resources/datum.zip");
186188
ZipInputStream zis = new ZipInputStream(datumUrl.openStream());
187189
/* Silly boilerplate because Java has no simple unzip-to-directory function. */
188190
for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) {

application/src/main/java/org/opentripplanner/standalone/config/buildconfig/S3BucketConfig.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.opentripplanner.standalone.config.buildconfig;
22

33
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.NA;
4+
import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_9;
45

6+
import java.net.URI;
57
import org.opentripplanner.framework.application.OtpAppException;
68
import org.opentripplanner.standalone.config.framework.json.NodeAdapter;
79
import org.slf4j.Logger;
@@ -18,6 +20,7 @@ public class S3BucketConfig {
1820
public String accessKey;
1921
public String secretKey;
2022
public String bucketName;
23+
public URI datumUrl;
2124

2225
public static S3BucketConfig fromConfig(NodeAdapter root, String elevationBucketName) {
2326
return fromConfig(
@@ -73,6 +76,24 @@ public static S3BucketConfig fromConfig(NodeAdapter config) {
7376
.since(NA)
7477
.summary("The bucket from which you want to download.")
7578
.asString();
79+
bucketConfig.datumUrl = config
80+
.of("datumUrl")
81+
.since(V2_9)
82+
.summary("HTTP URL of the vertical datum zip file.")
83+
.summary(
84+
"""
85+
URL of the vertical datum zip file which is necessary to convert the
86+
[USGS elevation data](https://www.usgs.gov/programs/national-geospatial-program/national-map)
87+
from North American Vertical Datum of 1988 (NAVD88) to WGS84 format that OpenStreetMap
88+
(and GPS) uses.
89+
90+
The OTP project used to host these files and hard-code the URL. In 2026 we made the decision
91+
to require users to host this file themselves.
92+
93+
If you would like to get a copy of the file, please ask in our chat room.
94+
"""
95+
)
96+
.asUri();
7697
} catch (OtpAppException ex) {
7798
LOG.error(
7899
"You must specify an accessKey, a secretKey, and a bucketName when " +

application/src/test/java/org/opentripplanner/graph_builder/module/ElevationModuleTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import static org.junit.jupiter.api.Assertions.assertNotNull;
55

66
import java.io.File;
7+
import java.net.URI;
8+
import java.net.URISyntaxException;
79
import org.junit.jupiter.api.Disabled;
810
import org.junit.jupiter.api.Test;
911
import org.locationtech.jts.geom.Coordinate;
@@ -31,7 +33,7 @@ public class ElevationModuleTest {
3133
*/
3234
@Test
3335
@Disabled
34-
public void testSetElevationOnEdgesUsingS3BucketTiles() {
36+
public void testSetElevationOnEdgesUsingS3BucketTiles() throws URISyntaxException {
3537
// create a graph with a StreetWithElevationEdge
3638
var graph = new Graph();
3739
OsmVertex from = new OsmVertex(-122.6932051, 45.5122964, 40513757);
@@ -92,7 +94,12 @@ public void testSetElevationOnEdgesUsingS3BucketTiles() {
9294
// create the elevation module
9395
File cacheDirectory = new File(ElevationModuleTest.class.getResource("ned").getFile());
9496
DegreeGridNEDTileSource awsTileSource = new DegreeGridNEDTileSource();
95-
NEDGridCoverageFactoryImpl gcf = new NEDGridCoverageFactoryImpl(cacheDirectory, awsTileSource);
97+
var datumUrl = new URI("https://example.com");
98+
NEDGridCoverageFactoryImpl gcf = new NEDGridCoverageFactoryImpl(
99+
cacheDirectory,
100+
datumUrl,
101+
awsTileSource
102+
);
96103
ElevationModule elevationModule = new ElevationModule(gcf, graph);
97104

98105
// build to graph to execute the elevation module

0 commit comments

Comments
 (0)