'read GZ file with python3

hello everybody i try to decompress a file with python3 gzip it is a map tiles The files are in binary format. They consist of an 11-byte header, followed by a block of data compressed in gz.

The header contains:

● byte 1: file version (1 from memory)

● bytes 2 and 3: latitude of the tile, the first byte indicates the sign, 1 for negative, 0 for positive, the second contains the absolute value of the latitude

● bytes 4 and 5: longitude of the tile, the first byte indicates the sign, 1 for negative, 0 for positive, the second contains the absolute value of the longitude

● byte 6: I don't know what this byte represents, from experience it has the value 1

● byte 7 and 8: width (and height) of the tile in number of values, this field is always 730, there are 730x730 so 532900 values ​​in the data

● bytes 9 to 11: file generation date, not very useful

year = 2040 - byte9

month = byte10 + 1 (for January = 1)

day = byte 11

Following this header is the value buffer, you must use a library of gzip unzip to unzip them. The terrain heights (or water depth) are encoded on 1 signed byte. Values strictly negative values ​​are water, positive or zero values ​​are earth.

i do this

import urllib.request
import gzip
url = 'https://static.virtualregatta.com/ressources/maps/dalles/vro2k16/1/0/4/1_-4_44.deg'
fileName = 'tile'
urllib.request.urlretrieve(url, fileName)
print('loaded tile!')
with gzip.open('tile', 'rb') as f:
    file_content = f.read()
    print(file_content)

but i get an error message, what is the problem?

Traceback (most recent call last):

  File "C:/Users/David.ECBM/PycharmProjects/ttt/main.py", line 9, in <module>

file_content = f.read()

  File "C:\Program Files (x86)\Python38-32\lib\gzip.py", line 292, in read

return self._buffer.read(size)

  File "C:\Program Files (x86)\Python38-32\lib\gzip.py", line 479, in read

if not self._read_gzip_header():

  File "C:\Program Files (x86)\Python38-32\lib\gzip.py", line 427, in _read_gzip_header
raise BadGzipFile('Not a gzipped file (%r)' % magic)

gzip.BadGzipFile: Not a gzipped file (b'\x01\x01')


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source