1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- extends Node
- var Downloader = preload("res://downloader.gd")
- var datafile = "height/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():
- file = File.new()
- if not file.file_exists("user://"+datafile):
- var downloader = Downloader.new()
- add_child(downloader)
- downloader.load(datafile, "height")
- yield(downloader, "request_completed")
- file.open("user://"+datafile, File.READ)
-
- func close():
- file.close()
- queue_free()
-
- 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
- # Called every frame. 'delta' is the elapsed time since the previous frame.
- #func _process(delta):
- # pass
|