فهرست منبع

updated file names

willpiper 4 سال پیش
والد
کامیت
83456ad752
6فایلهای تغییر یافته به همراه0 افزوده شده و 642 حذف شده
  1. 0 41
      README.md
  2. 0 41
      app.py
  3. 0 136
      offline_check.py
  4. 0 121
      offline_gen.py
  5. 0 290
      terrain_gen.py
  6. 0 13
      terraingen.ini

+ 0 - 41
README.md

@@ -1,41 +0,0 @@
-# ArduPilot terrain generator
-
-## Summary
-
-This is a website that pre-generates terrain files for Ardupilot. The user enters in the details
-of the area they wish the generate terrain for, then the website will generate a terrain.zip file containing
-the relevant dat files. The user will download this file and then
-then need to unzip to a "terrain" folder on the SD card in their flight controller.
-
-## Pre-generation of Terrain
-
-To ensure the website operates responsively, the terrain for the whole (-60 -> +60 latitude) world
-must be pregenerated. This will take some time.
-
-Run ``offline_gen.py`` to download the SRTM files from ardupilot.org and convert them to the dat
-file format. These files will be stored in the processedTerrain folder.
-
-## For developers
-
-This website uses the flask library.
-
-To install dependencies:
-
-``pip install flask wheel uwsgi numpy mavproxy crc16 pytest``
-
-To run:
-
-```
-python3 app.py
-```
-
-The unzipped processed files are temporarily stored in ./outputTer-tmp. These are deleted upon the zipping into a single
-downloadable file
-
-The downloadable files are stored in ./outputTer
-
-Each user request is given a UUID, which is incorporated into the folder/filename of the terrain files.
-
-To run the unit tests, type ``pytest``
-
-

+ 0 - 41
app.py

@@ -10,8 +10,6 @@ from flask import Flask # using flask as the framework
 from flask import render_template
 from flask import request
 
-from terrain_gen import add_offset
-
 # Directory of this file
 this_path = os.path.dirname(os.path.realpath(__file__))
 
@@ -24,21 +22,6 @@ tile_path = os.path.join(this_path, '..', 'data', 'tiles')
 # The output folder for all gzipped terrain requests
 app = Flask(__name__, static_url_path='/terrain', static_folder=output_path,)
 
-def clamp(n, smallest, largest):
-    return max(smallest, min(n, largest))
-
-def getDatFile(lat, lon):
-    '''Get file'''
-    if lat < 0:
-        NS = 'S'
-    else:
-        NS = 'N'
-    if lon < 0:
-        EW = 'W'
-    else:
-        EW = 'E'
-    return "%c%02u%c%03u.DAT.gz" % (NS, min(abs(int(lat)), 99), EW, min(abs(int(lon)), 999))
-
 def compressFiles(fileList, uuidkey):
     # create a zip file comprised of dat.gz tiles
     zipthis = os.path.join(output_path, uuidkey + '.zip')
@@ -105,30 +88,6 @@ def generate():
         # UUID for this terrain generation
         uuidkey = str(uuid.uuid1())
 
-        # get a list of files required to cover area
-        filelist = []
-        done = set()
-        for dx in range(-radius, radius):
-            for dy in range(-radius, radius):
-                (lat2, lon2) = add_offset(lat*1e7, lon*1e7, dx*1000.0, dy*1000.0)
-                lat_int = int(round(lat2 * 1.0e-7))
-                lon_int = int(round(lon2 * 1.0e-7))
-                tag = (lat_int, lon_int)
-                if tag in done:
-                    continue
-                done.add(tag)
-                # make sure tile is inside the 60deg latitude limit
-                if abs(lat_int) <= 60:
-                    filelist.append(os.path.join(tile_path, getDatFile(lat_int, lon_int)))
-                else:
-                    outsideLat = True
-
-        # make sure tile is inside the 60deg latitude limit
-        if abs(lat_int) <= 60:
-            filelist.append(os.path.join(tile_path, getDatFile(lat_int, lon_int)))
-        else:
-            outsideLat = True
-
         # remove duplicates
         filelist = list(dict.fromkeys(filelist))
         print(filelist)

+ 0 - 136
offline_check.py

