]> marstr Code Repo - orthographic/commitdiff
Corrections in water cut code, amendments for tile completion as code resulted in...
authorMarcus Str. <marcus@marstr.online>
Wed, 25 Sep 2024 12:14:33 +0000 (14:14 +0200)
committerMarcus Str. <marcus@marstr.online>
Wed, 25 Sep 2024 12:14:33 +0000 (14:14 +0200)
layergen.py
osmxml.py
photogen.py

index 4337fbf5f032907eafe44a4ad7a13c96013e3f77..55ef4b93e89ecd3ffd25ebfabd2af17dadec5694 100644 (file)
@@ -537,15 +537,15 @@ class mstr_layergen:
             # 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"):\r
                 mstr_msg("layergen", "Generating inland water mask")\r
-                inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (255,255,255,255))\r
+                inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,0))\r
                 lyr_pix = layer_comp.load()\r
                 inl_pix = inl_mask.load()\r
                 for y in range(self._imgsize):\r
                     for x in range(self._imgsize):\r
                         l = lyr_pix[x,y]\r
-                        if l[3] > 0:\r
+                        if l[3] > 65:\r
                             b = 255 - l[3]\r
-                            inl_pix[x,y] = (b,b,b,255)\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
                 mstr_msg("layergen", "Inland water mask generated and saved")\r
         \r
index b734334ba94de1ae60be53ce10def6aa978965b1..abd8ed5ecd6b9b3ad18baa3480b31729ef8185e4 100644 (file)
--- a/osmxml.py
+++ b/osmxml.py
@@ -41,25 +41,30 @@ class mstr_osmxml:
         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
-        data = { \r
-            "bbox": { \r
-                    "lat": str(self._lat),\r
-                    "lng": str(self._lng),\r
-                    "lat_b": str(self._curB_lat),\r
-                    "lng_b": str(self._curB_lng)\r
-                },\r
-                "tile_lat": str(self._lat),\r
-                "tile_lng": str(self._lng),\r
-                "square_lat": str(v),\r
-                "square_lng": str(h)\r
-                }\r
-        r = requests.post(mstr_osm_endpoint, json=data)\r
-\r
-        xmlf = mstr_datafolder + "_cache/tile.xml"\r
-        if os.path.isfile(xmlf):\r
-            os.remove(xmlf)\r
-        with open(xmlf, 'wb') as textfile:\r
-            textfile.write(r.content)\r
+        while os.path.isfile(mstr_datafolder + "_cache/tile.xml") == False:\r
+            data = { \r
+                "bbox": { \r
+                        "lat": str(self._lat),\r
+                        "lng": str(self._lng),\r
+                        "lat_b": str(self._curB_lat),\r
+                        "lng_b": str(self._curB_lng)\r
+                    },\r
+                    "tile_lat": str(self._lat),\r
+                    "tile_lng": str(self._lng),\r
+                    "square_lat": str(v),\r
+                    "square_lng": str(h)\r
+                    }\r
+            r = requests.post(mstr_osm_endpoint, json=data)\r
+\r
+            xmlf = mstr_datafolder + "_cache/tile.xml"\r
+            if os.path.isfile(xmlf):\r
+                os.remove(xmlf)\r
+            with open(xmlf, 'wb') as textfile:\r
+                textfile.write(r.content)\r
+\r
+            # 1 second delay in case the request fails\r
+            if os.path.isfile(mstr_datafolder + "_cache/tile.xml") == False:\r
+                sleep(1)\r
 \r
         # Provide the object directly\r
         if asobject == True:\r
index ed5e41501b27146df4c3ed8dc7b344da5ec2d704..6ce11fabb2f28b84a8ce27276b4dc93a0f755d96 100644 (file)
@@ -127,7 +127,7 @@ class mstr_photogen:
                 for y in range(wtr.height):\r
                     for x in range(wtr.width):\r
                         wp = wtr_pix[x,y]\r
-                        if wp[0] == 0:\r
+                        if wp[0] == 255 and wp[1] == 0 and wp[2] == 255 and wp[3] == 255:\r
                             tilepix[x,y] = (0,0,0,0)\r
         \r
         # We are now in posession of the final image.\r
@@ -172,18 +172,18 @@ class mstr_photogen:
 \r
     # This returns a mask of the empty space to cover, should there be any\r
     def buildCompletionMask(self):\r
-        mask = Image.new("RGBA", (self._imgsize, self._imgsize))\r
-        mask_pix = mask.load()\r
+        mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,255))\r
+        #mask_pix = mask.load()\r
 \r
         # Load photo\r
-        layer_pix = self._tile.load() \r
+        #layer_pix = self._tile.load() \r
         \r
         # Scan!\r
-        for y in range(self._tile.width-1):\r
-            for x in range(self._tile.height-1):\r
-                p = layer_pix[x,y]\r
-                if p[3] < 255: # <- Check for empty or non-complete alpha\r
-                    mask_pix[x,y] = (0,0,0,255)\r
+        #for y in range(self._tile.width-1):\r
+        #    for x in range(self._tile.height-1):\r
+        #        p = layer_pix[x,y]\r
+        #        if p[3] < 255: # <- Check for empty or non-complete alpha\r
+        #            mask_pix[x,y] = (0,0,0,255)\r
         # We do not apply any blur or other effects here - we only want the\r
         # exact pixel positions.\r
 \r