]> marstr Code Repo - marstr/orthographic.git/commitdiff
Transition to image-based contour detection for resource allocation. Allocation of...
authorMarcus Str. <marcus@marstr.online>
Fri, 10 Jan 2025 11:59:36 +0000 (12:59 +0100)
committerMarcus Str. <marcus@marstr.online>
Fri, 10 Jan 2025 11:59:36 +0000 (12:59 +0100)
defines.py
orthographic.py
tileprep.py

index 126b67b2d752524f56a419cc0e5c1b495856a860..13a76bb85afb13cb5dc0b0501a7b94071a482d13 100644 (file)
@@ -14,7 +14,7 @@
 # tiles will go. This is also the folder where the image generation sources are\r
 # stored.\r
 #mstr_datafolder = "M:/Developer/Projects/orthographic/"\r
-mstr_datafolder = "/home/marcus/Data/Developer/Projects/orthographic/"\r
+mstr_datafolder = "D:/Developer/Projects/orthographic/"\r
 # Switched to Linux, so path is amended\r
 \r
 \r
index 609856c2b9489c145904a9cd62fc7a1304a3be4c..defe6afed3175c325559c8a622325e24d73887a9 100644 (file)
@@ -297,9 +297,9 @@ class mstr_orthographic:
         mstr_msg("orthographic", "Beginning construction of tile")\r
 \r
         # Clear cache\r
-        tmp = glob.glob(mstr_datafolder + "_cache/*.*")\r
-        for t in range(0, len(tmp)):\r
-            os.remove(tmp[t])\r
+        #tmp = glob.glob(mstr_datafolder + "_cache/*.*")\r
+        #for t in range(0, len(tmp)):\r
+        #    os.remove(tmp[t])\r
 \r
         # We need to know which platform we are on\r
         os_platform = os.name\r
@@ -383,12 +383,24 @@ class mstr_orthographic:
         bb_lat = self._lat\r
         bb_lng = self._long\r
 \r
+        # Resource contour maps\r
+        contours = []\r
+\r
+        # Generate images for all resources\r
+        cnt_w = mlng * 20\r
+        cnt_h = mlat * 20\r
+        for l in mstr_ortho_layers:\r
+             if l[0] != "building":\r
+                cntimg = Image.new("RGBA", (cnt_w, cnt_h), (255,255,255,255))\r
+                contours.append([l[0], l[1], cntimg])\r
+        mstr_msg("orthographic", "Created base images for landuse contours")\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
-        """\r
+\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
@@ -410,8 +422,20 @@ class mstr_orthographic:
                         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._determineEdges()\r
+                        mask = mask.resize((20,20), Image.Resampling.BILINEAR)\r
+                        idx = 0\r
+                        for c in contours:\r
+                            if c[0] == layer[0] and c[1] == layer[1]:\r
+                                break\r
+                            else:\r
+                                idx=idx+1\r
+                        \r
+                        cnx = (lng_grid-1) * 20\r
+                        cny = cnt_h - (lat_grid * 20)\r
+                        contours[idx][2].alpha_composite(mask, dest=(cnx,cny))\r
+\r
+                        #tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, layer[0], layer[1], mask, False)\r
+                        #tp._determineEdges()\r
 \r
                     curlyr = curlyr+1\r
 \r
@@ -436,14 +460,18 @@ class mstr_orthographic:
             if cur_tile_y > top_lat:\r
                 top_lat = cur_tile_y\r
 \r
-        exit(1)\r
-        """\r
+\r
+        # Store all contour images\r
+        for c in contours:\r
+            c[2].save(mstr_datafolder + "_cache/contour_" + c[0] + "_" + c[1] + ".png")\r
+        mstr_msg("orthographic", "Saved contour images for each OSM tag")\r
+\r
 \r
         # We now need to "raytrace" the resources for correct placement\r
         mstr_msg("orthographic", "Performing resource plamement tracing for tile")\r
 \r
         # Let's set up an array which keeps track of all used tiles, per resource\r
-        \r
+        """\r
         for l in mstr_ortho_layers:\r
             self._tiles_visited.append([(l[0], l[1])]) # Store tag and value as tuple for each possible resource\r
         \r
@@ -469,6 +497,7 @@ class mstr_orthographic:
                     tp._setAlreadyVisitedTiles(self._tiles_visited[vstidx])\r
                     tp._placeTileSources(mlat, mlng)\r
                     self.adjust_tiles_visited(vstidx, tp._all_visited)\r
+        """\r
 \r
 \r
     # Adjust the tiles visited for one resource\r
index baa96479e7bb2edc7a84d60795082318f3666d1e..5660c644b3bcc9318773a28bbbcd3e6dfb604dd7 100644 (file)
@@ -14,7 +14,7 @@
 # -------------------------------------------------------------------
 
 import glob
-from os import MFD_ALLOW_SEALING
+#from os import MFD_ALLOW_SEALING
 from random import randrange
 from PIL import Image
 from osmxml import *