adamcharnock / python-srtm

Python API for reading NASA's SRTM `.hgt` or `.hgt.zip` altitude files.
https://pypi.org/project/python-srtm/
24 stars 7 forks source link

Height map for RasterBaseCoordinates not found #1

Closed LaurentBerder closed 3 years ago

LaurentBerder commented 4 years ago

Hi,

I'm trying out your package, and start by just running your example code:

# SRTM1 - 30m resolution
>>> from srtm import Srtm1HeightMapCollection
>>> srtm1_data = Srtm1HeightMapCollection()
>>> srtm1_data.get_altitude(latitude=40.123, longitude=-7.456)
615
>>> Srtm1HeightMapCollection().get_elevation_profile(40.123, -7.456, 40.129, -7.460)
[615, 620, 618, 620, 616, 603, 593, 582, 575, 579, 580, 589, 589, 581, 565, 553, 545, 541, 534, 533, 529, 520, 514]

But it just results in this error:

KeyError                                  Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_height_map_for_latitude_and_longitude(self, latitude, longitude)
     60         try:
---> 61             return self.height_maps[base]
     62         except KeyError:

KeyError: RasterBaseCoordinates(latitude=40, longitude=-8)

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-9-66c5ddd22251> in <module>
----> 1 Srtm1HeightMapCollection().get_elevation_profile(40.123, -7.456, 40.129, -7.460)

~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_elevation_profile(self, start_latitude, start_longitude, end_latitude, end_longitude, apply_earth_curvature)
    116         for latitude, longitude in converted_points:
    117             elevations.append(
--> 118                 (latitude, longitude, self.get_altitude(latitude, longitude))
    119             )
    120 

~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_altitude(self, latitude, longitude)
     68     def get_altitude(self, latitude: float, longitude: float) -> int:
     69         """Get the height of the given latitude and longitude"""
---> 70         height_map = self.get_height_map_for_latitude_and_longitude(latitude, longitude)
     71         return height_map.get_altitude_for_latitude_and_longitude(latitude, longitude)
     72 

~\AppData\Local\Programs\Python\Python39\lib\site-packages\srtm\height_map_collection.py in get_height_map_for_latitude_and_longitude(self, latitude, longitude)
     61             return self.height_maps[base]
     62         except KeyError:
---> 63             raise Exception(
     64                 f"Height map for {base} not found. Have you called "
     65                 f"build_file_index() on your heightmap collection?"

Exception: Height map for RasterBaseCoordinates(latitude=40, longitude=-8) not found. Have you called build_file_index() on your heightmap collection?
adamcharnock commented 3 years ago

Hi @LaurentBerder,

Sorry for the slow reply. Did you set the environment variables mentioned in the README? These are:

export SRTM1_DIR=/path/to/srtm1/
export SRTM3_DIR=/path/to/srtm3/

If this is indeed the problem, then I think I could make the error message a bit clearer :-)

LaurentBerder commented 3 years ago

@adamcharnock I remember scrupulously following the steps of the README, but it was a while ago, and I kinda gave up on your package.

I ended up adapting this code to my usecase, instead.

adamcharnock commented 3 years ago

No worries @LaurentBerder, I'm sure you followed the README just fine. Sorry it took me so long to get back to you. If this comes up again I'll endeavour to get on it faster :-)

Closing for now, but if anyone comes across this and wants to re-open it just make sure you tag me to ensure I get a notification.

StorywithLove commented 3 years ago

@adamcharnock, I have a doubt.What is the specific path that "path" refers to here

StorywithLove commented 3 years ago

@adamcharnock,我对此表示怀疑。“ path”指的具体路径是什么? It is already known that the function of the two environment variables is to set the directory of hgt data, and a file in the directory can read the data. However, when multiple data is placed in the directory, it cannot be read, and the same error of this issuse is reported. And the value read is different from the visualization software Global Mapper, the reason is being checked