Skip to content

Added Elevation data to OSMReader - #83

Closed
NopMap wants to merge 13 commits into
masterfrom
elevation_data
Closed

NopMap wants to merge 13 commits into
masterfrom
elevation_data

Conversation

@NopMap

@NopMap NopMap commented Jul 5, 2013

Copy link
Copy Markdown
Contributor

3D mode is activated by setting a path to/for the DEM data with OSMReader.setDemLocation()
The required DEM files are downloaded automatically for the bounds of the OSM file.
In 3D mode each node is assigned its elevation value before the ways are processed.

With normal encoders, the elevation difference is included in the edge distance calculation.
Elevation sensitive encoders can use the ElevationAnalyzer class to set parameters according to elevation difference or incline.
The class BikeTwoSpeedFlagEncoder is a bike encoder with two speeds for forward/backward which are modified depending on incline/decline. It can be activated in the configuration file like this
osmreader.acceptWay=BIKE,BIKE3D:com.graphhopper.routing.util.BikeTwoSpeedFlagEncoder

DEM handling needs a lot of memory (72MB for each 5°x5° area tile). It's prepared to scale to larger areas but that's not implemented yet.

If 3D mode is not activated, no additional memory is used.

Enables GH for #43

@karussell

Copy link
Copy Markdown
Member

Thanks! How can I try this and download a simple DEM file for my location?

Will also pure srtm files work? Or only cgiar?

@NopMap

NopMap commented Jul 6, 2013

Copy link
Copy Markdown
Contributor Author

The required DEM files are downloaded automatically for the bounds of the OSM file. CGIAR only.

@karussell

Copy link
Copy Markdown
Member

Ok, I just needed to specify the location for the DEM files - nice! And really nice work!

When downloading several problems could happen (network problems, out of memory errors, ...) so that the import process has to be run again and again. I would like to separate download from import somehow. So instead of putting DEM handling inside the OSMReader (which makes things there even more complicated) we have to put it into a post processing step, which would also reduce the maximum necessary RAM as no import data structures has to be hold in memory at the same time. Or why did you need it there? Additionally we then could process the graph tile by tile which would make the DEM import more scalable.

Some more todos for us:

  • we need more unit tests for the basic things
  • we have to move this DEM processing into a separate import-dem module to separate the proprietary jai from GraphHopper. Or can we somehow avoid this jar?
  • the default of the dem location should be graph-storage/dem/ -> how could be specify this? e.g. osmreader.demlocation=<default> ?
  • license header is missing for new files

@NopMap

NopMap commented Jul 8, 2013

Copy link
Copy Markdown
Contributor Author

When downloading several problems could happen (network problems, out of memory errors, ...) so that the import process has to be run again and again. I would like to separate download from import somehow. So instead of putting DEM handling inside the OSMReader (which makes things there even more complicated) we have to put it into a post processing step

Postprocessing does not work. The required order is:

  1. node processing, the bounds for the elevation processing are taken from the graph
  2. elevation download for this area if it is missing
  3. way processing. The Flag encoders need the elevation information to use it in the encoding

The only way to seperate this would be to build a DEM download module that runs before the OSMReader to make sure all DEM data is already there. Disadvantages

  • you have to know and manually enter the bounds
  • if you do not run the prefetch or get the bounds wrong, it is still possible that the DEM is missing. Then you would still need to download it on demand or throw an exception.

Adding an optional DEM prefetch sounds ok, but downloading on demand ist the easiest way if it works.

@karussell

Copy link
Copy Markdown
Member
  1. way processing. The Flag encoders need the elevation information to use it in the encoding

Yes. true. But can we somehow making it possible? I'm thinking more about this: calculating 'important' flags on the osm import. Then for the post processing: enhance or set the final flags. I've have to think about the separation (very hard!) but we should really separate this! Also for the future it is very important that we don't increase the complexity and memory usage of the import process.

@NopMap

NopMap commented Jul 8, 2013

Copy link
Copy Markdown
Contributor Author

I disagree.

  • Separating the encoding in some things that are done in the second pass and other things that are done in a third pass will make the import more complex not less as they are interdependent and you need to take care which operation is allowed in the second pass and which is not.
  • The memory consumption for the third pass will be the same as it is for the second pass now, you need the graph, elevations and geometry all at the same time. If you need to store information from the second pass for the third one, memory consumption increases.

