tkrajina / srtm.py

Geo elevation data parser for "The Shuttle Radar Topography Mission" data
Apache License 2.0
245 stars 57 forks source link

AssertionError: Invalid file size while trying to download .hgt file #47

Closed hari0603 closed 4 years ago

hari0603 commented 4 years ago

I have been using this package for a while now to perform elevation based operation on Geospatial data and it has been very useful! But recently when I tried to fetch SRTM elevation for longitude, latitude as 35.003152, 24.056313 respectively, I got the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Hari\AppData\Local\Programs\Python\Python36\lib\site-packages\srtm\data.py", line 57, in get_elevation
    geo_elevation_file = self.get_file(float(latitude), float(longitude))
  File "C:\Users\Hari\AppData\Local\Programs\Python\Python36\lib\site-packages\srtm\data.py", line 111, in get_file
    result = GeoElevationFile(file_name, data, self)
  File "C:\Users\Hari\AppData\Local\Programs\Python\Python36\lib\site-packages\srtm\data.py", line 345, in __init__
    assert square_side == int(square_side), 'Invalid file size: {0} for file {1}'.format(len(self.data), self.file_name)
AssertionError: Invalid file size: 70 for file N24E035.hgt

I was trying to find a solution for this and stumbled upon a similar issue which was raised about 7 years back. The exception that is raised seems to be same but the cause of error is different.

Currently, I am circumventing the issue by manually downloading the .hgt file mentioned in the trace log from https://dds.cr.usgs.gov/srtm/version2_1/SRTM3/Africa/.

Thanks again for the great work!

tkrajina commented 4 years ago

Not sure why that happened, but if that file in your ~/.cache/srtm directory is really 70 bytes long -- can you try delete it manually and re-run that script. If it works then a fix for this problem is to just delete files with invalid size and let the library re-download them again.

hari0603 commented 4 years ago

Deleting it manually and re-running the script did not fix the problem. The same exception is being raised.

hari0603 commented 4 years ago

I am running the following script that is raising the mentioned exception:

import srtm

srtm_data = srtm.get_data()
srtm_data.get_elevation(24.056313, 35.003152)
tkrajina commented 4 years ago

Ahhh... Right. I tried to reproduce it with 35.003152, 24.056313 but then I figured out that's not "lat and lon" but "lon and lat".

Anyway... Should be fixed with this https://github.com/tkrajina/srtm.py/commit/4a6dbf7b5c4d79024f9869da4157db46d2c203a7

hari0603 commented 4 years ago

Wow. That was a quick fix! Thanks a ton.