waymarkedtrails / waymarked-trails-site

Main repository for issue tracking and discussions for waymarkedetrails
http://waymarkedtrails.org
GNU General Public License v3.0
110 stars 24 forks source link

GPX with elevation data #306

Open carlos-mg89 opened 5 years ago

carlos-mg89 commented 5 years ago

Hi!

Is there a way to obtain the GPX files with the elevation included? I've seen in a few issues here that you talk about the elevation, but I haven't found a way of obtaining it in GPX or GeoJson fils.

Thanks in advance

carlos-mg89 commented 5 years ago

I've been checking the code of the GPX generation, and it doesn't seem to be possible to obtain the elevation parameter along with the GPX (although it's allowed in the standard as far as I know).

I was checking the Installation wiki ( https://github.com/waymarkedtrails/waymarked-trails-site/wiki/Installation ) and at the bottom it appears information to include the elevation information.

I have installed the requirements:

apt-get install python-gdal python-scipy python-pyproj
pip install geojson

And then I have added in my config/local.py the following line: SHOW_ELEV_PROFILE = True

Right after this, I dropped my DB (which was running) and run the following commands to re-import the data, along with the elevation data:

Everything went OK except the import (./makedb.py hiking import), where I got some errors:

19-01-07 22:40:10 Importing changed_objects...
19-01-07 22:40:10 Importing segments...
19-01-07 22:40:26 Processing relation 5076 (0 %)
19-01-07 22:41:56 Processing relation 275004 (1 %)
19-01-07 23:15:59 Processing relation 8785486 (99 %)
19-01-07 23:16:13 Importing hierarchy...
19-01-07 23:16:14 Importing routes...
19-01-07 23:22:45 Importing defstyle...
19-01-07 23:23:28 Importing guideposts...
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
psycopg2.InternalError: Input geometry has unknown (0) SRID

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./makedb.py", line 165, in <module>
    getattr(mapdb, 'construct')()
  File "/usr/local/lib/python3.6/dist-packages/osgende/mapdb.py", line 90, in construct
    tab.construct(self.engine)
  File "/usr/local/lib/python3.6/dist-packages/osgende/subtable.py", line 51, in construct
    self.insert_objects(engine, self.src.select_all(self.subset))
  File "/usr/local/lib/python3.6/dist-packages/osgende/subtable.py", line 90, in insert_objects
    workers.add_task(obj)
  File "/usr/local/lib/python3.6/dist-packages/osgende/nodes/nodes.py", line 83, in _process_next
    self.thread.compiled_insert.execute(tags)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/sql/compiler.py", line 243, in execute
    return e._execute_compiled(self, multiparams, params)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 1032, in _execute_compiled
    compiled, parameters
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
    context)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 1341, in _handle_dbapi_exception
    exc_info
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/util/compat.py", line 188, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=exc_value)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/util/compat.py", line 181, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
    context)
  File "/usr/local/lib/python3.6/dist-packages/sqlalchemy/engine/default.py", line 450, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.InternalError: (psycopg2.InternalError) Input geometry has unknown (0) SRID
 [SQL: 'INSERT INTO hiking.guideposts (id, name, ele, geom) VALUES (%(id)s, %(name)s, %(ele)s, ST_Transform(ST_GeomFromEWKT(%(geom)s), %(param_1)s)) RETURNING hiking.guideposts.id'] [parameters: {'id': 26022481, 'name': None, 'ele': None, 'geom': '0101000000520dfb3db1cefebfdbc93be2eb2a4540', 'param_1': 3857}]
19-01-07 23:23:29 Used memory by index: 47871842424

So basically I'm stuck here. If I try to get the info of a relation, I obtain the same data I obtained before.

E.g.: http://localhost:8080/api/details/relation/2163937

However, if I try to get it's elevation (here /api/details/relation/2163936/elevation ) I get this error, related with the elevation data being missing/incomplete:

127.0.0.1 - - [08/Jan/2019:08:33:53] "GET /api/details/relation/2163936/elevation HTTP/1.1" 500 1950 "" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0"
ERROR 4: /home/carlos/workspace/waymarked-trails-site/dem/900913/earth.vrt: No such file or directory
[08/Jan/2019:08:33:59] HTTP 
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cprequest.py", line 670, in respond
    response.body = self.handler()
  File "/usr/local/lib/python3.6/dist-packages/cherrypy/lib/encoding.py", line 217, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/cherrypy/lib/jsontools.py", line 63, in json_handler
    value = cherrypy.serving.request._json_inner_handler(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/cherrypy/_cpdispatch.py", line 61, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/home/carlos/workspace/waymarked-trails-site/api/details.py", line 343, in elevation
    compute_elevation(((xcoord, ycoord, pos), ), geom.bounds, ret)
  File "/home/carlos/workspace/waymarked-trails-site/api/elevation.py", line 33, in compute_elevation
    dem = Dem(config.defaults.DEM_FILE)
  File "/home/carlos/workspace/waymarked-trails-site/api/elevation.py", line 127, in __init__
    self.transform = self.source.GetGeoTransform()
AttributeError: 'NoneType' object has no attribute 'GetGeoTransform'

I didn't fully understand the Wiki link about the elevation profile preparation: https://github.com/waymarkedtrails/waymarked-trails-site/wiki/Elevation-profile-preparation . It seems that I have to manually download the DEM data. But I don't really know where and what to download.

Anyone could help me with this please? Perhaps @lonvia ?

lonvia commented 5 years ago

GPX or GeoJSON files do not contain elevation but if you are running your own instance, it should be fairly straightforward to add the information. elevation.py shows how to obtain the elevation points.

The elevation data is not part of the database. They are supposed to be in GDAL files somewhere on your hard disk. You have to download the data. I've updated the links to ASTER and SRTM. SRTM void-filled is liekly a good option these days and unproblematic licensewise.

The SRID(0) problem is unrelated to the elevation/ Looks more like a configuration issue.

carlos-mg89 commented 5 years ago

@lonvia I was checking the links SRTM and ASTER, and it seems easy to download the ASTER ones. However, being this the 2nd time (I did check at the SRTM link before writing this issue) I check the SRTM link, it seems unclear to me what do I have to download.

It's clear they are TIFF files. And I already got them on my GraphHopper instance (which happens to be taking the same osm.pbf, so it should be fine to take those TIFFs). The zip that contain the TIFFs have a naming like srtm_30_05.zip and they contain the following files:

So, do I have to extract all those zips, that are related to my OSM.PBF, and then run: gdalwarp -s_srs EPSG:4326 -t_srs EPSG:900913 old.tif new.tif for each of them

And right after, run:

ls -1 *.tif > tiff_list.txt
gdal_merge.py -v -o merged_image.tif --optfile tiff_list.txt
gdalbuildvrt DEM.vrt *.tif

If I get the DEM.vrt file, that doesn't seem to match the file that appears on my current error when I visit the /elevation endpoint: ERROR 4: /home/carlos/workspace/waymarked-trails-site/dem/900913/earth.vrt: No such file or directory

Should I store on that folder, and with that name the DEM.vrt?

Sorry for all these questions, but is not clear to me :(

carlos-mg89 commented 5 years ago

I've tried running gdalwarp -s_srs EPSG:4326 -t_srs EPSG:900913 srtm_35_01.tif new_srtm_35_01.tif but it throws an error:

ERROR 6: EPSG PCS/GCS code 900913 not found in EPSG support files.  Is this a valid EPSG coordinate system?
ERROR 1: Translating source or target SRS failed:
EPSG:900913