# Your data folder - meaning where the cache is stored, and where the finished
# tiles will go. This is also the folder where the image generation sources are
# stored.
-mstr_datafolder = "M:\\Developer\\Projects\\orthographic\\"
+mstr_datafolder = "M:/Developer/Projects/orthographic/"
# API endpoint to acquire OSM data (bonus: I have my own)
mstr_osm_endpoint = "https://marstr.online/osm/v1/"
("leisure", "golf_course", 35),
("leisure", "dog_park", 35),
("leisure", "garden", 20),
- ("leisure", "sports_centre", 15),
- ("leisure", "pitch", 5),
- ("landuse", "farmland", 15),
- ("landuse", "farmyard", 15),
+ ("leisure", "sports_centre", 5),
+ ("leisure", "pitch", 2),
+ ("landuse", "farmland", 10),
+ ("landuse", "farmyard", 10),
# Z-Order 2
("landuse", "forest", 20),
("leisure", "nature_reserve", 20),
("natural", "water", 20),
("natural", "bay", 30),
("natural", "beach", 30),
- ("water", "lake", 30),
- ("water", "pond", 30),
- ("water", "river", 30),
+ ("water", "lake", 20),
+ ("water", "pond", 20),
+ ("water", "river", 20),
("waterway", "river", 10),
("waterway", "stream", 10),
- ("amenity", "parking", 20),
+ ("amenity", "parking", 10),
("highway", "pedestrian", 12),
# Z-Order 4
("highway", "motorway", 5),
# Find out if we have a tiledata.json file at all
def doesTileDataExist(lat, lng):
e = False
- if os.path.isfile(mstr_datafolder + "Tiles\\" + str(lat) + "_" + str(lng) + "\\data.db"):
+ if os.path.isfile(mstr_datafolder + "Tiles/" + str(lat) + "_" + str(lng) + "/data.db"):
e = True
return e
# other effects.
def genborder(self, edgemask, tag, value):
layer = Image.new("RGBA", (self._imgsize, self._imgsize))
- root_folder = mstr_datafolder + "Textures\\" + tag + "\\" + value
+ root_folder = mstr_datafolder + "Textures/" + tag + "/" + value
# Determine which sources we use
- brd = glob.glob(root_folder + "\\brd\\b*.png")
+ brd = glob.glob(root_folder + "/brd/b*.png")
src = -1
if len(brd) == 1: src=1
if len(brd) >= 2:
src = randrange(1, len(brd))
- ptc = glob.glob(root_folder + "\\ptc\\b" + str(src) + "_p*.png")
+ ptc = glob.glob(root_folder + "/ptc/b" + str(src) + "_p*.png")
# Load in the sources to work with
- brd_src = Image.open(root_folder + "\\brd\\b" + str(src) + ".png")
+ brd_src = Image.open(root_folder + "/brd/b" + str(src) + ".png")
ptc_src = []
for p in ptc:
ptc_src.append(Image.open(p))
# Before we generate the layer, let's check for airports in this chunk
mstr_msg("layergen", "Checking for airport/s with ICAO code")
osmxml = mstr_osmxml(0,0)
- icao = osmxml.find_icao_codes(mstr_datafolder + "_cache\\tile.xml")
+ icao = osmxml.find_icao_codes(mstr_datafolder + "_cache/tile.xml")
mstr_msg("layergen", "Found " + str(len(icao)) + " airport/s")
# Runway surface, if any other than concrete/asphalt
rw_surface = ""
if len(iccheck) == 0:
self._tiledb.insert_icao(i, self._lat_number, self._lng_number, self._latitude, self._longitude)
mstr_msg("layergen", "Airport/s noted in data file")
- rw_surface = osmxml.find_runway_surface(mstr_datafolder + "_cache\\tile.xml")
+ rw_surface = osmxml.find_runway_surface(mstr_datafolder + "_cache/tile.xml")
# The image for the layer itself
layer = Image.new("RGBA", (self._imgsize, self._imgsize))
if (self._isline == False and self._tag != "building") or (self._is_completion == True):
# Determine where we get the our source material from
- root_folder = mstr_datafolder + "Textures\\"
+ root_folder = mstr_datafolder + "Textures/"
for s in mstr_ortho_layers:
if s[0] == self._tag and s[1] == self._value:
fld_main = len(s)-2
fld_sub = len(s)-1
- root_folder = root_folder + s[fld_main] + "\\" + s[fld_sub]
+ root_folder = root_folder + s[fld_main] + "/" + s[fld_sub]
# Determine which sources to use.
# First, we need to check for adjacent tile information. We then either
self._tag = al[0][2]
self._value = al[0][3]
- root_folder = mstr_datafolder + "Textures\\"
+ root_folder = mstr_datafolder + "Textures/"
for s in mstr_ortho_layers:
if s[0] == self._tag and s[1] == self._value:
fld_main = len(s)-2
fld_sub = len(s)-1
- root_folder = root_folder + s[fld_main] + "\\" + s[fld_sub]
+ root_folder = root_folder + s[fld_main] + "/" + s[fld_sub]
# We are south to the top tile.
if len(at) == 1 and src == -1:
self._tag = ald[0][2]
self._value = ald[0][3]
- root_folder = mstr_datafolder + "Textures\\"
+ root_folder = mstr_datafolder + "Textures/"
for s in mstr_ortho_layers:
if s[0] == self._tag and s[1] == self._value:
fld_main = len(s)-2
fld_sub = len(s)-1
- root_folder = root_folder + s[fld_main] + "\\" + s[fld_sub]
+ root_folder = root_folder + s[fld_main] + "/" + s[fld_sub]
# Should we get here and one of the degree border checks turns out true,
mstr_msg("layergen", "Adjacency check completed")
- brd = glob.glob(root_folder + "\\brd\\b*.png")
+ brd = glob.glob(root_folder + "/brd/b*.png")
# If the adjacency check returned nothing (src is still -1),
# then pick something
if len(brd) >= 2:
src = randrange(1, len(brd))
- ptc = glob.glob(root_folder + "\\ptc\\b" + str(src) + "_p*.png")
+ ptc = glob.glob(root_folder + "/ptc/b" + str(src) + "_p*.png")
# Load in the sources to work with
- brd_src = Image.open(root_folder + "\\brd\\b" + str(src) + ".png")
+ brd_src = Image.open(root_folder + "/brd/b" + str(src) + ".png")
ptc_src = []
for p in ptc:
ptc_src.append(Image.open(p))
# OK! Load the mask
if self._is_completion == False:
- osm_mask = Image.open( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + ".png" )
+ osm_mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + ".png" )
if self._is_completion == True:
- osm_mask = Image.open( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion.png" )
+ osm_mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion.png" )
# Generate an edge mask from the original
osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)
amt = randrange(1,5)
for i in range(1, amt):
ptc = randrange(1, 14)
- img = Image.open(mstr_datafolder + "Textures\\tile\\completion\\p" + str(ptc)+".png")
+ img = Image.open(mstr_datafolder + "Textures/tile/completion/p" + str(ptc)+".png")
lx = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.width )
ly = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.height )
layer.alpha_composite( img, (lx, ly) )
# Store layer
if self._is_completion == False:
- layer_comp.save( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )
+ layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )
if self._is_completion == True:
- layer_comp.save( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion_layer.png" )
- #layer_final.save( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )
+ layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion_layer.png" )
+ #layer_final.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )
mstr_msg("layergen", "Layer image finalized and saved.")
ca = a * st
aa = int(ca)
shadow_pix[shf_x, y] = (0,0,0,aa)
- shadow.save(mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_shadow.png")
+ shadow.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_shadow.png")
mstr_msg("layergen", "Shadow layer completed")
if self._isline == True or self._tag == "building":
# We will need the mask in question
- osm_mask = Image.open( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + ".png" )
+ osm_mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + ".png" )
# Generate an edge mask from the original
osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)
for i in range(1, numtrees):
# Pick some file
pick = str(randrange(1, 11))
- tree = Image.open(mstr_datafolder + "Textures\\building\\area\\p" + pick + ".png")
+ tree = Image.open(mstr_datafolder + "Textures/building/area/p" + pick + ".png")
trees.alpha_composite(tree, (shf_x, shf_y))
#layer_comp.paste(tree, (shf_x, shf_y))
trees.alpha_composite(layer_comp)
aa = int(ca)
shadow_pix[shf_x, y] = (0,0,0,aa)
shadow_pix[shf_x2, y] = (0,0,0,aa)
- shadow.save(mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_shadow.png")
+ shadow.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_shadow.png")
mstr_msg("layergen", "Shadow layer completed")
# Highways and runways of any kind get some special treatment
layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=4))
# Store layer
- layer_comp.save( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )
+ layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )
mstr_msg("layergen", "Layer image finalized and saved.")
if mstr_photores == 4096: imgsize=6000
mask_img = Image.new("RGBA", (imgsize, imgsize))
- tilexml = mstr_datafolder + "_cache\\tile.xml"
+ tilexml = mstr_datafolder + "_cache/tile.xml"
xml = mstr_osmxml(0,0)
fstr = str(self._box[0]) + "-" + str(self._box[1]) + "_" + str(self._box[2]) + "-" + str(self._box[3])
nds = xml.acquire_nodes(tilexml)
imgd.line(pts, fill="#000000", width=mstr_ortho_layers[idx][2], joint="curve")
# Save image
- mask_img.save(mstr_datafolder + "_cache\\" + fstr + "_" + self._tag + "-" + self._value + ".png")
+ mask_img.save(mstr_datafolder + "_cache/" + fstr + "_" + self._tag + "-" + self._value + ".png")
# Inform
mstr_msg("maskgen", "Mask built.")
mstr_msg("orthographic", "Adjusted bounding box for XML object")
# Determine what to do... maybe work was interrupted
- if os.path.isfile(mstr_datafolder + "Tiles\\" + str(self._lat) + "_" + str(self._long) + "\\Textures\\" + str(cur_tile_y) + "_" + str(cur_tile_x) + ".jpg") == False:
+ if os.path.isfile(mstr_datafolder + "Tiles/" + str(self._lat) + "_" + str(self._long) + "/Textures/" + str(cur_tile_y) + "_" + str(cur_tile_x) + ".jpg") == False:
# Let the user know
mstr_msg("orthographic", "Generating missing orthophoto " + str(cur_tile_y) + "-" + str(cur_tile_x))
mstr_msg("orthographic", "Beginning generation of layers")
# Generate the Tiles/lat-lng folder for the finished tile
- if not os.path.exists(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long) + "\\Textures"):
- os.makedirs(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long)+"\\Textures")
+ if not os.path.exists(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long) + "/Textures"):
+ os.makedirs(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long)+"/Textures")
mstr_msg("orthographic", "Created tile textures folder")
# Generate the Tiles/terrain folder for the finished tile
- if not os.path.exists(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long) + "\\terrain"):
- os.makedirs(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long)+"\\terrain")
+ if not os.path.exists(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long) + "/terrain"):
+ os.makedirs(self._output + "/Tiles/"+str(self._lat)+"_"+str(self._long)+"/terrain")
mstr_msg("orthographic", "Created tile terrain folder")
curlyr = 1
# Clear out cache
if mstr_clear_cache == True:
- ch = glob.glob(mstr_datafolder + "_cache\\*")
+ ch = glob.glob(mstr_datafolder + "_cache/*")
for f in ch:
if os_platform == "nt":
if self._isFileAccessibleWin(f) == True:
mstr_msg("orthographic", "Final step completed.")
print("")
print("")
- mstr_msg("orthographic", "Tile data in: " + mstr_datafolder + "\\Tiles\\" + str(self._lat) + "_" + self._lng)
+ mstr_msg("orthographic", "Tile data in: " + mstr_datafolder + "/Tiles/" + str(self._lat) + "_" + self._lng)
mstr_msg("orthographic", "Orthos are in the Textures subfolder")
mstr_msg("orthographic", "X-Plane .ter's are in the terrain subfolder")
print("")
layers = []
- tilexml = mstr_datafolder + "_cache\\tile.xml"
+ tilexml = mstr_datafolder + "_cache/tile.xml"
xml = mstr_osmxml(0,0)
way = xml.acquire_waypoint_data(tilexml)
rls = xml.acquire_relations(tilexml)
}
r = requests.post(mstr_osm_endpoint, json=data)
- xml = mstr_datafolder + "_cache\\tile.xml"
+ xml = mstr_datafolder + "_cache/tile.xml"
if os.path.isfile(xml):
os.remove(xml)
with open(xml, 'wb') as textfile:
# This puts it all together. Bonus: AND saves it.
def genphoto(self):
# Template for the file name which is always the same
- root_filename = mstr_datafolder + "\\_cache\\" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_"
+ root_filename = mstr_datafolder + "/_cache/" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_"
# First, we walk through all layers and blend them on top of each other, in order
mstr_msg("photogen", "Merging layers")
self._tile = self._tile.resize((mstr_photores, mstr_photores), Image.Resampling.BILINEAR)
# This we can save accordingly.
- self._tile.convert('RGB').save(mstr_datafolder + "Tiles\\" + str(self._lat) + "_" + str(self._lng) + "\\Textures\\" + str(self._ty) + "_" + str(self._tx) + ".jpg", format='JPEG', subsampling=0, quality=100)
+ self._tile.convert('RGB').save(mstr_datafolder + "Tiles/" + str(self._lat) + "_" + str(self._lng) + "/Textures/" + str(self._ty) + "_" + str(self._tx) + ".jpg", format='JPEG', subsampling=0, quality=100)
# This checks the final image for empty patches. Should one be
# We do not apply any blur or other effects here - we only want the
# exact pixel positions.
- mask.save( mstr_datafolder + "_cache\\" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_tile-completion.png" )
+ mask.save( mstr_datafolder + "_cache/" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "_tile-completion.png" )
mstr_msg("photogen", "Generated and saved empty space mask")
\ No newline at end of file
self._longitude = lng
# The db file will be created, should it not exist
- self._conn = sqlite3.connect(mstr_datafolder + "Tiles\\" + str(self._latitude) + "_" + str(self._longitude) + "\\data.db")
+ self._conn = sqlite3.connect(mstr_datafolder + "Tiles/" + str(self._latitude) + "_" + str(self._longitude) + "/data.db")
self._crs = self._conn.cursor()
#mstr_msg("tiledb", "Database object initiated")
rws = []
# For this we need to tap into the database of the tile, should there be one.
- dbn = mstr_datafolder + "Tiles\\" + str(lat) + "_" + str(lng) + "\\data.db"
+ dbn = mstr_datafolder + "Tiles/" + str(lat) + "_" + str(lng) + "/data.db"
if os.path.isfile(dbn):
tileconn = sqlite3.connect(dbn)
tilecrsr = tileconn.cursor()
rws = []
# For this we need to tap into the database of the tile, should there be one.
- dbn = mstr_datafolder + "Tiles\\" + str(lat) + "_" + str(lng) + "\\data.db"
+ dbn = mstr_datafolder + "Tiles/" + str(lat) + "_" + str(lng) + "/data.db"
if os.path.isfile(dbn):
tileconn = sqlite3.connect(dbn)
tilecrsr = tileconn.cursor()
def get_highest_latlong_from_tile(self, lat, lng):
latlng = [-1, -1]
# For this we need to tap into the database of the tile, should there be one.
- dbn = mstr_datafolder + "Tiles\\" + str(lat) + "_" + str(lng) + "\\data.db"
+ dbn = mstr_datafolder + "Tiles/" + str(lat) + "_" + str(lng) + "/data.db"
if os.path.isfile(dbn):
tileconn = sqlite3.connect(dbn)
tilecrsr = tileconn.cursor()
for lt in range(1, steps_lat):
for ln in range(1, steps_lng):
# Check if we need to do something
- if os.path.isfile(mstr_datafolder + "Tiles\\" + str(self._lat) + "_" + str(self._lng) + "\\Textures\\" + str(self._lat) + "-" + str(ln) + "_" + str(self._lng) + "-" + str(lt) + "_OG16.jpg") == False:
+ if os.path.isfile(mstr_datafolder + "Tiles/" + str(self._lat) + "_" + str(self._lng) + "/Textures/" + str(self._lat) + "-" + str(ln) + "_" + str(self._lng) + "-" + str(lt) + "_OG16.jpg") == False:
mstr_msg("tilegen", "Generating missing zoom level 16 ortho " + str(self._lat) + "-" + str(ln) + "_" + str(self._lng) + "-" + str(lt) + "_OG16.jpg")
for j in range(0, 3):
# We may run into situations where ask for tiles that don't exist...
# Let's make sure we can continue
- fpath = mstr_datafolder + "Tiles\\" + str(self._lat) + "_" + str(self._lng) + "\\Textures\\" + str(tiles[i][j][0]) + "_" + str(tiles[i][j][1]) + ".jpg"
+ fpath = mstr_datafolder + "Tiles/" + str(self._lat) + "_" + str(self._lng) + "/Textures/" + str(tiles[i][j][0]) + "_" + str(tiles[i][j][1]) + ".jpg"
if os.path.isfile( fpath ):
tlimg = Image.open(fpath)
tlimg = tlimg.resize((scaled_res,scaled_res), Image.Resampling.BILINEAR)
ypos = ypos - scaled_res
# Now save this image
- zl16.save(mstr_datafolder + "Tiles\\" + str(self._lat) + "_" + str(self._lng) + "\\Textures\\" + str(self._lat) + "-" + str(ln) + "_" + str(self._lng) + "-" + str(lt) + "_OG16.jpg", format='JPEG', subsampling=0, quality=100)
+ zl16.save(mstr_datafolder + "Tiles/" + str(self._lat) + "_" + str(self._lng) + "/Textures/" + str(self._lat) + "-" + str(ln) + "_" + str(self._lng) + "-" + str(lt) + "_OG16.jpg", format='JPEG', subsampling=0, quality=100)
# Store a terrain file
dmt = self._findWidthOfLongitude(a_lat) * mstr_zl_16
LOAD_CENTER """ + str(a_lat) + " " + str(a_lng) + " " + str(dmt) + " " + "../Textures/" + str(self._lat) + "-" + str(ln) + "_" + str(self._lng) + "-" + str(lt) + "_OG_16.jpg"+"""
NO_ALPHA"""
- with open(mstr_datafolder + "\\Tiles\\"+str(self._lat)+"_"+str(self._lng)+"\\terrain\\"+str(self._lat)+"_"+str(lt)+"-"+str(self._lng)+"-"+str(ln)+"_OG16.ter", 'w') as textfile:
+ with open(mstr_datafolder + "/Tiles/"+str(self._lat)+"_"+str(self._lng)+"/terrain/"+str(self._lat)+"_"+str(lt)+"-"+str(self._lng)+"-"+str(ln)+"_OG16.ter", 'w') as textfile:
textfile.write(ter_content)
mstr_msg("tilegen", "Wrote .ter file")
found = True
break
if found == False:
- os.remove(mstr_datafolder + "\\Tiles\\" + str(self._lat) + "_" + str(self._lng) + "\\Textures\\" + fn)
+ os.remove(mstr_datafolder + "/Tiles/" + str(self._lat) + "_" + str(self._lng) + "/Textures/" + fn)
mstr_msg("tilegen", "Cleanup completed")
k_lat = self._lat + (k[0] * self._vstep) + (self._vstep * 0.5)
k_lng = self._lat + (k[1] * mstr_zl_18) + (mstr_zl_18 * 0.5)
k_dmt = self._findWidthOfLongitude(self._lng * mstr_zl_18)
- k_fln = mstr_datafolder + "\\Tiles\\" + str(self._lat) + "_" + str(self._lng) + "\\terrain\\" + str(k[0]) + "_" + str(k[1]) + ".ter"
+ k_fln = mstr_datafolder + "/Tiles/" + str(self._lat) + "_" + str(self._lng) + "/terrain/" + str(k[0]) + "_" + str(k[1]) + ".ter"
ter_content = """A
800
TERRAIN