From b3d5fca1124f28a921ab6934eb76e4a3ae3a1194 Mon Sep 17 00:00:00 2001 From: "Marcus Str." Date: Sun, 2 Feb 2025 13:32:35 +0100 Subject: [PATCH] Fixed critical issue at which all natural:water was removed, which does not need to be the case for all orthos. Implemented new mechanism to check against existence of an empty file to selectively run the water removal mechanism. --- photogen.py | 102 ++++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/photogen.py b/photogen.py index 7535edb..3792f4a 100644 --- a/photogen.py +++ b/photogen.py @@ -531,59 +531,61 @@ class mstr_photogen: # At ZL16 there seems to be an issue with water bodies, especially rivers (natural:water). # Let's see if we can correct that - # natural:water - ntrl_water = False - ntrl_idx = 0 - for lyr in self._lyrnames: - if lyr[0] == "natural" and lyr[1] == "water": - ntrl_water = True - break - ntrl_idx = ntrl_idx + 1 + # These files will need to be generated after manual check of the orthos + if os.path.isfile(mstr_datafolder + "z_orthographic/data" + self._latlngfld + "/water/" + str(self._ty) + "_" + str(self._tx)) == True: + # natural:water + ntrl_water = False + ntrl_idx = 0 + for lyr in self._lyrnames: + if lyr[0] == "natural" and lyr[1] == "water": + ntrl_water = True + break + ntrl_idx = ntrl_idx + 1 - if ntrl_water == True: - - # We'll go through all layers and "shavve off" excess. - # This way we can hopefully correct incorrect line and polygon renders. - for l in range(0, len(layers)): - if l < ntrl_idx: # <- We don't want to load the target layer itself - lyrpix = layers[l].load() - wtr_pix = layers[ntrl_idx].load() - for y in range(0, self._tile.height): - for x in range(0, self._tile.width): - lp = lyrpix[x,y] - wp = wtr_pix[x,y] - if lp[3] > 0: - a = 255 - lp[3] - if a < wp[3]: - c = (wp[0], wp[1], wp[2], a) - wtr_pix[x,y] = c + if ntrl_water == True: + + # We'll go through all layers and "shavve off" excess. + # This way we can hopefully correct incorrect line and polygon renders. + for l in range(0, len(layers)): + if l < ntrl_idx: # <- We don't want to load the target layer itself + lyrpix = layers[l].load() + wtr_pix = layers[ntrl_idx].load() + for y in range(0, self._tile.height): + for x in range(0, self._tile.width): + lp = lyrpix[x,y] + wp = wtr_pix[x,y] + if lp[3] > 0: + a = 255 - lp[3] + if a < wp[3]: + c = (wp[0], wp[1], wp[2], a) + wtr_pix[x,y] = c - # water:river - river_water = False - river_idx = 0 - for lyr in self._lyrnames: - if lyr[0] == "water" and lyr[1] == "river": - river_water = True - break - river_idx = river_idx + 1 + # water:river + river_water = False + river_idx = 0 + for lyr in self._lyrnames: + if lyr[0] == "water" and lyr[1] == "river": + river_water = True + break + river_idx = river_idx + 1 - if river_water == True: - - # We'll go through all layers and "shavve off" excess. - # This way we can hopefully correct incorrect line and polygon renders. - for l in range(0, len(layers)): - if l < river_idx and l != ntrl_idx: # <- We don't want to load the target layer itself - lyrpix = layers[l].load() - wtr_pix = layers[river_idx].load() - for y in range(0, self._tile.height): - for x in range(0, self._tile.width): - lp = lyrpix[x,y] - wp = wtr_pix[x,y] - if lp[3] > 0: - a = 255 - lp[3] - if a < wp[3]: - c = (wp[0], wp[1], wp[2], a) - wtr_pix[x,y] = c + if river_water == True: + + # We'll go through all layers and "shavve off" excess. + # This way we can hopefully correct incorrect line and polygon renders. + for l in range(0, len(layers)): + if l < river_idx and l != ntrl_idx: # <- We don't want to load the target layer itself + lyrpix = layers[l].load() + wtr_pix = layers[river_idx].load() + for y in range(0, self._tile.height): + for x in range(0, self._tile.width): + lp = lyrpix[x,y] + wp = wtr_pix[x,y] + if lp[3] > 0: + a = 255 - lp[3] + if a < wp[3]: + c = (wp[0], wp[1], wp[2], a) + wtr_pix[x,y] = c return layers