Javad BIN
The following code was tested for files with header='JGGEO102'. For headerless files and for JGGEO101 YMMV.
import os,sys
import struct
def printf(format,*args):
sys.stdout.write(format % args)
fname=sys.argv[1]
fin = open(fname, "r")
if len > 0xb2:
header, = struct.unpack("8s",fin.read(8))
magic, = struct.unpack("b",fin.read(1))
misc_xx, = struct.unpack("57s",fin.read(57))
minx, = struct.unpack("d",fin.read(8))
maxy, = struct.unpack("d",fin.read(8))
maxx, = struct.unpack("d",fin.read(8))
miny, = struct.unpack("d",fin.read(8))
dx, = struct.unpack("d",fin.read(8))
dy, = struct.unpack("d",fin.read(8))
ncol, = struct.unpack("I",fin.read(4))
nrow, = struct.unpack("I",fin.read(4))
unk1, = struct.unpack("I",fin.read(4))
unk11, = struct.unpack("I",fin.read(4))
ncol2, = struct.unpack("I",fin.read(4))
nrow2, = struct.unpack("I",fin.read(4))
type, = struct.unpack("I",fin.read(4))
unk3, = struct.unpack("I",fin.read(4))
interp, = struct.unpack("I",fin.read(4))
nul1, = struct.unpack("I",fin.read(4))
nul2, = struct.unpack("I",fin.read(4))
zscale, = struct.unpack("d",fin.read(8))
zmin, = struct.unpack("d",fin.read(8))
nvals, = struct.unpack("I",fin.read(4))
for i in range(0,nrow*ncol):
row = int(i/ncol)
col = i%(ncol)
if type == 3: # int2
val, = struct.unpack("H",fin.read(2))
printf("%.9f %.9f %13.6f\n", (minx+col*dx)*R2D,(miny+row*dy)*R2D, zmin+(val-1)/zscale)
if type == 4: # int4
val, = struct.unpack("I",fin.read(4))
printf("%.9f %.9f %13.6f\n", (minx+col*dx)*R2D,(miny+row*dy)*R2D, zmin+val/zscale) # val-1 ?
if type == 5: # float4
val, = struct.unpack("f",fin.read(4))
printf("%.9f %.9f %13.6f\n", (minx+col*dx)*R2D,(miny+row*dy)*R2D, zmin+val)
This article is issued from Openstreetmap. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.