@@ -1,136 +0,0 @@
-#!/usr/bin/env python
-'''
-Check a set of terrain files for corruption
-'''
-import os
-#from multiprocessing import Pool
-from multiprocessing.pool import ThreadPool
-import argparse
-import time
-import gzip
-import shutil
-import struct
-import crc16
-
-from terrain_gen import TERRAIN_GRID_BLOCK_SIZE_Y, east_blocks, IO_BLOCK_SIZE, TERRAIN_GRID_FORMAT_VERSION, GridBlock
-
-# IO block size is 2048
-# Actual size is 1821 bytes
-# Last 227 bytes is filling
-def check_filled(block, lat_int, lon_int, grid_spacing):
-    '''check a block for validity'''
-    if len(block) != IO_BLOCK_SIZE - 227:
-        print("Bad size {0} of {1}".format(len(block), IO_BLOCK_SIZE))
-        return False
-    (bitmap, lat, lon, crc, version, spacing) = struct.unpack("<QiiHHH", block[:22])
-    if(lat == 0 and lon == 0 and crc == 0 and version == 0 and spacing == 0):
-        #print("Empty block")
-        return True
-    if (str(version) != str(TERRAIN_GRID_FORMAT_VERSION)):
-        print("Bad version: " + str(version))
-        return False
-    if abs(lat_int - (lat/1E7)) > 2 or abs(lon_int - (lon/1E7)) > 2:
-        print("Bad lat/lon: {0}, {1}".format((lat/1E7), (lon/1E7)))
-        return False
-    if spacing != 100:
-        print("Bad spacing: " + str(spacing))
-        return False
-    if bitmap != (1<<56)-1:
-        print("Bad bitmap")
-        return False
-
-    block = block[:16] + struct.pack("<H", 0) + block[18:]
-    crc2 = crc16.crc16xmodem(block[:1821])
-    if crc2 != crc:
-        print("Bad CRC")
-        return False
-
-    # all is good, return lon/lat of block
-    return (lat, lon)
-
-if __name__ == '__main__':
-    # Create the parser
-    parser = argparse.ArgumentParser(description='ArduPilot Terrain DAT file generator')
-
-    # Add the arguments
-    # Folder to store processed DAT files
-    parser.add_argument('-folder', action="store", dest="folder", default="processedTerrain")
-    
-    args = parser.parse_args()
-
-    targetFolder = os.path.join(os.getcwd(), args.folder)
-
-    grid_spacing = 100
-    
-
-    #for each file in folder
-    for file in os.listdir(targetFolder):
-        if file.endswith("DAT.gz") or file.endswith("DAT"):
-            # It's a compressed tile
-            # 1. Check it's a valid gzip
-            #print(file)
-            tile = None
-            try:
-                lat_int = int(os.path.basename(file)[1:3])
-                if os.path.basename(file)[0:1] == "S":
-                    lat_int = -lat_int
-                lon_int = int(os.path.basename(file)[4:7])
-                if os.path.basename(file)[3:4] == "W":
-                    lon_int = -lon_int
-                if file.endswith("DAT.gz"):
-                    with gzip.open(os.path.join(targetFolder, file), 'rb') as f:
-                        tile = f.read()
-                else:
-                    with open(os.path.join(targetFolder, file), 'rb') as f:
-                        tile = f.read()
-            except Exception as e:
-                print("Bad file: " + file)
-                print(e)
-            # 2. Is it a valid dat file?
-            if (tile):
-                
-                # 2a. Are the correct number (integer) of blocks present?
-                # It will be a multiple of 2048 bytes (block size)
-                # There is an missing 227 bytes at the end on the file (2048-1821 = 227), as the 
-                # terrain blocks only take up 1821 bytes.
-                # APM actually adds the padding on the end, so extra 227 is not needed sometimes
-                total_blocks = 0
-                if (len(tile)+227) % IO_BLOCK_SIZE == 0:
-                    total_blocks = int((len(tile)+227) / IO_BLOCK_SIZE)
-                elif len(tile) % IO_BLOCK_SIZE == 0:
-                    total_blocks = int(len(tile) / IO_BLOCK_SIZE)
-                else:
-                    print("Bad file size: {0}. {1} extra bytes at end".format(file, len(tile), len(tile) % IO_BLOCK_SIZE))
-                if total_blocks > 6000 or total_blocks < 900:
-                    print(file)
-                    print("Error: Has {0} blocks".format(total_blocks))
-                # 2b. Does each block have the correct CRC and fields?
-                if total_blocks != 0:
-                    lat_min = 90 * 1.0e7
-                    lat_max = -90 * 1.0e7
-                    lon_min = 180 * 1.0e7
-                    lon_max = -180 * 1.0e7
-                    for blocknum in range(total_blocks):
-                        block = tile[(blocknum * IO_BLOCK_SIZE):((blocknum + 1)* IO_BLOCK_SIZE)-227]
-                        ret = check_filled(block, lat_int, lon_int, 100)
-                        if not ret:
-                            print(file)
-                            print("Bad data in block {0} of {1}".format(blocknum, total_blocks))
-                        else:
-                            (lat, lon) = ret
-                            lat_min = min(lat_min, lat)
-                            lat_max = max(lat_max, lat)
-                            lon_min = min(lon_min, lon)
-                            lon_max = max(lon_max, lon)
-                    lat_min *= 1.0e-7
-                    lat_max *= 1.0e-7
-                    lon_min *= 1.0e-7
-                    lon_max *= 1.0e-7
-                    if abs(lat_max-lat_min) < 0.99 or abs(lon_max-lon_min) < 1.00 or abs(lat_max-lat_min) > 1.01 or abs(lon_max-lon_min) > 1.07:
-                        print(file)
-                        print("Bad tile")                                
-                        print("Tile covers ({0},{1}) to ({2},{3})".format(lat_min, lon_min, lat_max, lon_max))
-                        print("Tile size is ({0:.4f}, {1:.4f}) degrees".format(lat_max-lat_min, lon_max-lon_min))
-            else:
-                print("Bad tile: " + file)
-    print("Done!")

