Transition to image-based contour detection for resource allocation. Allocation of resources not yet implemented with this code. Contour detection requires opencv-python to be present.
This commit is contained in:
parent
cf25d45789
commit
e82ecc9d32
@ -14,7 +14,7 @@
|
||||
# tiles will go. This is also the folder where the image generation sources are
|
||||
# stored.
|
||||
#mstr_datafolder = "M:/Developer/Projects/orthographic/"
|
||||
mstr_datafolder = "/home/marcus/Data/Developer/Projects/orthographic/"
|
||||
mstr_datafolder = "D:/Developer/Projects/orthographic/"
|
||||
# Switched to Linux, so path is amended
|
||||
|
||||
|
||||
|
@ -297,9 +297,9 @@ class mstr_orthographic:
|
||||
mstr_msg("orthographic", "Beginning construction of tile")
|
||||
|
||||
# Clear cache
|
||||
tmp = glob.glob(mstr_datafolder + "_cache/*.*")
|
||||
for t in range(0, len(tmp)):
|
||||
os.remove(tmp[t])
|
||||
#tmp = glob.glob(mstr_datafolder + "_cache/*.*")
|
||||
#for t in range(0, len(tmp)):
|
||||
# os.remove(tmp[t])
|
||||
|
||||
# We need to know which platform we are on
|
||||
os_platform = os.name
|
||||
@ -383,12 +383,24 @@ class mstr_orthographic:
|
||||
bb_lat = self._lat
|
||||
bb_lng = self._long
|
||||
|
||||
# Resource contour maps
|
||||
contours = []
|
||||
|
||||
# Generate images for all resources
|
||||
cnt_w = mlng * 20
|
||||
cnt_h = mlat * 20
|
||||
for l in mstr_ortho_layers:
|
||||
if l[0] != "building":
|
||||
cntimg = Image.new("RGBA", (cnt_w, cnt_h), (255,255,255,255))
|
||||
contours.append([l[0], l[1], cntimg])
|
||||
mstr_msg("orthographic", "Created base images for landuse contours")
|
||||
|
||||
# We will now prepare the graphic tile generation. We do this by only generating
|
||||
# the masks and determine which sources to use in the actual images.
|
||||
# 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.
|
||||
"""
|
||||
|
||||
for lat_grid in range(1, maxlatlng[0]+1):
|
||||
for lng_grid in range(1, maxlatlng[1]+1):
|
||||
# Adjust bounding box
|
||||
@ -410,8 +422,20 @@ class mstr_orthographic:
|
||||
mg = mstr_maskgen( [self._lat, cur_tile_y, self._long, cur_tile_x], self._vstep, layer[0], layer[1], layer[2])
|
||||
mask = mg._build_mask(osmxml, is_prep=True) # We need an object here
|
||||
|
||||
tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, layer[0], layer[1], mask, False)
|
||||
tp._determineEdges()
|
||||
mask = mask.resize((20,20), Image.Resampling.BILINEAR)
|
||||
idx = 0
|
||||
for c in contours:
|
||||
if c[0] == layer[0] and c[1] == layer[1]:
|
||||
break
|
||||
else:
|
||||
idx=idx+1
|
||||
|
||||
cnx = (lng_grid-1) * 20
|
||||
cny = cnt_h - (lat_grid * 20)
|
||||
contours[idx][2].alpha_composite(mask, dest=(cnx,cny))
|
||||
|
||||
#tp = mstr_tileprep(self._lat, self._long, lat_grid, lng_grid, layer[0], layer[1], mask, False)
|
||||
#tp._determineEdges()
|
||||
|
||||
curlyr = curlyr+1
|
||||
|
||||
@ -436,14 +460,18 @@ class mstr_orthographic:
|
||||
if cur_tile_y > top_lat:
|
||||
top_lat = cur_tile_y
|
||||
|
||||
exit(1)
|
||||
"""
|
||||
|
||||
# Store all contour images
|
||||
for c in contours:
|
||||
c[2].save(mstr_datafolder + "_cache/contour_" + c[0] + "_" + c[1] + ".png")
|
||||
mstr_msg("orthographic", "Saved contour images for each OSM tag")
|
||||
|
||||
|
||||
# We now need to "raytrace" the resources for correct placement
|
||||
mstr_msg("orthographic", "Performing resource plamement tracing for tile")
|
||||
|
||||
# Let's set up an array which keeps track of all used tiles, per resource
|
||||
|
||||
"""
|
||||
for l in mstr_ortho_layers:
|
||||
self._tiles_visited.append([(l[0], l[1])]) # Store tag and value as tuple for each possible resource
|
||||
|
||||
@ -469,6 +497,7 @@ class mstr_orthographic:
|
||||
tp._setAlreadyVisitedTiles(self._tiles_visited[vstidx])
|
||||
tp._placeTileSources(mlat, mlng)
|
||||
self.adjust_tiles_visited(vstidx, tp._all_visited)
|
||||
"""
|
||||
|
||||
|
||||
# Adjust the tiles visited for one resource
|
||||
|
@ -14,7 +14,7 @@
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
import glob
|
||||
from os import MFD_ALLOW_SEALING
|
||||
#from os import MFD_ALLOW_SEALING
|
||||
from random import randrange
|
||||
from PIL import Image
|
||||
from osmxml import *
|
||||
|
Loading…
x
Reference in New Issue
Block a user