From 10e87db4a027619e812b8128c7c9b7a8ee846a1e Mon Sep 17 00:00:00 2001 From: "Marcus Str." Date: Sun, 6 Oct 2024 23:16:06 +0200 Subject: [PATCH] Correction to make streams appear correctly. Refinement to streets, roads, highways. Corrected bug in orthographic main class so that it renders correct amount of latitude and longitude tiles/orthos. --- defines.py | 2 +- layergen.py | 26 ++++++++++++++++++++++---- orthographic.py | 4 ++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/defines.py b/defines.py index ab30c06..b162937 100644 --- a/defines.py +++ b/defines.py @@ -154,7 +154,7 @@ mstr_ortho_layers = [ ("highway", "unclassified", 17), ("highway", "living_street", 12), ("waterway", "river", 10), - ("waterway", "stream", 10), + ("waterway", "stream", 2), ("leisure", "nature_reserve", "landuse", "forest"), ("landuse", "forest", "landuse", "forest"), ("natural", "wood", "natural", "wood"), diff --git a/layergen.py b/layergen.py index 3abcd5f..75f1e3a 100644 --- a/layergen.py +++ b/layergen.py @@ -445,7 +445,7 @@ class mstr_layergen: for y in range(img.height): for x in range(img.width): c = imgp[x,y] - nc = (c[0], c[1], c[2], int(imgp[x,y][3]*0.5)) + nc = (c[0], c[1], c[2], int(imgp[x,y][3]*0.4)) imgp[x,y] = nc lx = randrange( self._imgsize - img.width ) ly = randrange( self._imgsize - img.height ) @@ -910,12 +910,30 @@ class mstr_layergen: w = randrange(60, 96) a=mask_pix[x,y] layer_comp_pix[x, y] = ( w,w,w,a[3] ) + mstr_msg("layergen", "Street lines added") - mstr_msg("layergen", "Street lines added") + # Same as above, except that streams are lines and are not drawn as polygons. + # Therefore this part needs to be in here as well. + if self._tag == "waterway" and self._value == "stream": + mstr_msg("layergen", "Generating inland water mask") + 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] > 65: + b = 255 - l[3] + 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") + + + # Blur roads a bit + if self._tag == "highway": + layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=1)) - if self._tag == "waterway" and (self._value == "river" or self._value == "stream"): - layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=4)) # Store layer layer_comp.save( mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer.png" ) diff --git a/orthographic.py b/orthographic.py index 4c076aa..04353f2 100644 --- a/orthographic.py +++ b/orthographic.py @@ -169,8 +169,8 @@ class mstr_orthographic: # Previously, I downloaded all XML files in one go - but to ease the # stress on OSM servers and my server, we will do acquire the data # only for the current processed part of the tile. - while bb_lat < self._lat + 1: - while bb_lng < self._long + 1: + for lat_grid in range(1, maxlatlng[0]+1): + for lng_grid in range(1, maxlatlng[1]+1): # Adjust bounding box osmxml.adjust_bbox(bb_lat, bb_lng, bb_lat_edge, bb_lng_edge) mstr_msg("orthographic", "Adjusted bounding box for XML object") -- 2.30.2