In my opinion we should rather use efficient file-backed data structures so the import will run with about any amount of memory and can be supported by using an SSD for the files.

@karussell

Copy link
Copy Markdown
Member

and you need to take care which operation is allowed in the second pass and which is not

we just need to create some (additional) post processing of the graph. not of the OSM file. see below.

The memory consumption for the third pass will be the same

We don't need the big longlongmap when OSM import is finished. so this would save us lots of GB memory for the full planet scenario.

If you need to store information from the second pass for the third one, memory consumption increases.

There is no third pass of OSM file. it is just as we do with subnetwork removal: we use the data already present in the graph and traverse the graph + improving/setting speed values from elevation data.

What other data do we need besides the GPS coordinate?

will make the import more complex not less

My fear is just that with every feature request we increase the number of necessary parameters in methods like handleWayTags, addOSMWay, ... so instead I would rather introduce some sort of separation - be it a for-loop in the OSM import or a post-processing chain

In my opinion we should rather use efficient file-backed data structure

This will be an additional task, yes. but as this DEM import is possible IMO without a higher memory usage we should concentrate on this as using file-backed data structure will decrease the import speed a lot.

@NopMap

NopMap commented Jul 8, 2013

Copy link
Copy Markdown
Contributor Author

If you need to store information from the second pass for the third one, memory consumption increases.
There is no third pass of OSM file. it is just as we do with subnetwork removal: we use the data already present in the graph and traverse the graph + improving/setting speed values from elevation data.
What other data do we need besides the GPS coordinate?

The OSM tags. :-)

What I am planning needs a combination of several OSM tags (highway, tracktype, surface, sac_scale) and the incline of the way to decided on the flags. Upward has a much higher speed than downwards, and the continuity of the incline can modify this too.
The BikeTwoSpeedEncoder is a fairly simple example, but even there we could implement some more intelligent downhill speed calculation - at the moment it just assumes that you can let your bike roll the same on any sort of ground.

You can't do this with the graph only. You would have to make throwaway flags to encode way type information you never need for routing, just to use it as input in the elevation calculations.

I don't want the reader needlessly complex either. Thats the reason why I built GeometryAccess so you don't have to know how the reader and graph store their data to write an encoder. But separating things that belong together is not helpful. To write really intelligent Encoders you need all tags, relations and elevation at the same time.

@karussell

Copy link
Copy Markdown
Member

What I am planning needs a combination of several OSM tags (highway, tracktype, surface, sac_scale)
and the incline of the way to decided on the flags.

ah, ok. Of course then this isn't (easily) possible with a post processing step!

To write really intelligent Encoders you need all tags, relations and elevation at the same time.

Hmmh, the only thing I don't like is the very suboptimal access of elevation data. If we could somehow traverse the graph more like it is structured then a file based approach to access this elevation data wouldn't be that slow I guess ...

@karussell

Copy link
Copy Markdown
Member

Ok, going on here since some time ... I found a replacement called Apache xmlgraphics for JAI which has a better license and offers exactly the same classes as JAI (SeekableStream, TIFFDecodeParam, TIFFImageDecoder). I have the following plan to integrate this pull request:

  1. fetch DEM data (via interface) store it on disc or in-memory**. I'll create the first implementation via NASA SRTM data set as start. I wasn't able to get a license for the cgiar stuff (even after several email requests, not sure why they don't respond). But this make no sense for others too if they reply this way. If you implement the cgiar stuff just make sure you use the Apache XMLGraphics project.
  2. Change graph due to height information. Make this configurable. If height should be stored for every edge or node separately (so one could retrieve it later per request) or if it should just influence the speed and distance.
  3. make use of height information in the Weighting
  4. make it working for CH too, create two edges if there are two different weights
  5. Optionally improve data via OpenStreetMap GPX or ele tag information. See this idea

** As a side note: it is not necessary to extend LongLongMap (OsmNodeTranslation) because instead of storing the elevation data in the map it it a lot easier to reserve additionally two bytes in the DataAccess object node or just a temporary DataAccess object which can be accessed via tower node index.

In order to make it working I would really appreciate your help (e.g. see below) as I cannot just merge this code. For that I'll create a new dem_data branch with as many possible code as possible, of course.

I need to understand some more parts:

@NopMap

NopMap commented Jan 22, 2014

Copy link
Copy Markdown
Contributor Author

Ok, going on here since some time ... I found a replacement called Apache xmlgraphics for JAI which has a better license and offers exactly the same classes as JAI (SeekableStream, TIFFDecodeParam, TIFFImageDecoder).

Cool, then it should be directly exchangable.

fetch DEM data (via interface) store it on disc or in-memory**. I'll create the first implementation via NASA SRTM data set as start. I wasn't able to get a license for the cgiar stuff (even after several email requests, not sure why they don't respond). But this make no sense for others too if they reply this way.

Again: You do not need a licence. It is ok for everybody to use the CGIAR data for their own purposes. It is probably ok to evaluate the data. It is ok to redistribute the dataset for free. It is just not ok to redistribute the original dataset commercially.

If you want to use SRTM data please keep in mind:

If we have different datasets we need a configuration for the type of datasource and a factory pattern to instantiate the right tile class.

If you implement the cgiar stuff just make sure you use the Apache XMLGraphics project.

What do you mean? The CGIAR classes are already implemented in the pull request. Do you want to merge them on a different branch?

@NopMap

NopMap commented Jan 22, 2014

Copy link
Copy Markdown
Contributor Author

Optionally improve data via OpenStreetMap GPX or ele tag information. See this idea

The data from the ele tags is worthless and should not be used

  1. The reference system for ele in the OSM wiki has been redefined after some years to a very technical system, completely unexpected and incomprehensible to the ordinary mapper. There is consent that most people are not aware of this or ignore it, but some do regard it. As a result, you have no idea what an ele value actually means.
    (http://forum.openstreetmap.org/viewtopic.php?id=21009)
  2. They are just punctual values and do not match the SRTM data. For routing, the absolute elevation is unimportant, but you need a continuous elevation difference with the same reference system.

@NopMap

NopMap commented Jan 22, 2014

Copy link
Copy Markdown
Contributor Author

I need to understand some more parts:

What is this line doing? osmNodeTranslation.copyNode(nodeId, id, OSMReaderHelper.TOWER_NODE); https://github.com/graphhopper/graphhopper/pull/83/files#diff-5cab8f66bb340fdb3ff6074135118769R367

Took me a while - I have written that code 7 months ago and never had to look at it again. :-)

After you split a node into two to introduce a barrier edge it is necessary to also copy the elevation stored with the original node into the new node. That is what this line does after creating the node. If you change the location of the elevations to a dataAccess you will have to do something similar in that structure.

I did it this way to avoid adding an elevation parameter to all node creation and node handling functions which would make them more complex even if you are not using elevations at all.

Would you give a short description of GeometryAccess and why we need it in the FlagEncoders & EncodingManager

GeometryAccess encapsulates the actual storage locations of nodes and elevations and hides them from the Encoders. This way the Encoders do not need to know where and how the geometry is stored, they just request nodes and elevations and analyze them.

I found the access to geometry pretty cumbersome with the distinction of tower and pillar nodes, the index calculations and elevations from yet another location. Without GeometryAccess, you would have to duplicate all that code in every Encoder that needs to anlayze elevations or geometry e.g. to determine whether a road is straigt or has narrow bends.

@NopMap

NopMap commented Jan 23, 2014

Copy link
Copy Markdown
Contributor Author

** As a side note: it is not necessary to extend LongLongMap (OsmNodeTranslation) because instead of storing the elevation data in the map it it a lot easier to reserve additionally two bytes in the DataAccess object node or just a temporary DataAccess object which can be accessed via tower node index.

The elevations are required for ALL nodes, not just for tower nodes. But if you find a better way to store them temporarily that's great.

Do you plan to integrate the actual use of DEM data too or should that be a different step? There is an important change in the encoders. I introduced a second phase to the encoding. The first phase evaluates the OSM tags for the OSM way as usual. The second phase evaluates the elevations/geometry for each edge and completes the flags. This is important, evaluating elevations for the whole OSM way does not work, the evaluation is different for each edge.

I go even further and subdivide every edge longer than 100 meters for the analysis. Experiments showed that there are quite a number of long roads or tracks that run over a hill or through a valley with no intersections. If you just look at the elevations of start or end you would miss the hill/valley completely. I have designed it to be optional, controlled by the queryNeeds() function as it requires the DEM model to be present for the whole import.

@karussell

Copy link
Copy Markdown
Member

It is just not ok to redistribute the original dataset commercially

I'm not a lawyer but they (and you) say not for commercial purposes - how to define this? I think this is a gray area and I don't want to invest time there. But as you have it already implemented. Nothing is wrong with integrating it as one implementation.

That is what this line does after creating the node

ok

I found the access to geometry pretty cumbersome with the distinction of tower and pillar nodes

Indeed it is cumbersome and ugly. I'll have to think about if we can somehow avoid this in the encoders and e.g. 'enhance' the OSMWay or OSMNode object to provide this information in an easier 'fashion'.

The data from the ele tags is worthless and should not be used

ah, ok. Yes, you told me already but I thought it was only because the data is only punctual available. Now with the gaussian method this was interesting again for me. But the inconsistency is a bad thing.

If you want to use SRTM data please keep in mind:

ok, thanks. I'll investigate.

Do you want to merge them on a different branch?

No, in the same branch. But it should be done from you :) (?)

Do you plan to integrate the actual use of DEM data too or should that be a different step?

I think, yes for the branch but not at the beginning probably.

I go even further and subdivide every edge longer than 100 meters for the analysis.

Thanks! I'll also have a look into it!

@NopMap

NopMap commented Jan 23, 2014

Copy link
Copy Markdown
Contributor Author
I found the access to geometry pretty cumbersome with the distinction of tower and pillar nodes

Indeed it is cumbersome and ugly. I'll have to think about if we can somehow avoid this in the encoders and e.g. 'enhance' the OSMWay or OSMNode object to provide this information in an easier 'fashion'.

Well, I think GeometryAccess is already pretty simple. Adding it to the OSM stuff ist not really logical as the elevations are not related to the OSMNodes and you can have interpolated or derived Geometry that does not correspond to an OSMNode at all, but you still might need to get an Elevation value for it.

@NopMap

NopMap commented Jan 23, 2014

Copy link
Copy Markdown
Contributor Author
Do you want to merge them on a different branch?

No, in the same branch. But it should be done from you :) (?)

