Elevation data from local files

Assuming I have DEM data in a format like SRTM or CGIAR locally on my server (if it
is not in the right format I can make it so hopefully), can I point GH to use it instead of downloading the data?

I’m asking this question since I have data from aster which has a better
resolution compared to the above two. The original data is noisy but
some one very smart was able to clean it for me and now I have far
better DEM data.

I want to use this data for GH, is it possible?

That should be possible with some modifications if its not the same format. So either convert the aster files into SRTM or CGIAR format or implement a new ElevationProvider which should not be hard if you know a bit java and it would be very appreciated if contributed back!

See here for the relevant source package and here for the tests.

The original data is noisy but some one very smart was able to clean it for me and now I have far better DEM data.

Nice, would you mind asking him if he can reach out to us :slight_smile: ?

Thanks for the quick response, I’ll ask him to reach out but don’t get your hopes up.
While I can probably write a relevant provider I think the environment setup will take more time than what I have to spare right now.
My question was specific for local files. when setting the provider to srtm or cgiar the only parameters I can change as far as I understand from the documentation is base url and the type of DEM data (srtm or cgiar).
What is more interesting for me is if I can set somehow the provider to use a folder instead of going online and downloading the files.
will the cache folder do in case there are files in it - I mean if I set the cache folder to a specific location and place the DEM files there will GH take these files instead of downloading?

Yes, if the naming of the files is properly then the cache folder does exactly this.

Thanks! I’ll give it a try tonight hopefully.


I have ran the server with the cache and everything is working as expected.
My question regarding the cache is as follow:
I see that the files in the cache folder are in their zip format.
Please let me know if my assumption is correct:
The files are unzipped and loaded to memory on start up, right?
This means that I can place different zip files with the appropriate names before I start the service and GH will unzip them and use my custom files.
I’ll have a hard time testing that this truely works so I prefer to ask.
Harel M.

For the import that should be true, yes. But on a load without import GraphHopper just uses its own data.

Ok, So I need to make GH refresh its data.
Is there a way to do it besides deleting the created folder (the one with all the GH data)?
Can I do it from the command line? some sort of parameter to the jar file?

See the method graphHopper.clean() or just via command line

Not sure I understand how to use the clean method.
I’m running it on windows using the following command line:
java -jar *.jar jetty.resourcebase=webapp config=config-example.properties osmreader.osm=berlin-latest.osm.pbf
Can I tell GH using the above command to refresh? maybe using the config? or adding another parameter.
I’m asking mainly because we update the pbf file once a week and I’d like to automate this process as well…

Currently there is no parameter to pass to the java process, the clean method would be one which you call if you use GraphHopper in your java application. You could create an issue to implement this and/or just remove the folder via command line to force a fresh import

Ok, I’ll just delete the folder then.
You are free to add an issue if this is something you are interested in developing :slight_smile: I think I can live with the current workaround.

Ok, So I placed everything as it should be in the zip files.
Placed the zip files in the cache folder.
deleted gh folder and ran the server again.
Then I used it for routing and asked for the elevation data as well.
I think something is not working with the elevation…
Below is an image with the elevation graph for a small routing (9 points).
A possible problem might be that I’m using 1arc resolution files with 3arc resolution hgt files in the cache folder.
I have written a small elevation service of my own using the same hgt files so I know that the resulting elevation from the routing is incorrect.
Is there any data I can send that can help find the issue?
I know I can remove the elevation data and just use my elevation server, but that will render the bike2 profile useless and I was really looking forward to using it.
Thanks ahead,

As I said earlier: if the format is different like it is in your case due to the resolution we will need to implement this in GraphHopper (It shouldn’t be hard to do so) or you’ll have to convert them up front.

If you want to point me to the relevant location in the code I can take a look and maybe submit a pull request.
Here is the code I use which is resolution independent, I found it also to be very memory efficient relative to previous data structures I used, It uses some of .Net goodies but I assume it can be easily converted to Java.

You probably have to implement a new ElevationProvider, see the dem package and the tests.

How did you conceptionally make it resolution independent? Or do you mean if the data knows the resolution up front it can handle it?

Data structure-wise I think we use a similar technique: a hashmap (Dictionary) to store the short arrays, in our case that is the HeightTile which is a DataAccess storage, where we can use the short elevation data in-memory or memory mapped, which is important for world wide import.

Since SRTM does support more than one resolution (new SRTM is 1 arc while old is 3 arc) I think the code should be in SRTMProvider.

Looking at the code you are setting the width of the tile to be 1201 samples.
My assumptions is that the data is in a square format (meaning there will be same number of smaples both for height and width).
Using this assumption I can read the total number of bytes in the file, divide it by 2 in order to get the total number of samples and use sqrt to get the number of samples for both dimentions.

This is the relevant line of code:
int samples = (int)(Math.Sqrt(byteArray.Length / 2) + 0.5);
instead of using WIDTH = 1201

I think that all you need to do in the code is create the instance of HeightTile after you unzip the file so that you know how many bytes are in the file.

Again, I would love to do it but I think that setting up the environment will require too much effort from my side.

Do you want me to create an issue in github so I’ll be able to test it once it’s implemented?

Thanks, would you try if such a code change works for you? You just need to modify the sources, call ./graphhopper.sh clean and it’ll use the modification.

Again, I would love to do it but I think that setting up the environment will require too much effort from my side.

it should not be that complex :slight_smile:

Yes, feel free to create an issue for this

Took me 3 hours to set everything up, not sure it was really worth it…
Never mind me, just blowing off some steams.
I have change the code and ran the tests to make sure I didn’t broke any thing.
Unfortunately it looks like the DataAccess object that is used to keep the heights does not tell me the number of bytes in it - which I need in order to be resolution independent.
Should I be using a different data structure or save the total size/number of samples in the first byte?
Not sure how to continue here… I’m also not that experienced with Java judging from the google time I’ve just spent…
Also not sure that what I did is backwards compatible but you’ll have to review it anyway before you pull it…

The DataAccess concrete class is MMAPDataAccess, I was hoping to get the number of bytes from the capacity but since the segments size is a power of two the capacity is bigger than the original buffer that was used.
Any thoughts?