Corrections in water cut code, amendments for tile completion as code resulted in blank patches in DDS files where there is no water.

This commit is contained in:
Marcus Str. 2024-09-25 14:14:33 +02:00
parent 509cb359bd
commit 728b4aa9c6
3 changed files with 35 additions and 30 deletions

View File

@ -537,15 +537,15 @@ class mstr_layergen:
# Create a water mask we need to remove from the DDS later # 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"): 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") 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() lyr_pix = layer_comp.load()
inl_pix = inl_mask.load() inl_pix = inl_mask.load()
for y in range(self._imgsize): for y in range(self._imgsize):
for x in range(self._imgsize): for x in range(self._imgsize):
l = lyr_pix[x,y] l = lyr_pix[x,y]
if l[3] > 0: if l[3] > 65:
b = 255 - l[3] 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") 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") mstr_msg("layergen", "Inland water mask generated and saved")

View File

@ -41,6 +41,7 @@ class mstr_osmxml:
mstr_msg("osmxml", "Acquiring OSM data for " + str(self._lat)+","+str(self._lng)+" - "+str(self._curB_lat)+","+str(self._curB_lng)) 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. # We will use our self-hosted API for this.
while os.path.isfile(mstr_datafolder + "_cache/tile.xml") == False:
data = { data = {
"bbox": { "bbox": {
"lat": str(self._lat), "lat": str(self._lat),
@ -61,6 +62,10 @@ class mstr_osmxml:
with open(xmlf, 'wb') as textfile: with open(xmlf, 'wb') as textfile:
textfile.write(r.content) 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 # Provide the object directly
if asobject == True: if asobject == True:
xml_doc = xml.dom.minidom.parse("_cache/tile.xml") xml_doc = xml.dom.minidom.parse("_cache/tile.xml")

View File

@ -127,7 +127,7 @@ class mstr_photogen:
for y in range(wtr.height): for y in range(wtr.height):
for x in range(wtr.width): for x in range(wtr.width):
wp = wtr_pix[x,y] 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) tilepix[x,y] = (0,0,0,0)
# We are now in posession of the final image. # 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 # This returns a mask of the empty space to cover, should there be any
def buildCompletionMask(self): def buildCompletionMask(self):
mask = Image.new("RGBA", (self._imgsize, self._imgsize)) mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,255))
mask_pix = mask.load() #mask_pix = mask.load()
# Load photo # Load photo
layer_pix = self._tile.load() #layer_pix = self._tile.load()
# Scan! # Scan!
for y in range(self._tile.width-1): #for y in range(self._tile.width-1):
for x in range(self._tile.height-1): # for x in range(self._tile.height-1):
p = layer_pix[x,y] # p = layer_pix[x,y]
if p[3] < 255: # <- Check for empty or non-complete alpha # if p[3] < 255: # <- Check for empty or non-complete alpha
mask_pix[x,y] = (0,0,0,255) # mask_pix[x,y] = (0,0,0,255)
# We do not apply any blur or other effects here - we only want the # We do not apply any blur or other effects here - we only want the
# exact pixel positions. # exact pixel positions.