]> marstr Code Repo - orthographic/commitdiff
Initial step toward all-in-memory management, osmxml is now completely in-RAM driven...
authorMarcus Str. <marcus@marstr.online>
Tue, 12 Nov 2024 19:25:46 +0000 (20:25 +0100)
committerMarcus Str. <marcus@marstr.online>
Tue, 12 Nov 2024 19:25:46 +0000 (20:25 +0100)
functions.py
maskgen.py
og.py
orthographic.py
osmxml.py
tileprep.py

index b424fe2057eb9dfd6dd61952867f09bf77d29ff1..c1d89b4dbb1d8b211f99edc984c24ff5b9bee178 100644 (file)
@@ -91,3 +91,20 @@ def in_circle(center_x, center_y, radius, x, y):
 def meters_per_pixel(lngwidth):\r
     mpx = lngwidth / mstr_photores\r
     return mpx\r
+\r
+\r
+# Construct an X-Plane compatible folder name for latitude and longitude\r
+def xplane_latlng_folder(numbers):\r
+    fstr = ""\r
+    if numbers[0] >= 0: fstr = "+"\r
+    if numbers[0] <  0: fstr = "-"\r
+    if abs(numbers[0]) < 10: fstr = fstr + "0" + str(numbers[0])\r
+    if abs(numbers[0]) >= 10 and numbers[0] <= 90: fstr = fstr + str(numbers[0])\r
+\r
+    if numbers[1] >= 0: fstr = fstr + "+"\r
+    if numbers[1] <  0: fstr = fstr + "-"\r
+    if abs(numbers[1]) < 10: fstr = fstr + "00" + str(numbers[1])\r
+    if abs(numbers[1]) >= 10 and numbers[0] <= 99: fstr = fstr + "0" + str(numbers[1])\r
+    if abs(numbers[1]) >= 100 : fstr = fstr + str(numbers[1])\r
+\r
+    return fstr
\ No newline at end of file
index 9515e333a8ba1e65dbc65d9fa1a7b9ea8faeb527..d60f866d54749d32507fbfba6ccae5ff3718556e 100644 (file)
@@ -75,17 +75,18 @@ class mstr_maskgen:
 \r
 \r
     # Builds the required mask\r
-    def _build_mask(self):\r
+    def _build_mask(self, xml, is_prep=False):\r
         # Generate empty image\r
         imgsize = 2048\r
         mask_img = Image.new("RGBA", (imgsize, imgsize))\r
 \r
-        tilexml = mstr_datafolder + "_cache/tile.xml"\r
-        xml = mstr_osmxml(0,0)\r
+        #tilexml = mstr_datafolder + "_cache/tile_" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + ".xml"\r
+        #tilexml = mstr_datafolder + "_cache/tile.xml"\r
+        #xml = mstr_osmxml(0,0)\r
         fstr = str(self._box[0]) + "-" + str(self._box[1]) + "_" + str(self._box[2]) + "-" + str(self._box[3])\r
-        nds = xml.acquire_nodes(tilexml)\r
-        way = xml.acquire_waypoint_data(tilexml)\r
-        rls = xml.acquire_relations(tilexml)\r
+        nds = xml.acquire_nodes()\r
+        way = xml.acquire_waypoint_data()\r
+        rls = xml.acquire_relations()\r
 \r
         mstr_msg("maskgen", "Building mask for " + str(self._box[0]) + "-" + str(self._box[1]) + ", " + str(self._box[2]) + "-" + str(self._box[3]) + ", for " + self._tag + ": " + self._value )\r
 \r
@@ -205,11 +206,14 @@ class mstr_maskgen:
                     imgd.line(pts, fill="#000000", width=mstr_ortho_layers[idx][2], joint="curve")\r
         \r
         # Save image\r
-        mask_img.save(mstr_datafolder + "_cache/" + fstr + "_" + self._tag + "-" + self._value + ".png")\r
+        if is_prep == False:\r
+            mask_img.save(mstr_datafolder + "_cache/" + fstr + "_" + self._tag + "-" + self._value + ".png")\r
+        if is_prep == True:\r
+            return mask_img\r
 \r
         # If this is a building, we need to render the shadow here, as we only know the height\r
         # of the building in this loop.\r
-        if mstr_shadow_enabled == True:\r
+        if mstr_shadow_enabled == True and is_prep == False:\r
             if self._tag == "building":\r
                 mpp = meters_per_pixel(self._tile_width) * mstr_zl_18\r
                 pix_per_floor = mstr_shadow_floor_h / mpp\r
