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 #3

Closed GeospatialPython closed 11 years ago

GeospatialPython commented 11 years ago

Environment:

Running "sample_images.py" the first time works great. If I run it again, srtm.py tries to use the cached file but produces the following Traceback on the first file (istra sample):

Traceback (most recent call last):
  File "sample_images.py", line 29, in <module>
    image = geo_elevation_data.get_image((400, 400), (45, 46), (13, 14), 300)
  File "C:\Python27\lib\site-packages\srtm.py-0.2.3-py2.7.egg\srtm\data.py", line 183, in get_image
    elevation = self.get_elevation(latitude, longitude)
  File "C:\Python27\lib\site-packages\srtm.py-0.2.3-py2.7.egg\srtm\data.py", line 58, in get_elevation
    geo_elevation_file = self.get_file(float(latitude), float(longitude))
  File "C:\Python27\lib\site-packages\srtm.py-0.2.3-py2.7.egg\srtm\data.py", line 87, in get_file
    result = GeoElevationFile(file_name, data, self)
  File "C:\Python27\lib\site-packages\srtm.py-0.2.3-py2.7.egg\srtm\data.py", line 226, 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: 2053 for file N45E013.hgt

If I delete the cached files from the ~./srtm directory and run the script again everything works. I have not been able to determine if this is a Windows-specific problem yet. Note: I'm using the os.environ hack from the other issue I submitted about the HOME directory so it might be related to that.

Thanks again for the great work.

GeospatialPython commented 11 years ago

A solution to this issue and an explanation of why it is happening is committed in the GeospatialPython fork.

tkrajina commented 11 years ago

Right... The binary file type in windows.

I merged your changes and released a new version on pypi.

Thank you very much!