From: Marcus Str. Date: Wed, 25 Sep 2024 12:14:33 +0000 (+0200) Subject: Corrections in water cut code, amendments for tile completion as code resulted in... X-Git-Url: https://marstr.online/code/gitweb.cgi?a=commitdiff_plain;h=728b4aa9c6289f52846d7dd6b1f92cd825d17a2c;p=orthographic Corrections in water cut code, amendments for tile completion as code resulted in blank patches in DDS files where there is no water. --- diff --git a/layergen.py b/layergen.py index 4337fbf..55ef4b9 100644 --- a/layergen.py +++ b/layergen.py @@ -537,15 +537,15 @@ class mstr_layergen: # Create a water mask we need to remove from the DDS later 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"): mstr_msg("layergen", "Generating inland water mask") - inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (255,255,255,255)) + inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,0)) lyr_pix = layer_comp.load() inl_pix = inl_mask.load() for y in range(self._imgsize): for x in range(self._imgsize): l = lyr_pix[x,y] - if l[3] > 0: + if l[3] > 65: b = 255 - l[3] - inl_pix[x,y] = (b,b,b,255) + inl_pix[x,y] = (255,0,255,255) 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") mstr_msg("layergen", "Inland water mask generated and saved") diff --git a/osmxml.py b/osmxml.py index b734334..abd8ed5 100644 --- 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)) # We will use our self-hosted API for this. - data = { - "bbox": { - "lat": str(self._lat), - "lng": str(self._lng), - "lat_b": str(self._curB_lat), - "lng_b": str(self._curB_lng) - }, - "tile_lat": str(self._lat), - "tile_lng": str(self._lng), - "square_lat": str(v), - "square_lng": str(h) - } - r = requests.post(mstr_osm_endpoint, json=data) - - xmlf = mstr_datafolder + "_cache/tile.xml" - if os.path.isfile(xmlf): - os.remove(xmlf) - with open(xmlf, 'wb') as textfile: - textfile.write(r.content) + while os.path.isfile(mstr_datafolder + "_cache/tile.xml") == False: + data = { + "bbox": { + "lat": str(self._lat), + "lng": str(self._lng), + "lat_b": str(self._curB_lat), + "lng_b": str(self._curB_lng) + }, + "tile_lat": str(self._lat), + "tile_lng": str(self._lng), + "square_lat": str(v), + "square_lng": str(h) + } + r = requests.post(mstr_osm_endpoint, json=data) + + xmlf = mstr_datafolder + "_cache/tile.xml" + if os.path.isfile(xmlf): + os.remove(xmlf) + with open(xmlf, 'wb') as textfile: + textfile.write(r.content) + + # 1 second delay in case the request fails + if os.path.isfile(mstr_datafolder + "_cache/tile.xml") == False: + sleep(1) # Provide the object directly if asobject == True: diff --git a/photogen.py b/photogen.py index ed5e415..6ce11fa 100644 --- a/photogen.py +++ b/photogen.py @@ -127,7 +127,7 @@ class mstr_photogen: for y in range(wtr.height): for x in range(wtr.width): wp = wtr_pix[x,y] - if wp[0] == 0: + if wp[0] == 255 and wp[1] == 0 and wp[2] == 255 and wp[3] == 255: tilepix[x,y] = (0,0,0,0) # We are now in posession of the final image. @@ -172,18 +172,18 @@ class mstr_photogen: # This returns a mask of the empty space to cover, should there be any def buildCompletionMask(self): - mask = Image.new("RGBA", (self._imgsize, self._imgsize)) - mask_pix = mask.load() + mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,255)) + #mask_pix = mask.load() # Load photo - layer_pix = self._tile.load() + #layer_pix = self._tile.load() # Scan! - for y in range(self._tile.width-1): - for x in range(self._tile.height-1): - p = layer_pix[x,y] - if p[3] < 255: # <- Check for empty or non-complete alpha - mask_pix[x,y] = (0,0,0,255) + #for y in range(self._tile.width-1): + # for x in range(self._tile.height-1): + # p = layer_pix[x,y] + # if p[3] < 255: # <- Check for empty or non-complete alpha + # mask_pix[x,y] = (0,0,0,255) # We do not apply any blur or other effects here - we only want the # exact pixel positions.