Skip to content

Commit

Permalink
Merge pull request #13 from Vort/wmstms
Browse files Browse the repository at this point in the history
Add TMS support
  • Loading branch information
jonasstein committed Dec 30, 2014
2 parents 99d9b4f + f03b57b commit 463934e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
21 changes: 16 additions & 5 deletions canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@

class WmsCanvas:

def __init__(self, wms_url = None, proj = "EPSG:4326", zoom = 4, tile_size = None, mode = "RGBA"):
self.wms_url = wms_url
def __init__(self, ms_url = None, tms = 1, proj = "EPSG:4326", zoom = 4, tile_size = None, mode = "RGBA"):
self.ms_url = ms_url
self.tms = tms
self.zoom = zoom
self.proj = proj
self.mode = mode
self.tile_height = 256
self.tile_width = 256

if tms:
self.zoom = zoom + 1

if tile_size:
self.tile_width, self.tile_height = tile_size
Expand Down Expand Up @@ -76,8 +80,15 @@ def __getitem__ (self, x):
raise KeyError("internal error while fetching tile")

def ConstructTileUrl (self, x, y):
a, b, c, d = projections.from4326(projections.bbox_by_tile(self.zoom, x, y, self.proj), self.proj)
return self.wms_url + "width=%s&height=%s&srs=%s&bbox=%s,%s,%s,%s" % (self.tile_width, self.tile_height, self.proj, a, b, c, d)
if self.tms:
url = self.ms_url
url = url.replace("{zoom}", str(self.zoom - 1))
url = url.replace("{x}", str(x))
url = url.replace("{y}", str(y))
return url
else:
a, b, c, d = projections.from4326(projections.bbox_by_tile(self.zoom, x, y, self.proj), self.proj)
return self.ms_url + "width=%s&height=%s&srs=%s&bbox=%s,%s,%s,%s" % (self.tile_width, self.tile_height, self.proj, a, b, c, d)

def FetchTile(self, x, y):
dl_done = False
Expand All @@ -87,7 +98,7 @@ def FetchTile(self, x, y):
return

tile_data = ""
if self.wms_url:
if self.ms_url:
remote = self.ConstructTileUrl (x, y)
start = clock()
for dl_retrys in range(0, 3):
Expand Down
14 changes: 11 additions & 3 deletions scanaerial.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
[WMS]
fixedzoomlevel = 13
wmsname = Bing Imagery
# wms_server_url = http://wms.latlon.org/?layers=bing&
wms_server_url = http://irs.gis-lab.info/?layers=landsat&
#wmsname = Bing
#wms_server_url = http://wms.latlon.org/?layers=bing&
#wmsname = Landsat
#wms_server_url = http://irs.gis-lab.info/?layers=landsat&
#wmsname = OSM
#wms_server_url = http://ows.terrestris.de/osm/service?FORMAT=image/jpeg&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&LAYERS=OSM-WMS&STYLES=&
#tmsname = MapBox
#tms_server_url = http://a.tiles.mapbox.com/v4/openstreetmap.map-inh7ifmo/{zoom}/{x}/{y}.png?access_token=pk.eyJ1Ijoib3BlbnN0cmVldG1hcCIsImEiOiJncjlmd0t3In0.DmZsIeOW-3x-C5eX-wAqTw
tmsname = MapQuest
tms_server_url = http://oatile1.mqcdn.com/tiles/1.0.0/sat/{zoom}/{x}/{y}.png
projection = EPSG:3857
tile_sizex = 256
tile_sizey = 256
Expand All @@ -12,5 +19,6 @@ douglas_peucker_epsilon = 0.60
deactivate_simplifying = 0
colour_str = 30
maxfilter_setting = 3
timeout = 15

