from maskgen import *\r
from layergen import *\r
from photogen import *\r
+from tileprep import *\r
from xp_scenery import *\r
\r
\r
class mstr_orthographic:\r
\r
# Constructor of class. Takes longitude and latitude.\r
- def __init__(self, lat, lng, outfolder, pwd):\r
+ def __init__(self, lat, lng, outfolder, pwd, prep=False):\r
self._lat = lat\r
self._long = lng\r
self._output = outfolder\r
self._pwd = pwd\r
self._vstep = self._findVerticalStepping()\r
self._latlngfld = self.latlng_folder([lat,lng])\r
+ self._prep = prep\r
mstr_msg("orthographic", "Initiated with LAT: " + str(lat) + ", LNG: " + str(lng))\r
\r
\r
mstr_msg("orthographic", "[X-Plane] created tile normal maps folder")\r
if not os.path.exists(self._output + "/z_orthographic/normals/" + self._latlngfld):\r
os.makedirs(self._output + "/z_orthographic/normals/" + self._latlngfld)\r
- \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_edge = self._long+mstr_zl_18\r
cur_tile_x = 1\r
cur_tile_y = 1\r
- osmxml = mstr_osmxml(0,0)\r
+ #osmxml = mstr_osmxml(0,0)\r
mstr_msg("orthographic", "Set initial coordinates and bounding box for OSM acquisition")\r
\r
# The highest encountered tile numbers\r
bb_lat = self._lat\r
bb_lng = self._long\r
\r
+\r
+ # We will now prepare the graphic tile generation. We do this by only generating\r
+ # the masks and determine which sources to use in the actual images.\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
-\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
-\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
+ 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()\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
+ layers = self.determineLayerWork(osmxml)\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
+ 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
- # 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
+ # 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
- # 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
+ tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, layer[0], layer[1], mask, False)\r
+ tp._prepareTile()\r
\r
- # Clear out cache\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
+ curlyr = curlyr+1\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
+ # 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_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
+ 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
\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
+ # 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
+\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
+\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
\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
+ # 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
\r
\r
\r
\r
\r
# Checks which layers need to be generated, and what kind of layer it is\r
- def determineLayerWork(self):\r
+ def determineLayerWork(self, xmlobj):\r
\r
mstr_msg("orthographic", "Checking for work to be performed")\r
\r
layers = []\r
\r
- tilexml = mstr_datafolder + "_cache/tile.xml"\r
- xml = mstr_osmxml(0,0)\r
- way = xml.acquire_waypoint_data(tilexml)\r
- rls = xml.acquire_relations(tilexml)\r
+ #tilexml = mstr_datafolder + "_cache/tile.xml"\r
+ #xml = mstr_osmxml(0,0)\r
+ way = xmlobj.acquire_waypoint_data()\r
+ rls = xmlobj.acquire_relations()\r
\r
for l in mstr_ortho_layers:\r
# Check if there is anything to render\r