diff --git a/og.py b/og.py
index f8f128ebde0730d224270cbff762b9e176db9306..57a95f4606330ab6fbe9ee9eb0d30cd26fd57575 100644 (file)
--- a/og.py
+++ b/og.py
@@ -31,12 +31,14 @@ print(" ")
 \r
 cli = False\r
 pbf = False\r
+prep = False\r
 \r
-if len(sys.argv) == 3:\r
+if len(sys.argv) == 4:\r
     cli = True\r
+    if sys.argv[3] == "true": prep = True\r
 \r
-if len(sys.argv) == 4:\r
-    pbf = True\r
+#if len(sys.argv) == 4:\r
+#    pbf = True\r
 \r
 # Only if we find enough arguments, proceed.\r
 if cli == True:\r
@@ -46,7 +48,7 @@ if cli == True:
     mstr_msg("_main", "Beginning tile generation process.")\r
 \r
     # Create the class and init values\r
-    og = mstr_orthographic(lat, lng, mstr_datafolder, os.getcwd())\r
+    og = mstr_orthographic(lat, lng, mstr_datafolder, os.getcwd(), prep)\r
     og._buildTile()\r
 \r
 \r
index 16eb887dd3d426bc058357b197796cec14c215c2..9cccd68fc875f2fc9cad22dd93de72fce48cae75 100644 (file)
@@ -19,6 +19,7 @@ from osmxml import *
 from maskgen import *\r
 from layergen import *\r
 from photogen import *\r
+from tileprep import *\r
 from xp_scenery import *\r
 \r
 \r
@@ -26,13 +27,14 @@ from xp_scenery import *
 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
@@ -197,7 +199,7 @@ class mstr_orthographic:
                     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
@@ -206,7 +208,7 @@ class mstr_orthographic:
         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
@@ -231,147 +233,215 @@ class mstr_orthographic:
         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
index 7349ea3b103db2c159c6ff33ecd3728e9d7fc994..05e376e8cea53c76da4673de3c6374224b7621c1 100644 (file)
--- a/osmxml.py
+++ b/osmxml.py
@@ -54,11 +54,11 @@ class mstr_osmxml:
 \r
 \r
     # Acquire XMLs in chunks, then store them\r
-    def acquire_osm(self, v, h, asobject=False):\r
+    def acquire_osm(self, v, h):\r
         mstr_msg("osmxml", "Acquiring OSM data for " + str(self._lat)+","+str(self._lng)+" - "+str(self._curB_lat)+","+str(self._curB_lng))\r
         \r
         # We will use our self-hosted API for this.\r
-        while os.path.isfile(self._xmlfn) == False:\r
+        while self._xmlcontent == "":\r
             data = { \r
                 "bbox": { \r
                         "lat": str(self._lat),\r
@@ -86,7 +86,7 @@ class mstr_osmxml:
                 sleep(1)\r
         \r
         # Store the content in memory\r
-        self._xmldata = xml.dom.minidom.parse(self._xmlcontent)\r
+        self._xmldata = xml.dom.minidom.parseString(self._xmlcontent)\r
         self._xmlcontent = "" # Clear\r
 \r
 \r
index 8de6c399ebcc00b336c90b5f167401f5811dc2a4..f5197a2f9aca605f4877a850cada3bcfc8a76872 100644 (file)
@@ -43,6 +43,16 @@ class mstr_tileprep:
         self._is_completion = is_completion
 
 
+    def _findCorrectTextureFolder(self):
+        srcfld = []
+        for lyr in mstr_ortho_layers:
+            if lyr[0] == self._tag and lyr[1] == self._value:
+                srcfld.append(lyr[2])
+                srcfld.append(lyr[3])
+                break
+        return srcfld
+
+
     # Prepare the tile accordingly
     def _prepareTile(self):
         # Load the mask pixels
@@ -117,7 +127,8 @@ class mstr_tileprep:
 
         # If there was nothing in the info still, we need to select some source
         if self._source == -1:
-            tx = mstr_datafolder + "textures/" + self._tag + "/" + self._value + "/brd/b*.png"
+            srcfld = self._findCorrectTextureFolder()
+            tx = mstr_datafolder + "textures/" + srcfld[0] + "/" + srcfld[1] + "/brd/b*.png"
             lst = glob.glob(tx)
             if len(lst) == 1: self._source = 1
             if len(lst) >= 2: self._source = randrange(1, len(lst)+1)