No problem. But then we should discuss the common wrapper and DEMTile factory before.

@NopMap

NopMap commented Jan 23, 2014

Copy link
Copy Markdown
Contributor Author
It is just not ok to redistribute the original dataset commercially

I'm not a lawyer but they (and you) say not for commercial purposes - how to define this?

You do not need to. The key word is "original dataset". If you just use the data for calculations or extract a few locations, you are not redistributing the original dataset and it cannot be reconstructed from the excerpts. The licence is not aggressive or virulent like many others.

@karussell

Copy link
Copy Markdown
Member

@karussell

Copy link
Copy Markdown
Member

@NopMap

NopMap commented Jan 24, 2014

Copy link
Copy Markdown
Contributor Author

Do you know this data source/merge thing: http://www.viewfinderpanoramas.org/dem3.html

Yes. Never used it due to licencing terms and heterogenous data (better in some areas, unavailable in others).

@karussell

Copy link
Copy Markdown
Member

I'm doing development in the branch dim3, there is still a bug. But it already works. Current status:

elevation

Change graph due to height information.

This is now implemented although we should provide an option if the elevation data should only influence speed and distances or if it should be available on response as well (which means it is necessary to store the elevation info per node)

make use of height information in the Weighting

This can be used now, but not implemented.

make it working for CH too, create two edges if there are two different weights

This should work now

SRTM data contains holes with no data (values of -32767) They can be quite
large gaps in the mountains. You need to interpolate to close those gaps

Yeah, that is really ugly and occurs relative often. But a floodfilling algorithm should not be that hard though.

@NopMap Or maybe you can adapt your existing CGIAR import? The good news is that those guys have now allowed usage of their data for GraphHopper! http://graphhopper.com/public/license/CGIAR.txt

Please give me feedback and ask me if you have questions!

@ghost

ghost commented Feb 19, 2014

Copy link
Copy Markdown

Hi Peter,
please not that Phyghtmap uses corrections by viewfinderpanoramas where
available as well as both 1 arc second SRTM (available for US) and 3 arc
second precision.

They also have a plotting tool can be used to create a height map for a
route, this is very nice to have for both biking and pedestrian routes,
where route preference can be based on ascend/descend.

See http://katze.tfiu.de/projects/phyghtmap/phyghtmap.1.html

Best regards,

Raphael

PS: Will try out that branch on the weekend

On Wed, Feb 19, 2014 at 12:34 PM, Peter [email protected] wrote:

I'm doing development in the branch dim3, there is still a bug. But it
already works. Current status:

[image: elevation]https://f.cloud.github.com/assets/129644/2205941/611dd796-9958-11e3-901b-ae8056c9c839.png

Change graph due to height information.

This is now implemented although we should provide an option if the
elevation data should only influence speed and distances or if it should be
available on response as well (which means it is necessary to store the
elevation info per node)

make use of height information in the Weighting

This can be used now, but not implemented.

make it working for CH too, create two edges if there are two different
weights

This should work now

SRTM data contains holes with no data (values of -32767) They can be quite
large gaps in the mountains. You need to interpolate to close those gaps

Yeah, that is really ugly and occurs relative often. But a floodfilling
algorithm should not be that hard though.

@NopMap https://github.com/NopMap Or maybe you can adapt your existing
CGIAR import? The good news is that those guys have now allowed usage of
their data for GraphHopper!
http://graphhopper.com/public/license/CGIAR.txt

Please give me feedback and ask me if you have questions!

Reply to this email directly or view it on GitHubhttps://github.com//pull/83#issuecomment-35489472
.

@karussell

Copy link
Copy Markdown
Member

Phyghtmap uses corrections by viewfinderpanoramas

As discussed earlier. We won't use this due to the unclear license. Of course, you could go and implement a new ElevationProvider ...

They also have a plotting tool can be used to create a height map for a route

What do you mean with this? We don't plot maps or overlays with GraphHopper or what use case did you have in mind? Or do you mean to use it as it fills the voids?

where route preference can be based on ascend/descend.

This can be easily implemented now. After fixing some bugs I'll indeed use the BikeWeighting (provided by @NopMap) to achieve exactly this.

@ghost

ghost commented Feb 19, 2014

Copy link
Copy Markdown

Hi Peter answers inline below

On Wednesday, February 19, 2014, Peter [email protected] wrote:

Phyghtmap uses corrections by viewfinderpanoramas

As discussed earlier. We won't use this due to the unclear license.

Just write to Jonathan de Ferranti, it's handauthored and he was fine with
it in our case similar to CGIAR

They also have a plotting tool can be used to create a height map for a
route

What do you mean with this? We don't plot maps or overlays with
GraphHopper or what use case did you have in mind? Or do you mean to use it
as it fills the voids?

This was intended for incorporation in the WAR code, you could. Plot the
heights of the route as done in many track sharing sites such as GPSies

where route preference can be based on ascend/descend.

This can be easily implemented now. After fixing some bugs I'll indeed
use the BikeWeighting (provided by @NopMap) to achieve exactly this.

Related to this please consider my prior note on preprocessing relations
and copying the biking lane attribute to ways to give dedicated biking ways
a preference.

Reply to this email directly or view it on GitHub.

Prof. Dr. Raphael Volz
Vorsitzender des Aufsichtsrats
chairman of the board

Volz Innovation GmbH
Kirchhaldenweg 10, 76597 Loffenau, Germany

Web: www.volzinnovation.com
Phone: +49 7083 9328338
Fax: +49 7083 9328337

Company Seat / Sitz der Gesellschaft: Loffenau
Company Register / Handelsregisternummer: HRB 704418, Amtsgericht Mannheim
Managing Director / Geschäftsführer: Dr. Sara Brockmans
Chairperson of the Supervisory Board / Vorsitzender des Aufsichtsrats:
Prof. Dr. Raphael Volz

@karussell

Copy link
Copy Markdown
Member

This was intended for incorporation in the WAR code, you could.
Plot the heights of the route as done in many track sharing sites such as GPSies

We can already do this in dim3. See my screenshot above where the elevation data is plotted everytime a new route is calculated.

Related to this please consider my prior note on preprocessing relations
and copying the biking lane attribute to ways to give dedicated biking ways a preference.

We already consider bike routes and prefer them via giving them higher speed (ugly workaround). In a later version a better solution can be implemented though.

@karussell

Copy link
Copy Markdown
Member

I'm closing this in favor of #169 - a lot thanks to @NopMap ! Let me know if you find the speed calculation okayish (done in Bike2WeightFlagEncoder). The CGIAR would be still nice to have!

@karussell karussell closed this Mar 18, 2014
@karussell
karussell deleted the elevation_data branch January 20, 2015 16:09
karussell added a commit that referenced this pull request Apr 11, 2018
Penalize inner-link U-turns (builds on #83)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants