diff --git a/Hillup/data/NED100m.py b/Hillup/data/NED100m.py index 0ae66ad..cd4d61b 100644 --- a/Hillup/data/NED100m.py +++ b/Hillup/data/NED100m.py @@ -4,9 +4,9 @@ from math import floor, ceil, log from os import unlink, close, write, makedirs, chmod from os.path import basename, exists, isdir, join -from httplib import HTTPConnection -from urlparse import urlparse -from StringIO import StringIO +from http.client import HTTPConnection +from urllib.parse import urlparse +from io import StringIO from gzip import GzipFile from hashlib import md5 @@ -68,14 +68,14 @@ def datasource(lat, lon, source_dir): if not exists(local_dir): makedirs(local_dir) - chmod(local_dir, 0777) + chmod(local_dir, 0o777) assert isdir(local_dir) # # Grab a fresh remote copy # - print >> stderr, 'Retrieving', url, 'in DEM.NED100m.datasource().' + print('Retrieving', url, 'in DEM.NED100m.datasource().', file=stderr) conn = HTTPConnection(host, 80) conn.request('GET', path) @@ -83,7 +83,7 @@ def datasource(lat, lon, source_dir): if resp.status in range(400, 500): # we're probably outside the coverage area - print >> open(local_none, 'w'), url + print(url, file=open(local_none, 'w')) return None assert resp.status == 200, (resp.status, resp.read()) diff --git a/Hillup/data/NED10m.py b/Hillup/data/NED10m.py index fa9750b..53e118b 100644 --- a/Hillup/data/NED10m.py +++ b/Hillup/data/NED10m.py @@ -5,9 +5,9 @@ from os import unlink, close, write, makedirs, chmod from os.path import basename, exists, isdir, join from tempfile import mkstemp, mkdtemp -from httplib import HTTPConnection +from http.client import HTTPConnection from shutil import move, rmtree -from urlparse import urlparse +from urllib.parse import urlparse from zipfile import ZipFile from fnmatch import fnmatch from hashlib import md5 @@ -74,14 +74,14 @@ def datasource(lat, lon, source_dir): if not exists(local_dir): makedirs(local_dir) - chmod(local_dir, 0777) + chmod(local_dir, 0o777) assert isdir(local_dir) # # Grab a fresh remote copy # - print >> stderr, 'Retrieving', url, 'in DEM.NED10m.datasource().' + print('Retrieving', url, 'in DEM.NED10m.datasource().', file=stderr) conn = HTTPConnection(host, 80) conn.request('GET', path) @@ -89,7 +89,7 @@ def datasource(lat, lon, source_dir): if resp.status == 404: # we're probably outside the coverage area - print >> open(local_none, 'w'), url + print(url, file=open(local_none, 'w')) return None assert resp.status == 200, (resp.status, resp.read()) @@ -124,8 +124,8 @@ def datasource(lat, lon, source_dir): if local_file.endswith('.hdr'): # GDAL needs some extra hints to understand the raw float data hdr_file = open(local_file, 'a') - print >> hdr_file, 'nbits 32' - print >> hdr_file, 'pixeltype float' + print('nbits 32', file=hdr_file) + print('pixeltype float', file=hdr_file) # # The file better exist locally now diff --git a/Hillup/data/NED1km.py b/Hillup/data/NED1km.py index c28d942..432485a 100644 --- a/Hillup/data/NED1km.py +++ b/Hillup/data/NED1km.py @@ -4,9 +4,9 @@ from math import floor, ceil, log from os import unlink, close, write, makedirs, chmod from os.path import basename, exists, isdir, join -from httplib import HTTPConnection -from urlparse import urlparse -from StringIO import StringIO +from http.client import HTTPConnection +from urllib.parse import urlparse +from io import StringIO from gzip import GzipFile from hashlib import md5 @@ -68,14 +68,14 @@ def datasource(lat, lon, source_dir): if not exists(local_dir): makedirs(local_dir) - chmod(local_dir, 0777) + chmod(local_dir, 0o777) assert isdir(local_dir) # # Grab a fresh remote copy # - print >> stderr, 'Retrieving', url, 'in DEM.NED1km.datasource().' + print('Retrieving', url, 'in DEM.NED1km.datasource().', file=stderr) conn = HTTPConnection(host, 80) conn.request('GET', path) @@ -83,7 +83,7 @@ def datasource(lat, lon, source_dir): if resp.status in range(400, 500): # we're probably outside the coverage area - print >> open(local_none, 'w'), url + print(url, file=open(local_none, 'w')) return None assert resp.status == 200, (resp.status, resp.read()) diff --git a/Hillup/data/SRTM1.py b/Hillup/data/SRTM1.py index 3781bb0..855aab0 100644 --- a/Hillup/data/SRTM1.py +++ b/Hillup/data/SRTM1.py @@ -4,8 +4,8 @@ from math import floor, log from os import unlink, close, write, chmod, makedirs from os.path import basename, exists, isdir, join -from httplib import HTTPConnection -from urlparse import urlparse +from http.client import HTTPConnection +from urllib.parse import urlparse from tempfile import mkstemp from zipfile import ZipFile from hashlib import md5 @@ -105,14 +105,14 @@ def datasource(lat, lon, source_dir): if not exists(dem_dir): makedirs(dem_dir) - chmod(dem_dir, 0777) + chmod(dem_dir, 0o777) assert isdir(dem_dir) # # Grab a fresh remote copy # - print >> stderr, 'Retrieving', url, 'in DEM.SRTM1.datasource().' + print('Retrieving', url, 'in DEM.SRTM1.datasource().', file=stderr) conn = HTTPConnection(host, 80) conn.request('GET', path) @@ -120,7 +120,7 @@ def datasource(lat, lon, source_dir): if resp.status == 404: # we're probably outside the coverage area - print >> open(dem_none, 'w'), url + print(url, file=open(dem_none, 'w')) return None assert resp.status == 200, (resp.status, resp.read()) @@ -142,7 +142,7 @@ def datasource(lat, lon, source_dir): dem_file.write(zipfile.read(zipfile.namelist()[0])) dem_file.close() - chmod(dem_path, 0666) + chmod(dem_path, 0o666) finally: unlink(zip_path) diff --git a/Hillup/data/SRTM3.py b/Hillup/data/SRTM3.py index e502f2d..99a1336 100644 --- a/Hillup/data/SRTM3.py +++ b/Hillup/data/SRTM3.py @@ -55,8 +55,8 @@ from math import floor, log from os import unlink, close, write, chmod, makedirs from os.path import basename, exists, isdir, join -from httplib import HTTPConnection -from urlparse import urlparse +from http.client import HTTPConnection +from urllib.parse import urlparse from tempfile import mkstemp from zipfile import ZipFile from hashlib import md5 @@ -199,14 +199,14 @@ def datasource(lat, lon, source_dir): if not exists(dem_dir): makedirs(dem_dir) - chmod(dem_dir, 0777) + chmod(dem_dir, 0o777) assert isdir(dem_dir) # # Grab a fresh remote copy # - print >> stderr, 'Retrieving', url, 'in DEM.SRTM3.datasource().' + print('Retrieving', url, 'in DEM.SRTM3.datasource().', file=stderr) conn = HTTPConnection(host, 80) conn.request('GET', path) @@ -214,7 +214,7 @@ def datasource(lat, lon, source_dir): if resp.status == 404: # we're probably outside the coverage area - print >> open(dem_none, 'w'), url + print(url, file=open(dem_none, 'w')) return None assert resp.status == 200, (resp.status, resp.read()) @@ -236,7 +236,7 @@ def datasource(lat, lon, source_dir): dem_file.write(zipfile.read(zipfile.namelist()[0])) dem_file.close() - chmod(dem_path, 0666) + chmod(dem_path, 0o666) finally: unlink(zip_path) diff --git a/Hillup/data/VFP.py b/Hillup/data/VFP.py index bcd9be6..a5e1dcc 100644 --- a/Hillup/data/VFP.py +++ b/Hillup/data/VFP.py @@ -1,8 +1,8 @@ from sys import stderr -from urlparse import urlparse, urljoin +from urllib.parse import urlparse, urljoin from os import unlink, close, write, chmod, makedirs from os.path import basename, exists, isdir, join -from httplib import HTTPConnection +from http.client import HTTPConnection from tempfile import mkstemp from zipfile import ZipFile from hashlib import md5 @@ -39,14 +39,14 @@ def datasource(lat, lon, source_dir): if not exists(dem_dir): makedirs(dem_dir) - chmod(dem_dir, 0777) + chmod(dem_dir, 0o777) assert isdir(dem_dir) # # Grab a fresh remote copy # - print >> stderr, 'Retrieving', url, 'in VFP.vfp_datasource().' + print('Retrieving', url, 'in VFP.vfp_datasource().', file=stderr) conn = HTTPConnection(host, 80) conn.request('GET', path) @@ -54,10 +54,10 @@ def datasource(lat, lon, source_dir): if resp.status == 404: # we're probably outside the coverage area, use SRTM3 instead - print >> open(dem_none, 'w'), url + print(url, file=open(dem_none, 'w')) return None - print >> stderr, 'Found', resp.getheader('location'), 'X-Zip-Path:', resp.getheader('x-zip-path') + print('Found', resp.getheader('location'), 'X-Zip-Path:', resp.getheader('x-zip-path'), file=stderr) assert resp.status in range(300, 399), (resp.status, resp.read()) @@ -67,7 +67,7 @@ def datasource(lat, lon, source_dir): # # Get the real zip archive # - print >> stderr, 'Getting', zip_location + print('Getting', zip_location, file=stderr) s, host, path, p, q, f = urlparse(zip_location) @@ -90,13 +90,13 @@ def datasource(lat, lon, source_dir): # # Write the actual DEM # - print >> stderr, 'Extracting', zip_filepath, 'to', dem_path + print('Extracting', zip_filepath, 'to', dem_path, file=stderr) dem_file = open(dem_path, 'w') dem_file.write(zipfile.read(zip_filepath)) dem_file.close() - chmod(dem_path, 0666) + chmod(dem_path, 0o666) finally: unlink(zip_path) diff --git a/Hillup/data/__init__.py b/Hillup/data/__init__.py index 6e15a09..4ca1994 100644 --- a/Hillup/data/__init__.py +++ b/Hillup/data/__init__.py @@ -6,7 +6,7 @@ from tempfile import mkstemp from sys import modules -import NED10m, NED100m, NED1km, SRTM1, SRTM3, VFP, Worldwide +from . import NED10m, NED100m, NED1km, SRTM1, SRTM3, VFP, Worldwide from ModestMaps.Core import Coordinate from TileStache.Geography import SphericalMercator @@ -299,7 +299,7 @@ def calculate_slope_aspect(elevation, xres, yres, z=1.0): window = [z * elevation[row:(row + height), col:(col + width)] for (row, col) - in product(range(3), range(3))] + in product(list(range(3)), list(range(3)))] x = ((window[0] + window[3] + window[3] + window[6]) \ - (window[2] + window[5] + window[5] + window[8])) \ diff --git a/Hillup/tiles.py b/Hillup/tiles.py index 2f28961..58c4f8f 100644 --- a/Hillup/tiles.py +++ b/Hillup/tiles.py @@ -1,9 +1,9 @@ from math import pi, log from tempfile import mkstemp from os import close, write, remove -from urlparse import urljoin, urlparse +from urllib.parse import urljoin, urlparse from os.path import join, exists -from urllib import urlopen +from urllib.request import urlopen from TileStache.Geography import SphericalMercator @@ -94,7 +94,7 @@ def render_tile(source_dir, coord, min_zoom): ul = original.zoomTo(coord.zoom).left(coord.column).up(coord.row) lr = original.down().right().zoomTo(coord.zoom).left(coord.column).up(coord.row) - left, top, right, bottom = map(int, (ul.column * w, ul.row * h, lr.column * w, lr.row * h)) + left, top, right, bottom = list(map(int, (ul.column * w, ul.row * h, lr.column * w, lr.row * h))) shaded = shaded[top:bottom, left:right] diff --git a/hillup-seed.py b/hillup-seed.py index 3b90483..8c85eb8 100755 --- a/hillup-seed.py +++ b/hillup-seed.py @@ -87,7 +87,7 @@ def generateCoordinates(ul, lr, zooms, padding): # read out zooms, columns, rows zxys = [line.strip().split('/') for line in open(options.tile_list)] - coords = [Coordinate(*map(int, (y, x, z))) for (z, x, y) in zxys] + coords = [Coordinate(*list(map(int, (y, x, z)))) for (z, x, y) in zxys] tiles = [(i, len(coords), coord) for (i, coord) in enumerate(coords)] else: @@ -117,4 +117,4 @@ def generateCoordinates(ul, lr, zooms, padding): mimetype, content = getTile(layer, coord, 'TIFF', True) - print coord + print(coord)