123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- extends Node
- var Downloader = preload("res://downloader.gd")
- var filePrefix = "user://topo/"
- var formatString = "SLDEM2015_%s_%02d%s_%02d%s_%03d_%03d_FLOAT.IMG"
- # example sldem2015_512_00n_30n_000_045_float.img
- var datafile = "user://topo/sldem2015_512_00n_30n_000_045_float.img"
- var samplesPerLine = 23040
- var lines = 15360
- var offset = 1737.4*1000
- var scaleFact = 1
- var resolution = 512
- var latMin = 0
- var latMax = 30
- var lonMin = 0
- var lonMax = 45
- var cache = {}
- var file: File
- # Called when the node enters the scene tree for the first time.
- func open(latMinIN, lonMinIn):
- latMin = (int(latMinIN)/30) * 30
- latMax = latMin+30
- lonMin = (int(lonMinIn)/45) * 45
- lonMax = lonMin+45
- file = File.new()
- print("opening topo: "+filePrefix+getFilename())
- var err = file.open(filePrefix+getFilename(), File.READ)
- if err != 0:
- Downloader.download(getFilename(), "topo")
- func close():
- file.close()
- #queue_free()
-
- func clear():
- file.close()
- cache = {}
-
- func cacheArea(latMinIN, latMaxIN, lonMinIN, lonMaxIN):
- if not _validate(latMinIN,lonMinIN) and not _validate(latMaxIN,lonMaxIN) :
- print("out of scope!")
- return
-
- var lat = latMinIN
- while lat <= latMaxIN:
- cache[lat]={}
- var line = lat*resolution*samplesPerLine*4
- # the origin of each .img file lies in it's upper left corner
- # so we need to read the files from the end on the northern hemisphere
- if lat >= 0:
- var origin = latMax*resolution*samplesPerLine*4
- file.seek((origin - line) + lonMinIN*resolution*4)
- else:
- file.seek(line + lonMinIN*resolution*4)
- var lon = lonMinIN
- while lon <= lonMaxIN:
- cache[lat][lon] = file.get_float()
- lon += 1.0/float(resolution)
- lat += 1.0/float(resolution)
- return
-
- func read(lat,lon):
- if _validate(lat,lon):
- return cache[lat][lon]
- else:
- print("out of scope!")
- func _validate(lat,lon):
- if lat <= latMax and lat >= latMin and lon <= lonMax and lon >= lonMin:
- return true
- return false
- func getFilename():
- # example sldem2015_512_00n_30n_000_045_float.img
- # "%s/sldem2015_%s_%0*d%s_%0*d%s_%00*d_%00*d_float.img"
- var orientation: String
- if latMin >= 0:
- orientation = "N"
- else:
- orientation = "S"
- var properties = [resolution, latMin, orientation, latMax, orientation, lonMin, lonMax]
- return formatString % properties
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- #func _process(delta):
- # pass
|