+ 0 - 121
offline_gen.py

@@ -1,121 +0,0 @@
-#!/usr/bin/env python3
-'''
-Generation of all dat files at 100m spacing.
-Preprocessing so the website doesn't have to
-
-This will take a long time to process!
-'''
-import os
-#from multiprocessing import Pool
-from multiprocessing.pool import ThreadPool
-import argparse
-import time
-import gzip
-import shutil
-
-from MAVProxy.modules.mavproxy_map import srtm
-from terrain_gen import create_degree
-
-def worker(downloader, lat, long, targetFolder, startedTiles, totTiles):
-    # only create if the output file does not exists
-    if os.path.exists(datafile(lat, long, targetFolder) + '.gz'):
-        print("Skipping existing compressed tile {0} of {1} ({2:.3f}%)".format(startedTiles, totTiles, ((startedTiles)/totTiles)*100))
-        return
-
-    if not os.path.exists(datafile(lat, long, targetFolder)):
-        create_degree(downloader, lat, long, targetFolder, 100)
-        print("Created tile {0} of {1}".format(startedTiles, totTiles))
-    else:
-        print("Skipping existing tile {0} of {1} ({2:.3f}%)".format(startedTiles, totTiles, ((startedTiles)/totTiles)*100))
-
-    # and compress
-    with open(datafile(lat, long, targetFolder), 'rb') as f_in:
-        with gzip.open(datafile(lat, long, targetFolder) + '.gz', 'wb') as f_out:
-            shutil.copyfileobj(f_in, f_out)
-    os.remove(datafile(lat, long, targetFolder))
-
-    print("Done tile {0} of {1} ({2:.3f}%)".format(startedTiles, totTiles, ((startedTiles)/totTiles)*100))
-    print("Folder is {0:.0f}Mb in size".format(get_size(targetFolder)/(1024*1024)))
-
-def datafile(lat, lon, folder):
-    if lat < 0:
-        NS = 'S'
-    else:
-        NS = 'N'
-    if lon < 0:
-        EW = 'W'
-    else:
-        EW = 'E'
-    name = folder + "/%c%02u%c%03u.DAT" % (NS, min(abs(int(lat)), 99),
-                                    EW, min(abs(int(lon)), 999))
-
-    return name
-
-def get_size(start_path = '.'):
-    total_size = 0
-    for dirpath, dirnames, filenames in os.walk(start_path):
-        for f in filenames:
-            fp = os.path.join(dirpath, f)
-            # skip if it is symbolic link
-            if not os.path.islink(fp):
-                # other threads may be moving files whilst we're getting folder
-                # size here
-                try:
-                    total_size += os.path.getsize(fp)
-                except FileNotFoundError:
-                    pass
-
-    return total_size
-
-if __name__ == '__main__':
-    global filelistDownloadActive
-    # Create the parser
-    parser = argparse.ArgumentParser(description='ArduPilot Terrain DAT file generator')
-
-    # Add the arguments
-    # Folder to store processed DAT files
-    parser.add_argument('-folder', action="store", dest="folder", default="processedTerrain")
-    # Number of threads to use
-    parser.add_argument('-processes', action="store", dest="processes", type=int, default=4)
-    # Latitude range
-    parser.add_argument('-latitude', action="store", dest="latitude", type=int, default=60)
-    
-    args = parser.parse_args()
-
-    downloader = srtm.SRTMDownloader(debug=False, cachedir='srtmcache')
-    downloader.loadFileList()
-
-    targetFolder = os.path.join(os.getcwd(), args.folder)
-    #create folder if required
-    try:
-        os.mkdir(targetFolder)
-    except FileExistsError:
-        pass
-
-    print("Storing in " + targetFolder)
-
-    # store the threads
-    processes = []
-
-    # make tileID's
-    tileID = []
-    i = 0
-    for long in range(-180, 180):
-        for lat in range (-(args.latitude+1), args.latitude+1):
-            tileID.append([lat, long, i]) 
-            i += 1
-
-    # total number of tiles
-    totTiles = len(tileID)
-    startedTiles = 0
-
-    # Use a pool of workers to process
-    with ThreadPool(args.processes-1) as p:
-        reslist = [p.apply_async(worker, args=(downloader, td[0], td[1], targetFolder, td[2], len(tileID))) for td in tileID]
-        for result in reslist:
-            result.get()
-
-    print("--------------------------")
-    print("All tiles generated!")
-    print("--------------------------")
-