[NODES]
34 changes: 26 additions & 8 deletions scanaerial.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
it back to JOSM
"""

__author__ = "Darafei Praliaskouski, Jonas Stein, Ruben W."
__author__ = "Darafei Praliaskouski, Jonas Stein, Ruben W., Vort"
__license__ = "GPL"
__credits__ = ["Lakewalker-developer-Team", "JOSM-developer-Team", "Malenki"]
__email__ = "news@jonasstein.de"
Expand Down Expand Up @@ -63,7 +63,7 @@
ZOOM = int(float(argv[3]))
except (IndexError, ValueError):
debug("could not read TZoom from commandline, fixed zoom level is used")
ZOOM = config.getint('WMS', 'fixedzoomlevel')
ZOOM = config.getint('WMS', 'fixedzoomlevel')

# Coordinates from command string.
# (format is decimal, for SAS-planet go to Settings and set'em there as --d.
Expand All @@ -76,13 +76,23 @@
WHITE = 1
PROGRAM_START_TIMESTAMP = clock()

WMS_SERVER_URL = config.get('WMS', 'wms_server_url')
if config.has_option('WMS', 'wms_server_url') and config.has_option('WMS', 'wmsname'):
TMS = 0
MS_NAME = config.get('WMS', 'wmsname')
MS_SERVER_URL = config.get('WMS', 'wms_server_url')
elif config.has_option('WMS', 'tms_server_url') and config.has_option('WMS', 'tmsname'):
TMS = 1
MS_NAME = config.get('WMS', 'tmsname')
MS_SERVER_URL = config.get('WMS', 'tms_server_url')
else:
raise Exception('(wms_server_url and wmsname) or (tms_server_url and tmsname) must be specified')

PROJECTION = config.get('WMS', 'projection')
TILE_SIZE = (config.getint('WMS', 'tile_sizex'), config.getint('WMS', 'tile_sizey'))
#FIXME natural:water should go to .cfg NODES but how? It would be nice if the user could expand it for more keys.
WAY_TAGS = {"source:tracer":"scanaerial", \
"source:zoomlevel": ZOOM , \
"source:position": config.get('WMS', 'wmsname'), \
"source:zoomlevel": ZOOM, \
"source:position": MS_NAME, \
"natural":"water"}
POLYGON_TAGS = WAY_TAGS.copy()
POLYGON_TAGS["type"] = "multipolygon"
Expand All @@ -93,16 +103,19 @@
#sensivity for colour change, bigger = larger area covered = 20-23-25 is ok
colour_str = config.getfloat('SCAN', 'colour_str')

TIMEOUT = 0
if config.has_option('SCAN', 'timeout'):
TIMEOUT = config.getint('SCAN', 'timeout')



web = WmsCanvas(WMS_SERVER_URL, PROJECTION, ZOOM, TILE_SIZE, mode = "RGB")
web = WmsCanvas(MS_SERVER_URL, TMS, PROJECTION, ZOOM, TILE_SIZE, mode = "RGB")

was_expanded = True

normales_list = []

mask = WmsCanvas(None, PROJECTION, ZOOM, TILE_SIZE, mode = "1")
mask = WmsCanvas(None, TMS, PROJECTION, ZOOM, TILE_SIZE, mode = "1")

## Getting start pixel ##

Expand All @@ -118,7 +131,12 @@
normales_list = set([])
norm_dir = {(0, -1):0, (1, 0):1, (0, 1):2, (-1, 0):3}

start_time = clock()
while queue:
if TIMEOUT:
if clock() - start_time > TIMEOUT:
raise Exception('Timeout!')

px = queue.pop()
for d in DIRECTIONS:
x1, y1 = px[0] + d[0], px[1] + d[1]
Expand All @@ -143,7 +161,7 @@
debug("B/W MaxFilter: %s" % str(clock() - ttz))
del web
oldmask = mask
mask = WmsCanvas(None, PROJECTION, ZOOM, TILE_SIZE, mode = "1")
mask = WmsCanvas(None, TMS, PROJECTION, ZOOM, TILE_SIZE, mode = "1")
bc = 1
ttz = clock()

Expand Down

0 comments on commit 463934e

Please sign in to comment.