\r
# Tile info object\r
def open_tile_info(self):\r
- self._tileinfo = mstr_tileinfo(self._latitude, self._longitude, self._latlngfld)\r
+ self._tileinfo = mstr_tileinfo(self._latitude, self._longitude, self._lat_number, self._lng_number, self._latlngfld)\r
\r
# This generates a "border" image, for example farmland usually has a small space of grass\r
# before the actual crop of farm field itself. This generates this "border" layer,\r
mstr_msg("layergen", "Layer to be generated: " + str(self._latitude) + "-" + str(self._lat_number) + ":" + str(self._longitude) + "-" + str(self._lng_number) + " -- tag: " + self._tag + " - value: " + self._value )\r
\r
# Before we generate the layer, let's check for airports in this chunk\r
- """\r
mstr_msg("layergen", "Checking for airport/s with ICAO code")\r
osmxml = mstr_osmxml(0,0)\r
icao = osmxml.find_icao_codes(mstr_datafolder + "_cache/tile.xml")\r
rw_surface = ""\r
# If we find an airport, make a note ...\r
if len(icao) >= 1:\r
- for i in icao:\r
+ #for i in icao:\r
# ... but only, if this airport is not already noted\r
- iccheck = self._tiledb.perform_query("SELECT * FROM airports WHERE icao='" + i +"';")\r
- if len(iccheck) == 0:\r
- self._tiledb.insert_icao(i, self._lat_number, self._lng_number, self._latitude, self._longitude)\r
- mstr_msg("layergen", "Airport/s noted in data file")\r
+ #iccheck = self._tiledb.perform_query("SELECT * FROM airports WHERE icao='" + i +"';")\r
+ #if len(iccheck) == 0:\r
+ #self._tiledb.insert_icao(i, self._lat_number, self._lng_number, self._latitude, self._longitude)\r
+ # mstr_msg("layergen", "Airport/s noted in data file")\r
rw_surface = osmxml.find_runway_surface(mstr_datafolder + "_cache/tile.xml")\r
- """\r
\r
# The image for the layer itself\r
layer = Image.new("RGBA", (self._imgsize, self._imgsize))\r
\r
# Here we need to do some magic to make some features look more natural\r
if (self._tag == "landuse" and self._value == "meadow") or (self._tag == "natural" and self._value == "grassland") or (self._tag == "natural" and self._value == "heath"):\r
- amt = randrange(1,5)\r
+ amt = randrange(1,16)\r
for i in range(1, amt+1):\r
ptc = randrange(1, 14)\r
img = Image.open(mstr_datafolder + "textures/tile/completion/p" + str(ptc)+".png")\r
+++ /dev/null
-\r
-# -------------------------------------------------------------------\r
-# ORTHOGRAPHIC\r
-# Your personal aerial satellite. Always on. At any altitude.*\r
-# Developed by MarStrMind\r
-# License: Open Software License 3.0\r
-# Up to date version always on marstr.online\r
-# -------------------------------------------------------------------\r
-# tiledb.py\r
-# Manages information concerning the information for a particular\r
-# tile, particularly its consisting smaller subtiles. Used for\r
-# consistent layer generation.\r
-# -------------------------------------------------------------------\r
-\r
-import sqlite3\r
-from defines import *\r
-from functions import *\r
-from log import *\r
-\r
-class mstr_tiledb:\r
- def __init__(self, lat, lng, latlngfld):\r
- # Note coords\r
- self._latitude = lat\r
- self._longitude = lng\r
- self._latlngfld = latlngfld\r
-\r
- # The db file will be created, should it not exist\r
- self._conn = sqlite3.connect(mstr_datafolder + "z_orthographic/data/" + latlngfld + "/data.db")\r
- self._crs = self._conn.cursor()\r
- #mstr_msg("tiledb", "Database object initiated")\r
-\r
-\r
- # Opens a database file - used by maskgen\r
- def openDB(self, dbfile):\r
- self._conn = sqlite3.connect(dbfile + ".db")\r
- self._crs = self._conn.cursor()\r
-\r
-\r
- # Creates tables for this particular degree of lat/lng\r
- def create_tables(self):\r
- self._conn.execute("CREATE TABLE IF NOT EXISTS tiledata (tile_v INTEGER, tile_h INTEGER, tag TEXT, value TEXT, source INTEGER, adjacent TEXT);")\r
- self._conn.execute("CREATE TABLE IF NOT EXISTS airports (icao TEXT, tile_v INTEGER, tile_h INTEGER, latitude REAL, longitude REAL);")\r
- self._conn.execute("CREATE TABLE IF NOT EXISTS completion (tile_v INTEGER, tile_h INTEGER, tag TEXT, value TEXT, source INTEGER, adjacent TEXT);")\r
-\r
- \r
- # Insert data into their segments\r
- def insert_info(self, tv, th, tag, value, src, adj):\r
- self._conn.execute("INSERT INTO tiledata VALUES ( "+ str(tv) +", "+ str(th)+", '"+ tag +"', '"+ value +"', '"+ str(src) +"', '"+adj+"' );")\r
- \r
- # Insert data into the completion data\r
- def insert_completion_info(self, tv, th, tag, value, src, adj):\r
- self._conn.execute("INSERT INTO completion VALUES ( "+ str(tv) +", "+ str(th)+", '"+ tag +"', '"+ value +"', '"+ str(src) +"', '"+adj+"' );")\r
-\r
- # Insert an airport with ICAO code\r
- def insert_icao(self, icao, tv, th, lat, lng):\r
- self._conn.execute("INSERT INTO airports VALUES ('"+icao+"', "+str(tv)+", "+str(th)+", "+str(lat)+", "+str(lng)+");")\r
-\r
- # Commit a query or a number of queries\r
- def commit_query(self):\r
- self._conn.commit()\r
-\r
-\r
- # Retrieve the adjacency string for normal tile generation\r
- def get_adjacency_for_source(self, v, h, tag, value):\r
- r = self._crs.execute("SELECT * FROM tiledata where tile_v="+str(v)+" and tile_h="+str(h)+" and tag='"+tag+"' and value='"+value+"';")\r
- rws = r.fetchall()\r
- return rws\r
- \r
- # Retrieve the adjacency info for completion of a tile\r
- def get_adjacency_for_completion(self, v, h):\r
- r = self._crs.execute("SELECT * FROM completion where tile_v="+str(v)+" and tile_h="+str(h)+";")\r
- rws = r.fetchall()\r
- return rws\r
- \r
- # These calls are a bit more complex. We also need to know adjacency info when we are directly\r
- # next to another latitude or longitude. We want seamless generation in those situations too.\r
- def get_adjacency_for_source_in_lat_lng(self, lat, lng, v, h, tag, value):\r
- # The rows to return\r
- rws = []\r
-\r
- # For this we need to tap into the database of the tile, should there be one.\r
- dbn = mstr_datafolder + "Tiles/" + str(lat) + "_" + str(lng) + "/data.db"\r
- if os.path.isfile(dbn):\r
- tileconn = sqlite3.connect(dbn)\r
- tilecrsr = tileconn.cursor()\r
- r = tilecrsr.execute("SELECT * from tiledata WHERE tile_v="+str(v)+" AND tile_h="+str(h)+" AND tag='"+tag+"' AND value='"+value+"';")\r
- rws = r.fetchall()\r
- tileconn.close()\r
-\r
- return rws\r
- \r
- # These calls are a bit more complex. We also need to know adjacency info when we are directly\r
- # next to another latitude or longitude. We want seamless generation in those situations too.\r
- def get_adjacency_for_completion_in_lat_lng(self, lat, lng, v, h):\r
- # The rows to return\r
- rws = []\r
-\r
- # For this we need to tap into the database of the tile, should there be one.\r
- dbn = mstr_datafolder + "Tiles/" + str(lat) + "_" + str(lng) + "/data.db"\r
- if os.path.isfile(dbn):\r
- tileconn = sqlite3.connect(dbn)\r
- tilecrsr = tileconn.cursor()\r
- r = tilecrsr.execute("SELECT * from completion WHERE tile_v="+str(v)+" AND tile_h="+str(h)+";")\r
- rws = r.fetchall()\r
- tileconn.close()\r
-\r
- return rws\r
- \r
- # Acquire the highest latitude and longitude tile number of a neighbouring tile\r
- def get_highest_latlong_from_tile(self, lat, lng):\r
- latlng = [-1, -1]\r
- # For this we need to tap into the database of the tile, should there be one.\r
- dbn = mstr_datafolder + "Tiles/" + str(lat) + "_" + str(lng) + "/data.db"\r
- if os.path.isfile(dbn):\r
- tileconn = sqlite3.connect(dbn)\r
- tilecrsr = tileconn.cursor()\r
- lt = tilecrsr.execute("SELECT * FROM tiledata ORDER BY tile_v DESC")\r
- rws = lt.fetchall()\r
- lat = rws[0][0]\r
- ln = tilecrsr.execute("SELECT * FROM tiledata ORDER BY tile_h DESC")\r
- rws = ln.fetchall()\r
- lng = rws[0][1]\r
- latlng[0] = lat\r
- latlng[1] = lng\r
- tileconn.close()\r
- \r
- return latlng\r
-\r
-\r
- # Get all tiles with detected airports (ICAO codes)\r
- def get_tiles_with_airports(self):\r
- r = self._crs.execute("SELECT * FROM airports")\r
- rws = r.fetchall\r
- return rws\r
-\r
-\r
- # Perform a custom query and retrieve results\r
- def perform_query(self, qry):\r
- r = self._crs.execute(qry)\r
- rws = r.fetchall()\r
- return rws\r
-\r
-\r
- # Close DB\r
- def close_db(self):\r
- mstr_msg("tiledb", "Closing database connection")\r
- self._conn.close()\r
-\r
class mstr_tileinfo:
- def __init__(self, lat, lng, latlngfld):
+ def __init__(self, lat, lng, latnum, lngnum, latlngfld):
self._lat = lat
self._lng = lng
+ self._latnum = latnum
+ self._lngnum = lngnum
self._latlngfld = latlngfld
- self._adjfile = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/adjinfo"
+ self._adjfile = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/" + str(self._latnum) + "_" + str(self._lngnum)
+ #self._adjfile = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/adjinfo"
self._cplfile = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/cplinfo"
self.createDataFile()
self.createCompletionFile()
def get_adjacency_for_tag_and_value(self, tv, th, tag, value):
adj = []
fnlines = []
- with open(self._adjfile) as textfile:
- fnlines = textfile.readlines()
+ fn = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/" + str(tv) + "_" + str(th)
+ if os.path.isfile(fn) == True: # It is possible that the requested file does not yet exist
+ with open(fn) as textfile:
+ fnlines = textfile.readlines()
- for ln in fnlines:
- l = ln.split(" ")
- if int(l[0]) == tv and int(l[1]) == th:
- if l[2] == tag and l[3] == value:
- l[5] = l[5].replace("\n", "")
- adj.append(int(l[4]))
- adj.append(l[5])
- break
+ for ln in fnlines:
+ l = ln.split(" ")
+ if int(l[0]) == tv and int(l[1]) == th:
+ if l[2] == tag and l[3] == value:
+ l[5] = l[5].replace("\n", "")
+ adj.append(int(l[4]))
+ adj.append(l[5])
+ break
return adj
def get_adjacency_for_tag_and_value_in_lat_lng(self, lat, lng, tag, value, tv, th, brd):
latlngfld = self.latlng_folder([lat, lng])
adj = []
- fn = mstr_datafolder + "z_orthographic/data/" + latlngfld + "/adjinfo"
+ fn = mstr_datafolder + "z_orthographic/data/" + latlngfld + "/" + str(tv) + "_" + str(th)
if os.path.isfile(fn) == True:
fnlines = []
with open(fn) as textfile: