return layer_final\r
\r
\r
+ # Find the source to use pre-determined in phase one\r
+ def findLayerSource(self):\r
+ # The source number\r
+ src = -1\r
+\r
+ # The already existing source data\r
+ srcfile = mstr_datafolder + "z_orthographic/data/" + self._latlngfld + "/" + str(self._lat_number) + "_" + str(self._lng_number)\r
+\r
+ # Let's open the file and find our entry\r
+ with open(srcfile) as file:\r
+ for line in file:\r
+ linedata = line.split(" ")\r
+ if linedata[2] == self._tag and linedata[3] == self._value:\r
+ src = int(linedata[4])\r
+ break\r
+ \r
+ # Should we encounter a -1 at this point, we can choose something\r
+ # It means it touches no border as it was not found in the file\r
+ if src == -1:\r
+ root_folder = mstr_datafolder + "textures/"\r
+ for s in mstr_ortho_layers:\r
+ if s[0] == self._tag and s[1] == self._value:\r
+ fld_main = len(s)-2\r
+ fld_sub = len(s)-1\r
+ root_folder = root_folder + s[fld_main] + "/" + s[fld_sub]\r
+ \r
+ brd = glob.glob(root_folder + "/brd/b*.png")\r
+ src = randrange(1, len(brd)+1)\r
+\r
+ return src\r
+\r
+\r
+\r
# This generates the layer from the defined mask\r
- def genlayer(self):\r
+ def genlayer(self, mask, xml):\r
\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
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
- mstr_msg("layergen", "Found " + str(len(icao)) + " airport/s")\r
+ \r
+ icao = None\r
+ if xml != None:\r
+ icao = xml.find_icao_codes()\r
+ mstr_msg("layergen", "Found " + str(len(icao)) + " airport/s")\r
# Runway surface, if any other than concrete/asphalt\r
rw_surface = ""\r
# If we find an airport, make a note ...\r
- if len(icao) >= 1:\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
- rw_surface = osmxml.find_runway_surface(mstr_datafolder + "_cache/tile.xml")\r
+ if icao != None:\r
+ if len(icao) >= 1 and self._is_completion == False:\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
+ rw_surface = xml.find_runway_surface()\r
\r
# The image for the layer itself\r
layer = Image.new("RGBA", (self._imgsize, self._imgsize))\r
root_folder = root_folder + s[fld_main] + "/" + s[fld_sub]\r
\r
# Determine which sources to use.\r
- # First, we need to check for adjacent tile information. We then either\r
- # need to use the source of any adjacent tile, or we can choose freely.\r
- src = -1\r
- \r
- # Find our adjacent tiles\r
- adjtiles = findAdjacentTilesTo(self._lat_number, self._lng_number)\r
-\r
- mstr_msg("layergen", "Performing adjacency check")\r
- # Walk through each tile and see what we can find in relation to this\r
- # tile in the center\r
- # Since we already know the order in adjtiles, we can do this real easy\r
- if self._is_completion == False:\r
- at = self._tileinfo.get_adjacency_for_tag_and_value(adjtiles[0][0], adjtiles[0][1], self._tag, self._value) # Top\r
- ar = self._tileinfo.get_adjacency_for_tag_and_value(adjtiles[1][0], adjtiles[1][1], self._tag, self._value) # Right\r
- ab = self._tileinfo.get_adjacency_for_tag_and_value(adjtiles[2][0], adjtiles[2][1], self._tag, self._value) # Bottom\r
- al = self._tileinfo.get_adjacency_for_tag_and_value(adjtiles[3][0], adjtiles[3][1], self._tag, self._value) # Left\r
- #at = self._tiledb.get_adjacency_for_source(adjtiles[0][0], adjtiles[0][1], self._tag, self._value) # Top\r
- #ar = self._tiledb.get_adjacency_for_source(adjtiles[1][0], adjtiles[1][1], self._tag, self._value) # Right\r
- #ab = self._tiledb.get_adjacency_for_source(adjtiles[2][0], adjtiles[2][1], self._tag, self._value) # Bottom\r
- #al = self._tiledb.get_adjacency_for_source(adjtiles[3][0], adjtiles[3][1], self._tag, self._value) # Left\r
- if self._is_completion == True:\r
- at = self._tileinfo.get_adjacency_for_completion(adjtiles[0][0], adjtiles[0][1]) # Top\r
- ar = self._tileinfo.get_adjacency_for_completion(adjtiles[1][0], adjtiles[1][1]) # Right\r
- ab = self._tileinfo.get_adjacency_for_completion(adjtiles[2][0], adjtiles[2][1]) # Bottom\r
- al = self._tileinfo.get_adjacency_for_completion(adjtiles[3][0], adjtiles[3][1]) # Left\r
- #at = self._tiledb.get_adjacency_for_completion(adjtiles[0][0], adjtiles[0][1]) # Top\r
- #ar = self._tiledb.get_adjacency_for_completion(adjtiles[1][0], adjtiles[1][1]) # Right\r
- #ab = self._tiledb.get_adjacency_for_completion(adjtiles[2][0], adjtiles[2][1]) # Bottom\r
- #al = self._tiledb.get_adjacency_for_completion(adjtiles[3][0], adjtiles[3][1]) # Left\r
-\r
- if len(at) == 4:\r
- self._tag = at[0]\r
- self._value = at[1]\r
- if len(ar) == 4:\r
- self._tag = ar[0]\r
- self._value = ar[1]\r
- if len(ab) == 4:\r
- self._tag = ab[0]\r
- self._value = ab[1]\r
- if len(al) == 4:\r
- self._tag = al[0]\r
- self._value = al[1]\r
-\r
- root_folder = mstr_datafolder + "textures/"\r
- for s in mstr_ortho_layers:\r
- if s[0] == self._tag and s[1] == self._value:\r
- fld_main = len(s)-2\r
- fld_sub = len(s)-1\r
- root_folder = root_folder + s[fld_main] + "/" + s[fld_sub]\r
-\r
- # We are south to the top tile.\r
- if len(at) == 2 and src == -1:\r
- if "b" in at[1]: src = at[0]\r
- # We are west to the right tile.\r
- if len(ar) == 2 and src == -1:\r
- if "l" in ar[1]: src = ar[0]\r
- # We are north to the bottom tile.\r
- if len(ab) == 2 and src == -1:\r
- if "t" in ab[1]: src = ab[0]\r
- # We are east to the left tile.\r
- if len(al) == 2 and src == -1:\r
- if "r" in al[1]: src = al[0]\r
-\r
- # Should we be at the border of the degree for latitude and longitude, we need to perform\r
- # additional checks\r
- is_deg_brd_t = False\r
- is_deg_brd_r = False\r
- is_deg_brd_b = False\r
- is_deg_brd_l = False\r
- if self._lat_number == 1: is_deg_brd_b = True\r
- if self._lat_number == self._maxlat: is_deg_brd_t = True\r
- if self._lng_number == 1: is_deg_brd_l = True\r
- if self._lng_number == self._maxlng: is_deg_brd_r = True\r
-\r
- # Adjacent latitude and longitude tiles\r
- deg_tiles = []\r
- deg_tiles.append( ( self._latitude+1, self._longitude ) ) # Top\r
- deg_tiles.append( ( self._latitude, self._longitude+1 ) ) # Right\r
- deg_tiles.append( ( self._latitude-1, self._longitude ) ) # Bottom\r
- deg_tiles.append( ( self._latitude, self._longitude-1 ) ) # Left\r
-\r
- # Perform degree border checks\r
- # - and make sure we do not run into errors - this drove me crazy in testing\r
- atd = []\r
- ard = []\r
- abd = []\r
- ald = []\r
- if is_deg_brd_t == True:\r
- if self._is_completion == False:\r
- atd = self._tileinfo.get_adjacency_for_tag_and_value_in_lat_lng(deg_tiles[0][0], deg_tiles[0][1], self._tag, self._value, 1, self._lng_number, "b") # Top\r
- #atd = self._tiledb.get_adjacency_for_source_in_lat_lng(deg_tiles[0][0], deg_tiles[0][1], 1, self._lng_number, self._tag, self._value) # Top\r
- if self._is_completion == True:\r
- atd = self._tileinfo.get_completion_in_lat_lng(deg_tiles[0][0], deg_tiles[0][1], 1, self._lng_number, "b")\r
- #atd = self._tiledb.get_adjacency_for_completion_in_lat_lng(deg_tiles[0][0], deg_tiles[0][1], 1, self._lng_number) # Top\r
- \r
- if is_deg_brd_r == True:\r
- if self._is_completion == False:\r
- ard = self._tileinfo.get_adjacency_for_tag_and_value_in_lat_lng(deg_tiles[1][0], deg_tiles[1][1], self._tag, self._value, self._lat_number, 1, "l") # Right\r
- #ard = self._tiledb.get_adjacency_for_source_in_lat_lng(deg_tiles[1][0], deg_tiles[1][1], self._lat_number, 1, self._tag, self._value) # Right\r
- if self._is_completion == True:\r
- ard = self._tileinfo.get_completion_in_lat_lng(deg_tiles[1][0], deg_tiles[1][1], self._lat_number, 1, "l")\r
- #ard = self._tiledb.get_adjacency_for_completion_in_lat_lng(deg_tiles[1][0], deg_tiles[1][1], self._lat_number, 1) # Right\r
- \r
- if is_deg_brd_b == True:\r
- #maxlatlng = self._tiledb.get_highest_latlong_from_tile(self._latitude-1, self._longitude)\r
- if self._is_completion == False:\r
- abd = self._tileinfo.get_adjacency_for_tag_and_value_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], self._tag, self._value, self._lat_number, self._lng_number, "t")\r
- #abd = self._tiledb.get_adjacency_for_source_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], maxlatlng[0], self._lng_number, self._tag, self._value) # Bottom\r
- if self._is_completion == True:\r
- abd = self._tileinfo.get_completion_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], self._lat_number, self._lng_number, "t")\r
- #abd = self._tiledb.get_adjacency_for_completion_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], maxlatlng[0], self._lng_number) # Bottom\r
- \r
- if is_deg_brd_l == True:\r
- #maxlatlng = self._tiledb.get_highest_latlong_from_tile(self._latitude, self._longitude-1)\r
- if self._is_completion == False:\r
- ald = self._tileinfo.get_adjacency_for_tag_and_value_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], self._tag, self._value, self._lat_number, self._lng_number, "r")\r
- #ald = self._tiledb.get_adjacency_for_source_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], self._lat_number, maxlatlng[1], self._tag, self._value) # Left\r
- if self._is_completion == True:\r
- ald = self._tileinfo.get_completion_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], self._lat_number, self._lng_number, "r")\r
- #ald = self._tiledb.get_adjacency_for_completion_in_lat_lng(deg_tiles[2][0], deg_tiles[2][1], self._lat_number, maxlatlng[1]) # Left\r
-\r
- if (is_deg_brd_t == True or is_deg_brd_r == True or is_deg_brd_b == True or is_deg_brd_l == True):\r
- if src == -1 and self._is_completion == True:\r
- if len(atd) == 4:\r
- self._tag = atd[0]\r
- self._value = atd[1]\r
- if len(ard) == 4:\r
- self._tag = ard[0]\r
- self._value = ard[1]\r
- if len(abd) == 4:\r
- self._tag = abd[0]\r
- self._value = abd[1]\r
- if len(ald) == 4:\r
- self._tag = ald[0]\r
- self._value = ald[1]\r
-\r
- root_folder = mstr_datafolder + "textures/"\r
- for s in mstr_ortho_layers:\r
- if s[0] == self._tag and s[1] == self._value:\r
- fld_main = len(s)-2\r
- fld_sub = len(s)-1\r
- root_folder = root_folder + s[fld_main] + "/" + s[fld_sub]\r
-\r
-\r
- # Should we get here and one of the degree border checks turns out true,\r
- # we need to make sure that we select the source we found. This should\r
- # enable seamless tiling... around the entire planet\r
- if is_deg_brd_t == True and len(at) == 0 and src == -1:\r
- if len(atd) == 2:\r
- if "b" in atd[3]: src = int(atd[2])\r
- if is_deg_brd_r == True and len(ar) == 0 and src == -1:\r
- if len(ard) == 2:\r
- if "l" in ard[3]: src = int(ard[2])\r
- if is_deg_brd_b == True and len(ab) == 0 and src == -1:\r
- if len(abd) == 2:\r
- if "t" in abd[3]: src = int(abd[2])\r
- if is_deg_brd_l == True and len(al) == 0 and src == -1:\r
- if len(ald) == 2:\r
- if "r" in ald[3]: src = int(ald[2])\r
- \r
- mstr_msg("layergen", "Adjacency check completed")\r
-\r
- brd = glob.glob(root_folder + "/brd/b*.png")\r
-\r
- # If the adjacency check returned nothing (src is still -1),\r
- # then pick something\r
- if src == -1:\r
- if len(brd) == 1: src=1\r
- if len(brd) >= 2:\r
- src = randrange(1, len(brd)+1)\r
+ src = self.findLayerSource()\r
\r
ptc = glob.glob(root_folder + "/ptc/b" + str(src) + "_p*.png")\r
\r
ptc_src.append(Image.open(p))\r
mstr_msg("layergen", "Layer sources selected")\r
\r
+ """\r
# OK! Load the mask\r
if self._is_completion == False:\r
- 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" )\r
+ 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" )\r
if self._is_completion == True:\r
- osm_mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion.png" )\r
+ mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion.png" )\r
+ """\r
\r
# Generate an edge mask from the original\r
- osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)\r
+ osm_edge = mask.filter(ImageFilter.FIND_EDGES)\r
osm_edge = osm_edge.filter(ImageFilter.MaxFilter)\r
mstr_msg("layergen", "Edge mask generated")\r
\r
# This adds some natural looking shapes to these types of features\r
if self._value == "forest" or self._value == "nature_reserve":\r
epx = osm_edge.load()\r
- imgd = ImageDraw.Draw(osm_mask)\r
+ imgd = ImageDraw.Draw(mask)\r
\r
- # Walk through a grid of 200x200 - on the edge image\r
- for y in range(0, osm_mask.height, int(osm_mask.height/200)):\r
- for x in range(0, osm_mask.width, int(osm_mask.width/200)):\r
+ # Walk through a grid of 100x100 - on the edge image\r
+ for y in range(0, mask.height, int(mask.height/100)):\r
+ for x in range(0, mask.width, int(mask.width/100)):\r
px = epx[x,y]\r
if px[3] == 255:\r
rx = randrange(24,60)\r
psy = randrange(y-11, y+11)\r
\r
# Do some magic - but not on edges\r
- if x > 0 and x < osm_mask.width and y > 0 and y < osm_mask.height:\r
+ if x > 0 and x < mask.width and y > 0 and y < mask.height:\r
if f != 5:\r
imgd.ellipse((psx-int(rx/2), psy-int(ry/2), psx+rx, psy+ry), fill="black")\r
if f == 3 or f == 7:\r
\r
# We need to change the image in certain conditions\r
if self._value == "hedge" and self._tag == "barrier":\r
- osm_mask = osm_edge\r
+ mask = osm_edge\r
\r
# From here on in we will need to perform some adjustments on the masks, depending\r
# on what they are.\r
for i in mstr_mask_blur:\r
if i[0] == self._tag and i[1] == self._value:\r
if self._tag != "place" and (self._value != "sea" or self._value != "ocean"): \r
- osm_mask = osm_mask.filter(ImageFilter.BoxBlur(radius=i[2]))\r
+ mask = mask.filter(ImageFilter.BoxBlur(radius=i[2]))\r
break\r
\r
# Begin producing a largely random image\r
ly = randrange( self._imgsize - img.height )\r
layer.alpha_composite( img, (lx, ly) )\r
if self._is_completion == True:\r
- mp = osm_mask.load()\r
+ mp = mask.load()\r
edn = self.xplane_latlng_folder(self.find_earthnavdata_number())\r
idx = 0\r
for r in mstr_completion_colors:\r
# Generate the layer from the mask.\r
layer_comp = Image.new("RGBA", (self._imgsize, self._imgsize))\r
layer_pix = layer.load()\r
- mask_pix = osm_mask.load()\r
+ mask_pix = mask.load()\r
layer_comp_pix = layer_comp.load()\r
for y in range(self._imgsize):\r
for x in range(self._imgsize):\r
# Here we want to make sure that the generated image fits well with others, so\r
# let's do that.\r
mstr_msg("layergen", "Generating adjacent fades")\r
- self.generate_adjacent_fades()\r
+ adjfade = self.generate_adjacent_fades(mask)\r
\r
# Determine if there are any fades, and if so, fade those in first before we save the layer\r
+ """\r
fade_fn = mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value\r
if os.path.isfile(fade_fn + "_fade_top.png") == True:\r
fade = Image.open(fade_fn + "_fade_top.png")\r
if os.path.isfile(fade_fn + "_fade_left.png") == True:\r
fade = Image.open(fade_fn + "_fade_left.png")\r
layer_comp.alpha_composite(fade)\r
+ """\r
+\r
+ layer_comp.alpha_composite(adjfade)\r
mstr_msg("layergen", "Adjacent fading completed")\r
\r
\r
layer_comp_pix[x,y] = (lpix[0], lpix[1], lpix[2], 255-rpix[3])\r
\r
# Store layer\r
- if self._is_completion == False:\r
- 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" )\r
- if self._is_completion == True:\r
- layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion_layer.png" )\r
+ #if self._is_completion == False:\r
+ # 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" )\r
+ #if self._is_completion == True:\r
+ # layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_tile-completion_layer.png" )\r
#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" )\r
mstr_msg("layergen", "Layer image finalized and saved.")\r
\r
break\r
if nm == True:\r
nrm = mstr_xp_normalmap(self._latitude, self._longitude, self._tag, self._value, self._lat_number, self._lng_number, self._latlngfld)\r
- nrm.build_normalmap()\r
+ nrm.build_normalmap(layer_comp)\r
\r
\r
# Let's try our hand at pseudo shadows\r
if self._tag == sh[0] and self._value == sh[1]:\r
mstr_msg("layergen", "Generating shadow for layer")\r
shadow_pix = shadow.load()\r
- mask_pix = osm_mask.load()\r
+ mask_pix = mask.load()\r
shf = 1\r
while shf < mstr_shadow_shift:\r
for y in range(self._imgsize):\r
\r
shadow = shadow.filter(ImageFilter.GaussianBlur(radius=1.5))\r
\r
- 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")\r
+ #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")\r
+ shadow.alpha_composite(layer_comp)\r
+ layer_comp = shadow\r
mstr_msg("layergen", "Shadow layer completed")\r
\r
\r
-\r
- # Check if pixels touch the borders of the image, and if so -\r
- # make a not of that in the database.\r
- at=False\r
- ar=False\r
- ab=False\r
- al=False\r
- layer_pix = layer_comp.load() # <- Just to be safe\r
-\r
- # Top scan\r
- for i in range(0, self._imgsize-1):\r
- p = layer_pix[i,0]\r
- if p[3] > 0:\r
- at=True\r
- break\r
- \r
- # Right scan\r
- for i in range(0, self._imgsize-1):\r
- p = layer_pix[self._imgsize-1,i]\r
- if p[3] > 0:\r
- ar=True\r
- break\r
- \r
- # Bottom scan\r
- for i in range(0, self._imgsize-1):\r
- p = layer_pix[i,self._imgsize-1]\r
- if p[3] > 0:\r
- ab=True\r
- break\r
- \r
- # Left scan\r
- for i in range(0, self._imgsize-1):\r
- p = layer_pix[1,i]\r
- if p[3] > 0:\r
- al=True\r
- break\r
- \r
- # Construct DB String\r
- adjstr = ""\r
- if at==True: adjstr = adjstr + "t"\r
- if ar==True: adjstr = adjstr + "r"\r
- if ab==True: adjstr = adjstr + "b"\r
- if al==True: adjstr = adjstr + "l"\r
-\r
- # Store into DB - but only if there is something to store\r
- if adjstr != "":\r
- if self._is_completion == False:\r
- r = self._tileinfo.get_adjacency_for_tag_and_value(self._lat_number, self._lng_number, self._tag, self._value)\r
- #r = self._tiledb.get_adjacency_for_source(self._lat_number, self._lng_number, self._tag, self._value)\r
- if len(r) == 0:\r
- self._tileinfo.add_adjacency_data(self._lat_number, self._lng_number, self._tag, self._value, src, adjstr)\r
- mstr_msg("layergen", "Adjacency info stored in database")\r
-\r
- if self._is_completion == True:\r
- r = self._tileinfo.get_adjacency_for_completion(self._lat_number, self._lng_number)\r
- #r = self._tiledb.get_adjacency_for_completion(self._lat_number, self._lng_number)\r
- if len(r) == 0:\r
- self._tileinfo.add_completion_data(self._lat_number, self._lng_number, self._tag, self._value, src, adjstr)\r
- mstr_msg("layergen", "Adjacency info for completion stored in database")\r
-\r
- #self._tiledb.commit_query()\r
- #self._tiledb.close_db()\r
-\r
# Create a water mask we need to remove from the DDS later\r
if (self._tag == "natural" and self._value == "water") or (self._tag == "water" and self._value == "lake") or (self._tag == "water" and self._value == "pond") or (self._tag == "water" and self._value == "river") or (self._tag == "leisure" and self._value == "swimming_pool"):\r
mstr_msg("layergen", "Generating inland water mask")\r
if l[3] > 65:\r
b = 255 - l[3]\r
inl_pix[x,y] = (255,0,255,255)\r
- inl_mask.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_mask.png")\r
+ #inl_mask.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_mask.png")\r
+ layer_comp = inl_mask\r
mstr_msg("layergen", "Inland water mask generated and saved")\r
+\r
+ # Return the completed image\r
+ return layer_comp\r
\r
\r
# ---------------------------------------------------------------------------------------\r
if self._isline == True or self._tag == "building":\r
\r
# We will need the mask in question\r
- 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" )\r
+ #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" )\r
\r
# Generate an edge mask from the original\r
- osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)\r
+ osm_edge = mask.filter(ImageFilter.FIND_EDGES)\r
osm_edge = osm_edge.filter(ImageFilter.MaxFilter)\r
mstr_msg("layergen", "Edge mask generated")\r
\r
if self._tag != "building":\r
for i in mstr_mask_blur:\r
if i[0] == self._tag and i[1] == self._value:\r
- osm_mask = osm_mask.filter(ImageFilter.BoxBlur(radius=i[2]))\r
+ mask = mask.filter(ImageFilter.BoxBlur(radius=i[2]))\r
break\r
\r
\r
# This time we have no source material - instead we will fill the\r
# mask with a color that is appropriate for this street type.\r
layer_comp = Image.new("RGBA", (self._imgsize, self._imgsize))\r
- mask_pix = osm_mask.load()\r
+ mask_pix = mask.load()\r
edge_pix = osm_edge.load()\r
layer_comp_pix = layer_comp.load()\r
\r
\r
# We will do some super magic here to let houses look more realistic\r
if self._tag == "building":\r
+ \r
+ details = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+ tree_shadow = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+ trees = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+ roof_details = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+ shadow = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+\r
+ if mstr_shadow_enabled == True:\r
+ fn = mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_building-" + self._value + "_layer_shadow.png"\r
+ if os.path.isfile(fn):\r
+ shadow = Image.open(fn)\r
+\r
vls = [ "detached", "hotel", "farm", "semidetached_house", "apartments", "civic", "house", "school", "kindergarten", "yes" ]\r
if self._value in vls:\r
# Generate a new image\r
- details = Image.new("RGBA", (self._imgsize, self._imgsize))\r
details_pix = details.load()\r
layer_pix = layer_comp.load()\r
for y in range(self._imgsize):\r
details_pix[shf_x2, shf_y2] = (187-d2, 179-d2, 176-d2, aa)\r
\r
# Image for roof details\r
- roof_details = Image.new("RGBA", (self._imgsize, self._imgsize))\r
roof_det_pix = roof_details.load()\r
for y in range(self._imgsize):\r
for x in range(self._imgsize):\r
a = randrange(1, 151)\r
nc = (mstr_building_detail_colors[0][0]-d, mstr_building_detail_colors[0][1]-d, mstr_building_detail_colors[0][2]-d, a)\r
roof_det_pix[x,y] = nc\r
- layer_comp.alpha_composite(roof_details)\r
\r
\r
# Let's see how it works with this method\r
- details.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_details.png")\r
+ #details.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_details.png")\r
+ #layer_comp.alpha_composite(details)\r
\r
# Add some random trees\r
div = int(self._imgsize/200)\r
- trees = Image.new("RGBA", (self._imgsize, self._imgsize))\r
for y in range(0, self._imgsize, div):\r
for x in range(0, self._imgsize, div):\r
if x > 0 and x < self._imgsize and y > 0 and y < self._imgsize:\r
if shf_x > self._imgsize - tree.width: shf_x = self._imgsize - tree.width - 1\r
if shf_y > self._imgsize - tree.height: shf_y = self._imgsize - tree.height - 1\r
trees.alpha_composite(tree, (shf_x, shf_y))\r
-\r
+ \r
+ \r
if mstr_shadow_enabled == True:\r
- tree_shadow = Image.new("RGBA", (self._imgsize, self._imgsize))\r
tree_pix = trees.load()\r
shadow_pix = tree_shadow.load()\r
for y in range(self._imgsize):\r
tree_shadow.alpha_composite(trees)\r
\r
# Save this separately, so that we can blur buildings, but not the trees\r
- fn = mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_building_trees.png"\r
-\r
- if os.path.isfile(fn) == True:\r
- extrees = Image.open(fn)\r
- extrees.alpha_composite(tree_shadow)\r
- extrees.save(fn)\r
- else:\r
- tree_shadow.save(fn)\r
-\r
- #layer_comp.alpha_composite(tree_shadow)\r
- #tree_shadow.alpha_composite(layer_comp)\r
- #layer_comp = tree_shadow\r
+ #fn = mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_building_trees.png"\r
+\r
+ #if os.path.isfile(fn) == True:\r
+ # extrees = Image.open(fn)\r
+ # extrees.alpha_composite(tree_shadow)\r
+ # extrees.save(fn)\r
+ #else:\r
+ # tree_shadow.save(fn)\r
+\r
+ # Let's try this one on for size\r
+ bld_comp = Image.new("RGBA", (self._imgsize, self._imgsize))\r
+ details = details.filter(ImageFilter.GaussianBlur(radius=1))\r
+ bld_comp.alpha_composite(details)\r
+ bld_comp.alpha_composite(tree_shadow)\r
+ bld_comp.alpha_composite(trees)\r
+ shd_p = shadow.load()\r
+ for y in range(self._imgsize):\r
+ for x in range(self._imgsize):\r
+ c = shd_p[x,y]\r
+ if c[3] > 0:\r
+ s = (0,0,0,120-(randrange(0,21)))\r
+ shd_p[x,y] = s\r
+ shadow = shadow.filter(ImageFilter.GaussianBlur(radius=1))\r
+ bld_comp.alpha_composite(shadow)\r
+ layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=1.1))\r
+ bld_comp.alpha_composite(layer_comp)\r
+ layer_comp = bld_comp\r
+ layer_comp.alpha_composite(roof_details)\r
\r
mstr_msg("layergen", "Layer image generated")\r
\r
\r
# Some funnies with shadows\r
if self._tag == "building" and (self._value == "detached" or self._value == "semidetached_house" or self._value == "apartments" or self._value == "civic" or self._value == "house" or self._value == "terrace"):\r
- mask_pix = osm_mask.load()\r
+ mask_pix = mask.load()\r
roofshadow = Image.new("RGBA", (self._imgsize, self._imgsize))\r
roofpix = roofshadow.load()\r
# Generate a pseudo shifted roof shadow\r
\r
# Now apply the shift where necessary\r
roofpix = roofshadow.load()\r
- mask_pix = osm_mask.load()\r
+ mask_pix = mask.load()\r
layer_comp_pix = layer_comp.load()\r
for y in range(self._imgsize):\r
for x in range(self._imgsize):\r
# Highways and runways of any kind get some special treatment\r
if (self._tag == "highway" and self._value == "motorway") or (self._tag == "highway" and self._value == "primary") or (self._tag == "highway" and self._value == "secondary") or (self._tag == "highway" and self._value == "tertiary") or (self._tag == "aeroway" and self._value == "runway"):\r
# We will now add some white lines for coolness\r
- osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)\r
+ osm_edge = mask.filter(ImageFilter.FIND_EDGES)\r
mask_pix = osm_edge.load()\r
layer_comp_pix = layer_comp.load()\r
for y in range(self._imgsize):\r
layer_comp_pix[x, y] = ( w,w,w,a[3] )\r
\r
if self._tag == "highway" and self._value == "residential":\r
- osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)\r
+ osm_edge = mask.filter(ImageFilter.FIND_EDGES)\r
mask_pix = osm_edge.load()\r
layer_comp_pix = layer_comp.load()\r
for y in range(self._imgsize):\r
if l[3] > 65:\r
b = 255 - l[3]\r
inl_pix[x,y] = (255,0,255,255)\r
- inl_mask.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_mask.png")\r
+ #inl_mask.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_mask.png")\r
mstr_msg("layergen", "Inland water mask generated and saved")\r
\r
\r
\r
\r
# Store layer\r
- 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" )\r
+ #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" )\r
mstr_msg("layergen", "Layer image finalized and saved.")\r
\r
\r
break\r
if nm == True:\r
nrm = mstr_xp_normalmap(self._latitude, self._longitude, self._tag, self._value, self._lat_number, self._lng_number, self._latlngfld)\r
- nrm.build_normalmap()\r
+ nrm.build_normalmap(layer_comp)\r
+\r
+\r
+ # Return image\r
+ return layer_comp\r
\r
\r
# Should we find more than one source, the first one found will take precedence.\r
# For the others, we will need to generate fading images, so that the final layer \r
# image works with other tiles\r
- def generate_adjacent_fades(self):\r
+ def generate_adjacent_fades(self, mask):\r
adj_sources = self.find_all_adjacent_sources()\r
precedence = -1\r
\r
\r
# Generate required images\r
# Basically a shortened version of the main layergen call\r
+ adj_image = Image.new("RGBA", (self._imgsize, self._imgsize))\r
for s in range(0, 4):\r
if adj_sources[s] != precedence and adj_sources[s] != -1:\r
src = adj_sources[s]\r
\r
- adj_image = Image.new("RGBA", (self._imgsize, self._imgsize))\r
adj_pix = adj_image.load()\r
\r
# Root folder\r
for p in ptc:\r
ptc_src.append(Image.open(p))\r
\r
- 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" )\r
+ #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" )\r
#lyr_mask = Image.open( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" )\r
\r
for i in mstr_mask_blur:\r
if i[0] == self._tag and i[1] == self._value:\r
if self._tag != "place" and (self._value != "sea" or self._value != "ocean"): \r
- osm_mask = osm_mask.filter(ImageFilter.BoxBlur(radius=i[2]))\r
+ mask = mask.filter(ImageFilter.BoxBlur(radius=i[2]))\r
break\r
- mask_pix = osm_mask.load()\r
+ mask_pix = mask.load()\r
\r
# Begin producing a largely random image\r
samples = 250 # <- We need this in a moment\r
adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
else:\r
adj_pix[x,y] = (0,0,0,0)\r
- adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_top.png")\r
+ #adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_top.png")\r
\r
if s == 1:\r
for y in range(self._imgsize):\r
adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
else:\r
adj_pix[x,y] = (0,0,0,0)\r
- adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_right.png")\r
+ #adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_right.png")\r
\r
if s == 2:\r
for y in range(self._imgsize):\r
adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
else:\r
adj_pix[x,y] = (0,0,0,0)\r
- adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_bottom.png")\r
+ #adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_bottom.png")\r
\r
if s == 3:\r
for y in range(self._imgsize):\r
adj_pix[x,y] = (c[0], c[1], c[2], fade_a[3])\r
else:\r
adj_pix[x,y] = (0,0,0,0)\r
- adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_left.png")\r
+ #adj_image.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_fade_left.png")\r
+\r
+ # Return the image\r
+ return adj_image\r
+\r
\r
\r
def find_all_adjacent_sources(self):\r
import math\r
import os\r
import glob\r
+import threading\r
+from multiprocessing import Process\r
from defines import *\r
from log import *\r
from osmxml import *\r
top_lat = cur_tile_y\r
\r
\r
- # Builds and processes the tile with everything required, in one call.\r
- def _buildTile(self):\r
+ # Start the multi-threaded build of all orthos\r
+ # amtsmt = AmountSimultaneous - so how many orthos you want to\r
+ # generate at the same time. You may need to fine tune this value\r
+ # so that you don't overload your machine.\r
+ def _generateOrthos_mt(self, amtsmt):\r
+ # Need to know maximum values first\r
+ bb_lat = self._lat\r
+ bb_lng = self._long\r
+ bb_lat_edge = self._lat+self._vstep\r
+ bb_lng_edge = self._long+mstr_zl_18\r
+ mlat = 1\r
+ mlng = 1\r
+ while bb_lat < self._lat + 1:\r
+ bb_lat = bb_lat + self._vstep\r
+ mlat = mlat+1\r
+ while bb_lng < self._long + 1:\r
+ bb_lng = bb_lng + mstr_zl_18\r
+ mlng = mlng+1\r
+ mstr_msg("orthographic", "Max lat tile: " + str(mlat) + " - max lng tile: " + str(mlng))\r
+ maxlatlng = [ mlat, mlng ]\r
+\r
+ procs = []\r
+ for p in range(1, amtsmt+1):\r
+ proc = Process(target=self._buildOrtho, args=[1, p, amtsmt])\r
+ procs.append(proc)\r
+ proc.start()\r
+ mstr_msg("orthographic", "Ortho threads started")\r
+\r
+\r
+ # Starts a threading loop to build orthos, with the defined starting point in\r
+ # the lat-lng grid. You will also need to provide the horizontal stepping so\r
+ # that the thread keeps running.\r
+ def _buildOrtho(self, v, h, step):\r
+\r
+ # Starting point\r
+ grid_lat = v\r
+ grid_lng = h\r
+\r
+ # The tile is constructed of many smaller parts. We walk through the\r
+ # smallest possible, from which the bigger ones are later built.\r
+ bb_lat = self._lat\r
+ bb_lng = self._long\r
+ bb_lat_edge = self._lat+self._vstep\r
+ bb_lng_edge = self._long+mstr_zl_18\r
+\r
+ # We need to know the highest possible latitude and longitude tile numbers,\r
+ # in case we render at the edge\r
+ mlat = 1\r
+ mlng = 1\r
+ while bb_lat < self._lat + 1:\r
+ bb_lat = bb_lat + self._vstep\r
+ mlat = mlat+1\r
+ while bb_lng < self._long + 1:\r
+ bb_lng = bb_lng + mstr_zl_18\r
+ mlng = mlng+1\r
+ mstr_msg("orthographic", "Max lat tile: " + str(mlat) + " - max lng tile: " + str(mlng))\r
+ maxlatlng = [ mlat, mlng ]\r
+\r
+ while grid_lat <= maxlatlng[0]:\r
+ # Reset these two\r
+ bb_lat = self._lat + ((grid_lat-1)*self._vstep)\r
+ bb_lng = self._long + ((grid_lng-1)*mstr_zl_18)\r
+ bb_lat_edge = self._lat + ((grid_lat-1)*self._vstep) + self._vstep\r
+ bb_lng_edge = self._long + ((grid_lng-1)*mstr_zl_18) + mstr_zl_18\r
+\r
+ osmxml = mstr_osmxml()\r
+ osmxml.adjust_bbox(bb_lat, bb_lng, bb_lat_edge, bb_lng_edge)\r
+ osmxml.acquire_osm(grid_lat, grid_lng)\r
+\r
+ # Let the user know\r
+ mstr_msg("orthographic", "Generating orthophoto " + str(grid_lat) + "-" + str(grid_lng))\r
+\r
+ # Get the data\r
+ #osmxml.acquire_osm(cur_tile_y, cur_tile_x) # <- This acquires current OSM info\r
+ #mstr_msg("orthographic", "Acquired current OSM info from marstr.online repository")\r
+\r
+ # Check for work to be done\r
+ layers = self.determineLayerWork(osmxml)\r
+\r
+ # We need to walk through the array of layers,\r
+ # in their z-order.\r
+ # For each layer, we will generate the mask, the layer image\r
+ # itself, and finally, compose the ortho photo.\r
+ mstr_msg("orthographic", "Beginning generation of layers")\r
+\r
+ # In here we store the layers\r
+ photolayers = []\r
+\r
+ # The masks are handed to layergen in sequence. The layers are then\r
+ # in turn handed to photogen.\r
+\r
+ curlyr = 1\r
+ for layer in layers:\r
+ # Let the user know\r
+ mstr_msg("orthographic", "Processing layer " + str(curlyr) + " of " + str(len(layers)))\r
+\r
+ # Generate the mask\r
+ mg = mstr_maskgen( [self._lat, grid_lat, self._long, grid_lng], self._vstep, layer[0], layer[1], layer[2])\r
+ if layer[0] == "building":\r
+ mg.set_tile_width(self._findWidthOfLongitude(bb_lat))\r
+ mg.set_latlng_numbers(self._lat, grid_lat, self._long, grid_lng)\r
+ mask = mg._build_mask(osmxml)\r
+ \r
+ # Generate the layer\r
+ lg = mstr_layergen(layer[0], layer[1], self._lat, grid_lat, self._long, grid_lng, layer[2])\r
+ lg.set_max_latlng_tile(maxlatlng)\r
+ lg.set_latlng_folder(self._latlngfld)\r
+ #lg.open_db()\r
+ lg.open_tile_info()\r
+ photolayers.append(lg.genlayer(mask, osmxml))\r
+ curlyr = curlyr+1\r
+ mstr_msg("orthographic", "All layers created")\r
+\r
+ # We should have all layers now.\r
+ # Snap a photo with our satellite :)\r
+ mstr_msg("orthographic", "Generating ortho photo")\r
+ pg = mstr_photogen(self._lat, self._long, grid_lat, grid_lng, maxlatlng[0], maxlatlng[1])\r
+ pg.genphoto(photolayers)\r
+ mstr_msg("orthographic", " -- Ortho photo generated -- ")\r
+ print("")\r
+ print("")\r
+\r
+ # Perform adjustment of grid position\r
+ n_lng = grid_lng + step\r
+ if n_lng > maxlatlng[1]:\r
+ np = n_lng - maxlatlng[1]\r
+ grid_lng = np\r
+ grid_lat = grid_lat+1\r
+ else:\r
+ grid_lng = n_lng\r
+\r
+\r
+ # Prepares the entire tile\r
+ def _prepareTile(self):\r
mstr_msg("orthographic", "Beginning construction of tile")\r
\r
# We need to know which platform we are on\r
# Previously, I downloaded all XML files in one go - but to ease the\r
# stress on OSM servers and my server, we will do acquire the data\r
# only for the current processed part of the tile.\r
- if self._prep == True:\r
- for lat_grid in range(1, maxlatlng[0]+1):\r
- for lng_grid in range(1, maxlatlng[1]+1):\r
- # Adjust bounding box\r
- osmxml = mstr_osmxml()\r
- osmxml.adjust_bbox(bb_lat, bb_lng, bb_lat_edge, bb_lng_edge)\r
- osmxml.acquire_osm(lat_grid, lng_grid)\r
- mstr_msg("orthographic", "Adjusted bounding box for XML object")\r
-\r
- # Check for work to be done\r
- layers = self.determineLayerWork(osmxml)\r
-\r
- curlyr = 1\r
- for layer in layers:\r
- if layer[2] == False and layer[0] != "building":\r
- # Let the user know\r
- mstr_msg("orthographic", "Processing layer " + str(curlyr) + " of " + str(len(layers)))\r
-\r
- # Generate the mask\r
- mg = mstr_maskgen( [self._lat, cur_tile_y, self._long, cur_tile_x], self._vstep, layer[0], layer[1], layer[2])\r
- mask = mg._build_mask(osmxml, is_prep=True) # We need an object here\r
-\r
- tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, layer[0], layer[1], mask, False)\r
- tp._prepareTile()\r
-\r
- curlyr = curlyr+1\r
-\r
- # Adjust longitude coordinates\r
- cur_tile_x = cur_tile_x+1\r
- bb_lng = bb_lng + mstr_zl_18\r
- bb_lng_edge = bb_lng_edge + mstr_zl_18\r
- mstr_msg("orthographic", "Adjustment of longitude performed")\r
- # Adjust peak longitude tile number\r
- if cur_tile_x > top_lng:\r
- top_lng = cur_tile_x\r
-\r
- # Adjust latitude and all other values when we get here\r
- cur_tile_y = cur_tile_y+1\r
- cur_tile_x = 1\r
- bb_lng = self._long\r
- bb_lng_edge = self._long + mstr_zl_18\r
- bb_lat = bb_lat + self._vstep\r
- bb_lat_edge = bb_lat_edge + self._vstep\r
- mstr_msg("orthographic", "Adjustment of latitude performed")\r
- # Adjust peak latitude number\r
- if cur_tile_y > top_lat:\r
- top_lat = cur_tile_y\r
-\r
- # Need to differentiate\r
- if self._prep == False:\r
- # The tile is constructed of many smaller parts. We walk through the\r
- # smallest possible, from which the bigger ones are later built.\r
- bb_lat = self._lat\r
- bb_lng = self._long\r
- bb_lat_edge = self._lat+self._vstep\r
- bb_lng_edge = self._long+mstr_zl_18\r
- cur_tile_x = 1\r
- cur_tile_y = 1\r
- osmxml = mstr_osmxml(0,0)\r
-\r
- # Previously, I downloaded all XML files in one go - but to ease the\r
- # stress on OSM servers and my server, we will do acquire the data\r
- # only for the current processed part of the tile.\r
- for lat_grid in range(1, maxlatlng[0]+1):\r
- for lng_grid in range(1, maxlatlng[1]+1):\r
- # Adjust bounding box\r
- osmxml.adjust_bbox(bb_lat, bb_lng, bb_lat_edge, bb_lng_edge)\r
- mstr_msg("orthographic", "Adjusted bounding box for XML object")\r
+ for lat_grid in range(1, maxlatlng[0]+1):\r
+ for lng_grid in range(1, maxlatlng[1]+1):\r
+ # Adjust bounding box\r
+ osmxml = mstr_osmxml()\r
+ osmxml.adjust_bbox(bb_lat, bb_lng, bb_lat_edge, bb_lng_edge)\r
+ osmxml.acquire_osm(lat_grid, lng_grid)\r
+ mstr_msg("orthographic", "Adjusted bounding box for XML object")\r
\r
- # Determine what to do... maybe work was interrupted\r
- if os.path.isfile(mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(cur_tile_y) + "_" + str(cur_tile_x) + ".dds") == False:\r
+ # Check for work to be done\r
+ layers = self.determineLayerWork(osmxml)\r
\r
+ curlyr = 1\r
+ for layer in layers:\r
+ if layer[2] == False and layer[0] != "building":\r
# Let the user know\r
- mstr_msg("orthographic", "Generating missing orthophoto " + str(cur_tile_y) + "-" + str(cur_tile_x))\r
-\r
- # Get the data\r
- #osmxml.acquire_osm(cur_tile_y, cur_tile_x) # <- This acquires current OSM info\r
- #mstr_msg("orthographic", "Acquired current OSM info from marstr.online repository")\r
-\r
- # Check for work to be done\r
- layers = self.determineLayerWork()\r
-\r
- # We need to walk through the array of layers,\r
- # in their z-order.\r
- # For each layer, we will generate the mask, the layer image\r
- # itself, and finally, compose the ortho photo.\r
- mstr_msg("orthographic", "Beginning generation of layers")\r
-\r
- curlyr = 1\r
- for layer in layers:\r
- # Let the user know\r
- mstr_msg("orthographic", "Processing layer " + str(curlyr) + " of " + str(len(layers)))\r
-\r
- # Generate the mask\r
- mg = mstr_maskgen( [self._lat, cur_tile_y, self._long, cur_tile_x], self._vstep, layer[0], layer[1], layer[2])\r
- if layer[0] == "building":\r
- mg.set_tile_width(self._findWidthOfLongitude(bb_lat))\r
- mg.set_latlng_numbers(self._lat, lat_grid, self._long, lng_grid)\r
- mg._build_mask()\r
- \r
- # Generate the layer\r
- lg = mstr_layergen(layer[0], layer[1], self._lat, cur_tile_y, self._long, cur_tile_x, layer[2])\r
- lg.set_max_latlng_tile(maxlatlng)\r
- lg.set_latlng_folder(self._latlngfld)\r
- #lg.open_db()\r
- lg.open_tile_info()\r
- lg.genlayer()\r
- curlyr = curlyr+1\r
- mstr_msg("orthographic", "All layers created")\r
-\r
- # We should have all layers now.\r
- # Snap a photo with our satellite :)\r
- mstr_msg("orthographic", "Generating ortho photo")\r
- pg = mstr_photogen(self._lat, self._long, cur_tile_y, cur_tile_x, maxlatlng[0], maxlatlng[1])\r
- pg.genphoto()\r
- mstr_msg("orthographic", " -- Ortho photo generated -- ")\r
- print("")\r
- print("")\r
-\r
- # Adjust longitude coordinates\r
- cur_tile_x = cur_tile_x+1\r
- bb_lng = bb_lng + mstr_zl_18\r
- bb_lng_edge = bb_lng_edge + mstr_zl_18\r
- mstr_msg("orthographic", "Adjustment of longitude performed")\r
- # Adjust peak longitude tile number\r
- if cur_tile_x > top_lng:\r
- top_lng = cur_tile_x\r
-\r
- # Clear out cache\r
- """\r
- if mstr_clear_cache == True:\r
- ch = glob.glob(mstr_datafolder + "_cache/*")\r
- for f in ch:\r
- if os_platform == "nt":\r
- if self._isFileAccessibleWin(f) == True:\r
- os.remove(f)\r
- if os_platform == "posix":\r
- if self._isFileAccessiblePosix(f) == True:\r
- os.remove(f)\r
- mstr_msg("orthographic", "Cleared cache")\r
- """\r
- \r
+ mstr_msg("orthographic", "Processing layer " + str(curlyr) + " of " + str(len(layers)))\r
\r
- # Adjust latitude and all other values when we get here\r
- cur_tile_y = cur_tile_y+1\r
- cur_tile_x = 1\r
- bb_lng = self._long\r
- bb_lng_edge = self._long + mstr_zl_18\r
- bb_lat = bb_lat + self._vstep\r
- bb_lat_edge = bb_lat_edge + self._vstep\r
- mstr_msg("orthographic", "Adjustment of latitude performed")\r
- # Adjust peak latitude number\r
- if cur_tile_y > top_lat:\r
- top_lat = cur_tile_y\r
- \r
- mstr_msg("orthographic", "Generation of all tiles completed!")\r
-\r
-\r
- # Complete scenery\r
- if mstr_xp_genscenery == True:\r
- scn = mstr_xp_scenery(self._lat, self._long, mlat, mlng, self._vstep, self._latlngfld)\r
- scn.acquire_elevation_data()\r
- scn.acquire_xes_data()\r
- scn.build_mesh_script()\r
- scn.build_mesh()\r
- scn.build_ter_files()\r
- mstr_msg("orthographic", "[X-Plane] Mesh built, and scenery completed")\r
- \r
- mstr_msg("orthographic", "Final step completed.")\r
- mstr_msg("orthographic", "Tile data in: " + self._output + "z_orthographic/" + self._latlngfld)\r
- print("")\r
- mstr_msg("orthographic", "Thanks for using Orthographic! -- Best, Marcus")\r
- print("")\r
+ # Generate the mask\r
+ mg = mstr_maskgen( [self._lat, cur_tile_y, self._long, cur_tile_x], self._vstep, layer[0], layer[1], layer[2])\r
+ mask = mg._build_mask(osmxml, is_prep=True) # We need an object here\r
\r
- # Let's leave this out for the moment\r
- """\r
- mstr_msg("orthographic", "Generating ZL16 tiles and keeping airport tiles")\r
- tg = mstr_tilegen(self._lat, self._lng, self._vstep, top_lat, top_lng)\r
- tg.genTiles()\r
- mstr_msg("orthographic", "Final step completed.")\r
- print("")\r
- mstr_msg("orthographic", "Tile data in: " + mstr_datafolder + "/Tiles/" + str(self._lat) + "_" + self._lng)\r
- print("")\r
- print("")\r
- mstr_msg("orthographic", "Thanks for using Orthographic! -- Best, Marcus")\r
- print("")\r
- """\r
+ tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, layer[0], layer[1], mask, False)\r
+ tp._prepareTile()\r
+\r
+ curlyr = curlyr+1\r
\r
+ # Adjust longitude coordinates\r
+ cur_tile_x = cur_tile_x+1\r
+ bb_lng = bb_lng + mstr_zl_18\r
+ bb_lng_edge = bb_lng_edge + mstr_zl_18\r
+ mstr_msg("orthographic", "Adjustment of longitude performed")\r
+ # Adjust peak longitude tile number\r
+ if cur_tile_x > top_lng:\r
+ top_lng = cur_tile_x\r
+\r
+ # Adjust latitude and all other values when we get here\r
+ cur_tile_y = cur_tile_y+1\r
+ cur_tile_x = 1\r
+ bb_lng = self._long\r
+ bb_lng_edge = self._long + mstr_zl_18\r
+ bb_lat = bb_lat + self._vstep\r
+ bb_lat_edge = bb_lat_edge + self._vstep\r
+ mstr_msg("orthographic", "Adjustment of latitude performed")\r
+ # Adjust peak latitude number\r
+ if cur_tile_y > top_lat:\r
+ top_lat = cur_tile_y\r
\r
\r
\r