+ 0 - 290
terrain_gen.py

@@ -1,290 +0,0 @@
-#!/usr/bin/env python
-'''
-create ardupilot terrain database files
-'''
-
-import math, struct, os
-import crc16, time, struct
-
-from MAVProxy.modules.mavproxy_map import srtm
-
-# MAVLink sends 4x4 grids
-TERRAIN_GRID_MAVLINK_SIZE = 4
-
-# a 2k grid_block on disk contains 8x7 of the mavlink grids.  Each
-# grid block overlaps by one with its neighbour. This ensures that
-# the altitude at any point can be calculated from a single grid
-# block
-TERRAIN_GRID_BLOCK_MUL_X = 7
-TERRAIN_GRID_BLOCK_MUL_Y = 8
-
-# this is the spacing between 32x28 grid blocks, in grid_spacing units
-TERRAIN_GRID_BLOCK_SPACING_X = ((TERRAIN_GRID_BLOCK_MUL_X-1)*TERRAIN_GRID_MAVLINK_SIZE)
-TERRAIN_GRID_BLOCK_SPACING_Y = ((TERRAIN_GRID_BLOCK_MUL_Y-1)*TERRAIN_GRID_MAVLINK_SIZE)
-
-# giving a total grid size of a disk grid_block of 32x28
-TERRAIN_GRID_BLOCK_SIZE_X = (TERRAIN_GRID_MAVLINK_SIZE*TERRAIN_GRID_BLOCK_MUL_X)
-TERRAIN_GRID_BLOCK_SIZE_Y = (TERRAIN_GRID_MAVLINK_SIZE*TERRAIN_GRID_BLOCK_MUL_Y)
-
-# format of grid on disk
-TERRAIN_GRID_FORMAT_VERSION = 1
-
-IO_BLOCK_SIZE = 2048
-IO_BLOCK_DATA_SIZE = 1821
-IO_BLOCK_TRAILER_SIZE = IO_BLOCK_SIZE - IO_BLOCK_DATA_SIZE
-
-#GRID_SPACING = 100
-
-def to_float32(f):
-    '''emulate single precision float'''
-    return struct.unpack('f', struct.pack('f',f))[0]
-
-LOCATION_SCALING_FACTOR = to_float32(0.011131884502145034)
-LOCATION_SCALING_FACTOR_INV = to_float32(89.83204953368922)
-
-def longitude_scale(lat):
-    '''get longitude scale factor'''
-    scale = to_float32(math.cos(to_float32(math.radians(lat))))
-    return max(scale, 0.01)
-
-def get_distance_NE_e7(lat1, lon1, lat2, lon2):
-    '''get distance tuple between two positions in 1e7 format'''
-    return ((lat2 - lat1) * LOCATION_SCALING_FACTOR, (lon2 - lon1) * LOCATION_SCALING_FACTOR * longitude_scale(lat1*1.0e-7))
-
-def add_offset(lat_e7, lon_e7, ofs_north, ofs_east):
-    '''add offset in meters to a position'''
-    dlat = int(float(ofs_north) * LOCATION_SCALING_FACTOR_INV)
-    dlng = int((float(ofs_east) * LOCATION_SCALING_FACTOR_INV) / longitude_scale(lat_e7*1.0e-7))
-    return (int(lat_e7+dlat), int(lon_e7+dlng))
-
-def east_blocks(lat_e7, lon_e7, grid_spacing):
-    '''work out how many blocks per stride on disk'''
-    lat2_e7 = lat_e7
-    lon2_e7 = lon_e7 + 10*1000*1000
-
-    # shift another two blocks east to ensure room is available
-    lat2_e7, lon2_e7 = add_offset(lat2_e7, lon2_e7, 0, 2*grid_spacing*TERRAIN_GRID_BLOCK_SIZE_Y)
-    offset = get_distance_NE_e7(lat_e7, lon_e7, lat2_e7, lon2_e7)
-    return int(offset[1] / (grid_spacing*TERRAIN_GRID_BLOCK_SPACING_Y))
-
-def pos_from_file_offset(lat_degrees, lon_degrees, file_offset, grid_spacing):
-    '''return a lat/lon in 1e7 format given a file offset'''
-
-    ref_lat = int(lat_degrees*10*1000*1000)
-    ref_lon = int(lon_degrees*10*1000*1000)
-
-    stride = east_blocks(ref_lat, ref_lon, grid_spacing)
-    blocks = file_offset // IO_BLOCK_SIZE
-    grid_idx_x = blocks // stride
-    grid_idx_y = blocks % stride
-
-    idx_x = grid_idx_x * TERRAIN_GRID_BLOCK_SPACING_X
-    idx_y = grid_idx_y * TERRAIN_GRID_BLOCK_SPACING_Y
-    offset = (idx_x * grid_spacing, idx_y * grid_spacing)
-
-    (lat_e7, lon_e7) = add_offset(ref_lat, ref_lon, offset[0], offset[1])
-
-    offset = get_distance_NE_e7(ref_lat, ref_lon, lat_e7, lon_e7)
-    grid_idx_x = int(idx_x / TERRAIN_GRID_BLOCK_SPACING_X)
-    grid_idx_y = int(idx_y / TERRAIN_GRID_BLOCK_SPACING_Y)
-
-    (lat_e7, lon_e7) = add_offset(ref_lat, ref_lon,
-                                  grid_idx_x * TERRAIN_GRID_BLOCK_SPACING_X * float(grid_spacing),
-                                  grid_idx_y * TERRAIN_GRID_BLOCK_SPACING_Y * float(grid_spacing))
-
-    return (lat_e7, lon_e7)
-
-class GridBlock(object):
-    def __init__(self, lat_int, lon_int, lat, lon, grid_spacing):
-        '''
-        a grid block is a structure in a local file containing height
-        information. Each grid block is 2048 bytes in size, to keep file IO to
-        block oriented SD cards efficient
-        '''
-
-        # crc of whole block, taken with crc=0
-        self.crc = 0
-
-        # format version number
-        self.version = TERRAIN_GRID_FORMAT_VERSION
-
-        # grid spacing in meters
-        self.spacing = grid_spacing
-
-        # heights in meters over a 32*28 grid
-        self.height = []
-        for x in range(TERRAIN_GRID_BLOCK_SIZE_X):
-            self.height.append([0]*TERRAIN_GRID_BLOCK_SIZE_Y)
-
-        # bitmap of 4x4 grids filled in from GCS (56 bits are used)
-        self.bitmap = (1<<56)-1
-
-        lat_e7 = int(lat * 1.0e7)
-        lon_e7 = int(lon * 1.0e7)
-
-        # grids start on integer degrees. This makes storing terrain data on
-        # the SD card a bit easier. Note that this relies on the python floor
-        # behaviour with integer division
-        self.lat_degrees = lat_int
-        self.lon_degrees = lon_int
-
-        # create reference position for this rounded degree position
-        ref_lat = self.lat_degrees*10*1000*1000
-        ref_lon = self.lon_degrees*10*1000*1000
-
-        # find offset from reference
-        offset = get_distance_NE_e7(ref_lat, ref_lon, lat_e7, lon_e7)
-
-        offset = (round(offset[0]), round(offset[1]))
-
-        # get indices in terms of grid_spacing elements
-        idx_x = int(offset[0] / self.spacing)
-        idx_y = int(offset[1] / self.spacing)
-
-        # find indexes into 32*28 grids for this degree reference. Note
-        # the use of TERRAIN_GRID_BLOCK_SPACING_{X,Y} which gives a one square
-        # overlap between grids
-        self.grid_idx_x = idx_x // TERRAIN_GRID_BLOCK_SPACING_X
-        self.grid_idx_y = idx_y // TERRAIN_GRID_BLOCK_SPACING_Y
-
-        # calculate lat/lon of SW corner of 32*28 grid_block
-        (ref_lat, ref_lon) = add_offset(ref_lat, ref_lon,
-                                        self.grid_idx_x * TERRAIN_GRID_BLOCK_SPACING_X * float(self.spacing),
-                                        self.grid_idx_y * TERRAIN_GRID_BLOCK_SPACING_Y * float(self.spacing))
-        self.lat = ref_lat
-        self.lon = ref_lon
-
-    def fill(self, gx, gy, altitude):
-        '''fill a square'''
-        self.height[gx][gy] = int(altitude)
-
-    def blocknum(self):
-        '''find IO block number'''
-        stride = east_blocks(self.lat_degrees*1e7, self.lon_degrees*1e7, self.spacing)
-        return stride * self.grid_idx_x + self.grid_idx_y
-
-class DataFile(object):
-    def __init__(self, lat, lon, folder):
-        if lat < 0:
-            NS = 'S'
-        else:
-            NS = 'N'
-        if lon < 0:
-            EW = 'W'
-        else:
-            EW = 'E'
-        self.name = folder + "/%c%02u%c%03u.DAT" % (NS, min(abs(int(lat)), 99),
-                                             EW, min(abs(int(lon)), 999))
-        self.tmpname = folder + "/%c%02u%c%03u.DAT.tmp" % (NS, min(abs(int(lat)), 99),
-                                             EW, min(abs(int(lon)), 999))
-        try:
-            os.mkdir(folder)
-        except Exception:
-            pass
-        if not os.path.exists(self.name):
-            self.fh = open(self.tmpname, 'w+b')
-        else:
-            self.fh = open(self.name, 'r+b')
-
-    def finalise(self):
-        '''finalise file after writing'''
-        self.fh.close()
-        #and rename
-        os.rename(self.tmpname, self.name)
-
-    def seek_offset(self, block):
-        '''seek to right offset'''
-        # work out how many longitude blocks there are at this latitude
-        file_offset = block.blocknum() * IO_BLOCK_SIZE
-        self.fh.seek(file_offset)
-
-    def pack(self, block):
-        '''pack into a block'''
-        buf = bytes()
-        buf += struct.pack("<QiiHHH", block.bitmap, block.lat, block.lon, block.crc, block.version, block.spacing)
-        for gx in range(TERRAIN_GRID_BLOCK_SIZE_X):
-            buf += struct.pack("<%uh" % TERRAIN_GRID_BLOCK_SIZE_Y, *block.height[gx])
-        buf += struct.pack("<HHhb", block.grid_idx_x, block.grid_idx_y, block.lon_degrees, block.lat_degrees)
-        buf += struct.pack("%uB" % IO_BLOCK_TRAILER_SIZE, *[0]*IO_BLOCK_TRAILER_SIZE)
-        return buf
-
-    def write(self, block):
-        '''write a grid block'''
-        self.seek_offset(block)
-        block.crc = 0
-        buf = self.pack(block)
-        block.crc = crc16.crc16xmodem(buf[:IO_BLOCK_DATA_SIZE])
-        buf = self.pack(block)
-        self.fh.write(buf)
-
-    def check_filled(self, block, grid_spacing):
-        '''read a grid block and check if already filled'''
-        self.seek_offset(block)
-        buf = self.fh.read(IO_BLOCK_SIZE)
-        if len(buf) != IO_BLOCK_SIZE:
-            return False
-        (bitmap, lat, lon, crc, version, spacing) = struct.unpack("<QiiHHH", buf[:22])
-        if (version != TERRAIN_GRID_FORMAT_VERSION or
-            abs(lat - block.lat)>2 or
-            abs(lon - block.lon)>2 or
-            spacing != grid_spacing or
-            bitmap != (1<<56)-1):
-            return False
-        buf = buf[:16] + struct.pack("<H", 0) + buf[18:]
-        crc2 = crc16.crc16xmodem(buf[:1821])
-        if crc2 != crc:
-            return False
-        return True
-
-def create_degree(downloader, lat, lon, folder, grid_spacing):
-    '''create data file for one degree lat/lon'''
-    lat_int = int(math.floor(lat))
-    lon_int = int(math.floor((lon)))
-
-    tiles = {}
-
-    dfile = DataFile(lat_int, lon_int, folder)
-
-    print("Creating for %d %d" % (lat_int, lon_int))
-
-    blocknum = -1
-
-    while True:
-        blocknum += 1
-        (lat_e7, lon_e7) = pos_from_file_offset(lat_int, lon_int, blocknum * IO_BLOCK_SIZE, grid_spacing)
-        if lat_e7*1.0e-7 - lat_int >= 1.0:
-            break
-        lat = lat_e7 * 1.0e-7
-        lon = lon_e7 * 1.0e-7
-        grid = GridBlock(lat_int, lon_int, lat, lon, grid_spacing)
-        if grid.blocknum() != blocknum:
-            continue
-        if dfile.check_filled(grid, grid_spacing):
-            continue
-        for gx in range(TERRAIN_GRID_BLOCK_SIZE_X):
-            for gy in range(TERRAIN_GRID_BLOCK_SIZE_Y):
-                lat_e7, lon_e7 = add_offset(lat*1.0e7, lon*1.0e7, gx*grid_spacing, gy*grid_spacing)
-                lat2_int = int(math.floor(lat_e7*1.0e-7))
-                lon2_int = int(math.floor(lon_e7*1.0e-7))
-                tile_idx = (lat2_int, lon2_int)
-                while not tile_idx in tiles:
-                    tile = downloader.getTile(lat2_int, lon2_int)
-                    waited = False
-                    if tile == 0:
-                        print("waiting on download of %d,%d" % (lat2_int, lon2_int))
-                        time.sleep(0.3)
-                        waited = True
-                        continue
-                    if waited:
-                        print("downloaded %d,%d" % (lat2_int, lon2_int))
-                    tiles[tile_idx] = tile
-                if isinstance(tile, srtm.SRTMOceanTile):
-                    # if it's a blank ocean tile, there's a quicker way to generate the tile
-                    grid.fill(gx, gy, 0)
-                else:
-                    altitude = tiles[tile_idx].getAltitudeFromLatLon(lat_e7*1.0e-7, lon_e7*1.0e-7)
-                    grid.fill(gx, gy, altitude)
-        dfile.write(grid)
-
-    dfile.finalise()
-

+ 0 - 13
terraingen.ini

@@ -1,13 +0,0 @@
-[uwsgi]
-module = wsgi:app
-
-master = true
-processes = 5
-
-socket = terraingen.sock
-chmod-socket = 660
-vacuum = true
-
-die-on-term = true
-
-touch-reload=/data/sites/terrain/web/terraingen/reload.touch