diff --git a/kartograph/__init__.py b/kartograph/__init__.py
index 87acd1f..09d10ad 100644
--- a/kartograph/__init__.py
+++ b/kartograph/__init__.py
@@ -1,6 +1,7 @@
+from __future__ import absolute_import
-from kartograph import Kartograph
-from kartograph import verbose
-from map import projections
+from .kartograph import Kartograph
+from .kartograph import verbose
+from .map import projections
__all__ = ['Kartograph', 'projections', 'verbose']
diff --git a/kartograph/cartogram.py b/kartograph/cartogram.py
index 290c00c..1deb5df 100644
--- a/kartograph/cartogram.py
+++ b/kartograph/cartogram.py
@@ -2,6 +2,7 @@
"""
computes a circle cartogram for a given svg map + data file
"""
+from __future__ import absolute_import
import sys
class Cartogram:
@@ -61,7 +62,7 @@ def load_csv(self, url, key='id', value='val'):
def compute_radii(self):
import sys, math
minv = 0
- maxv = sys.maxint * -1
+ maxv = sys.maxsize * -1
for c in self.circles:
minv = min(minv, c.value)
maxv = max(maxv, c.value)
@@ -105,7 +106,7 @@ def layout_step(self, correct=False):
C.move()
def rescale(self):
- from geometry import BBox, View
+ from .geometry import BBox, View
svg = self.svg
svg_view = svg[1][0][0]
vh = float(svg_view['h'])
diff --git a/kartograph/cli.py b/kartograph/cli.py
index 524d7e4..fb9e4ac 100755
--- a/kartograph/cli.py
+++ b/kartograph/cli.py
@@ -2,11 +2,13 @@
"""
command line interface for kartograph
"""
+from __future__ import print_function
+from __future__ import absolute_import
import argparse
import os
import os.path
-from options import read_map_config
+from .options import read_map_config
import sys
@@ -37,7 +39,7 @@ def disable(self):
parser.add_argument('--preview', '-p', nargs='?', metavar='', const=True, help='opens the generated svg for preview')
parser.add_argument('--pretty-print', '-P', dest='pretty_print', action='store_true', help='pretty print the svg file')
-from kartograph import Kartograph
+from .kartograph import Kartograph
import time
import os
@@ -74,7 +76,7 @@ def render_map(args):
# print str(r)
pass
- except Exception, e:
+ except Exception as e:
print_error(e)
exit(-1)
@@ -98,17 +100,17 @@ def main():
try:
args = parser.parse_args()
- except IOError, e:
+ except IOError as e:
# parser.print_help()
sys.stderr.write('\n' + str(e) + '\n')
- except Exception, e:
+ except Exception as e:
parser.print_help()
- print '\nError:', e
+ print('\nError:', e)
else:
args.func(args)
elapsed = (time.time() - start)
if args.output != '-':
- print 'execution time: %.3f secs' % elapsed
+ print('execution time: %.3f secs' % elapsed)
sys.exit(0)
diff --git a/kartograph/geometry/__init__.py b/kartograph/geometry/__init__.py
index 7adf6ed..d508864 100644
--- a/kartograph/geometry/__init__.py
+++ b/kartograph/geometry/__init__.py
@@ -2,10 +2,11 @@
"""
geometry package
"""
+from __future__ import absolute_import
__all__ = ['Feature', 'BBox', 'Point', 'View', 'create_feature']
-from feature import *
-from point import Point
-from bbox import BBox
-from view import View
+from .feature import *
+from .point import Point
+from .bbox import BBox
+from .view import View
diff --git a/kartograph/geometry/bbox.py b/kartograph/geometry/bbox.py
index 19918c4..451fb3e 100644
--- a/kartograph/geometry/bbox.py
+++ b/kartograph/geometry/bbox.py
@@ -1,5 +1,6 @@
+from __future__ import absolute_import
-from point import Point
+from .point import Point
class BBox(object):
@@ -7,15 +8,15 @@ class BBox(object):
def __init__(self, width=None, height=None, left=0, top=0):
import sys
if width == None:
- self.xmin = sys.maxint
- self.xmax = sys.maxint * -1
+ self.xmin = sys.maxsize
+ self.xmax = sys.maxsize * -1
else:
self.xmin = self.left = left
self.xmax = self.right = left + width
self.width = width
if height == None:
- self.ymin = sys.maxint
- self.ymax = sys.maxint * -1
+ self.ymin = sys.maxsize
+ self.ymax = sys.maxsize * -1
else:
self.ymin = self.top = top
self.ymax = self.bottom = height + top
diff --git a/kartograph/geometry/feature/MultiLineFeature.py b/kartograph/geometry/feature/MultiLineFeature.py
index a072adf..7108b37 100644
--- a/kartograph/geometry/feature/MultiLineFeature.py
+++ b/kartograph/geometry/feature/MultiLineFeature.py
@@ -1,4 +1,5 @@
-from Feature import Feature
+from __future__ import absolute_import
+from .Feature import Feature
from kartograph.simplify.unify import unify_rings
diff --git a/kartograph/geometry/feature/MultiPolygonFeature.py b/kartograph/geometry/feature/MultiPolygonFeature.py
index 01c272c..abc500c 100644
--- a/kartograph/geometry/feature/MultiPolygonFeature.py
+++ b/kartograph/geometry/feature/MultiPolygonFeature.py
@@ -1,4 +1,5 @@
-from Feature import Feature
+from __future__ import absolute_import
+from .Feature import Feature
from kartograph.errors import KartographError
from kartograph.simplify.unify import unify_rings
@@ -113,12 +114,12 @@ def restore_geometry(self, lines, minArea=0):
polygons = []
holes_total = 0
for num_hole in self._topology_num_holes:
- ext = ring_iter.next()
- island = islands_iter.next()
+ ext = next(ring_iter)
+ island = next(islands_iter)
holes = []
while num_hole > 0:
- hole = ring_iter.next()
- islands_iter.next() # skip island flag for holes
+ hole = next(ring_iter)
+ next(islands_iter) # skip island flag for holes
if len(hole) > 3:
holes.append(hole)
holes_total += 1
diff --git a/kartograph/geometry/feature/PointFeature.py b/kartograph/geometry/feature/PointFeature.py
index 78be899..d3a7d1a 100644
--- a/kartograph/geometry/feature/PointFeature.py
+++ b/kartograph/geometry/feature/PointFeature.py
@@ -1,5 +1,6 @@
+from __future__ import absolute_import
-from Feature import Feature
+from .Feature import Feature
class PointFeature(Feature):
diff --git a/kartograph/geometry/feature/__init__.py b/kartograph/geometry/feature/__init__.py
index 95a4036..aa5ad8d 100644
--- a/kartograph/geometry/feature/__init__.py
+++ b/kartograph/geometry/feature/__init__.py
@@ -2,13 +2,14 @@
"""
package geometry.feature
"""
+from __future__ import absolute_import
__all__ = ['Feature', 'MultiPolygonFeature', 'create_feature', 'MultiLineFeature', 'PointFeature']
-from Feature import Feature
-from MultiPolygonFeature import MultiPolygonFeature
-from MultiLineFeature import MultiLineFeature
-from PointFeature import PointFeature
+from .Feature import Feature
+from .MultiPolygonFeature import MultiPolygonFeature
+from .MultiLineFeature import MultiLineFeature
+from .PointFeature import PointFeature
def create_feature(geom, props):
diff --git a/kartograph/geometry/utils.py b/kartograph/geometry/utils.py
index 6a64231..ebefba6 100644
--- a/kartograph/geometry/utils.py
+++ b/kartograph/geometry/utils.py
@@ -1,6 +1,7 @@
"""
geometry utils
"""
+from __future__ import absolute_import
def is_clockwise(pts):
@@ -61,7 +62,7 @@ def geom_to_bbox(geom, min_area=0):
def join_features(features, props, buf=False):
""" joins polygonal features
"""
- from feature import MultiPolygonFeature, MultiLineFeature
+ from .feature import MultiPolygonFeature, MultiLineFeature
from shapely.ops import linemerge
if len(features) == 0:
diff --git a/kartograph/kartograph.py b/kartograph/kartograph.py
index 473686c..3748c5f 100644
--- a/kartograph/kartograph.py
+++ b/kartograph/kartograph.py
@@ -1,11 +1,13 @@
+from __future__ import print_function
+from __future__ import absolute_import
-from options import parse_options
+from .options import parse_options
from shapely.geometry import Polygon, LineString, MultiPolygon
-from errors import *
+from .errors import *
from copy import deepcopy
-from renderer import SvgRenderer
-from mapstyle import MapStyle
-from map import Map
+from .renderer import SvgRenderer
+from .mapstyle import MapStyle
+from .map import Map
import os
@@ -64,14 +66,14 @@ def generate(self, opts, outfile=None, format='svg', preview=None, stylesheet=No
command = commands[sys.platform]
else:
sys.stderr.write('don\'t know how to preview SVGs on your system. Try setting the KARTOGRAPH_PREVIEW environment variable.')
- print renderer
+ print(renderer)
return
renderer.preview(command)
# Write the map to a file or return the renderer instance.
if outfile is None:
return renderer
elif outfile == '-':
- print renderer
+ print(renderer)
else:
renderer.write(outfile)
else:
diff --git a/kartograph/layersource/__init__.py b/kartograph/layersource/__init__.py
index 9214e02..7ee32e2 100644
--- a/kartograph/layersource/__init__.py
+++ b/kartograph/layersource/__init__.py
@@ -5,14 +5,15 @@
- KML ? (only polygons and polylines)
- GeoJSON ?
"""
+from __future__ import absolute_import
__all__ = ['LayerSource', 'ShapefileLayer', 'CsvLayer', 'GraticuleLayer', 'PostGISLayer']
-from shplayer import ShapefileLayer
-from csvlayer import CsvLayer
-from postgislayer import PostGISLayer
-from layersource import LayerSource
-from special import GraticuleLayer, SeaLayer
+from .shplayer import ShapefileLayer
+from .csvlayer import CsvLayer
+from .postgislayer import PostGISLayer
+from .layersource import LayerSource
+from .special import GraticuleLayer, SeaLayer
from kartograph.errors import *
diff --git a/kartograph/layersource/csvlayer.py b/kartograph/layersource/csvlayer.py
index 1777289..6016f2b 100644
--- a/kartograph/layersource/csvlayer.py
+++ b/kartograph/layersource/csvlayer.py
@@ -1,5 +1,6 @@
+from __future__ import absolute_import
-from layersource import LayerSource
+from .layersource import LayerSource
from kartograph.errors import *
from kartograph.geometry import BBox, create_feature
from shapely.geometry import LineString, Point, Polygon
@@ -24,7 +25,7 @@ def __init__(self, src, mode, xfield, yfield, dialect, crs):
src = src.encode('ascii', 'ignore')
self.cr = UnicodeReader(open(src), dialect=dialect)
# read csv header
- self.header = h = self.cr.next()
+ self.header = h = next(self.cr)
# initialize CRS
self.proj = None
self.mode = mode
@@ -100,7 +101,7 @@ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
self.reader = csv.reader(f, dialect=dialect, **kwds)
def next(self):
- row = self.reader.next()
+ row = next(self.reader)
return [unicode(s, "utf-8") for s in row]
def __iter__(self):
diff --git a/kartograph/layersource/postgislayer.py b/kartograph/layersource/postgislayer.py
index ebfc879..6205565 100644
--- a/kartograph/layersource/postgislayer.py
+++ b/kartograph/layersource/postgislayer.py
@@ -1,5 +1,7 @@
+from __future__ import print_function
+from __future__ import absolute_import
-from layersource import LayerSource
+from .layersource import LayerSource
from kartograph.errors import *
from kartograph.geometry import create_feature
import shapely.wkb
@@ -76,7 +78,7 @@ def get_features(self, filter=None, bbox=None, verbose=False, ignore_holes=False
try:
meta[fields[f]] = rec[f].decode('utf-8')
except:
- print 'decoding error', fields[f], rec[f]
+ print('decoding error', fields[f], rec[f])
meta[fields[f]] = '--decoding error--'
else:
meta[fields[f]] = rec[f]
diff --git a/kartograph/layersource/shplayer.py b/kartograph/layersource/shplayer.py
index abd7dab..9979e6b 100644
--- a/kartograph/layersource/shplayer.py
+++ b/kartograph/layersource/shplayer.py
@@ -1,11 +1,13 @@
+from __future__ import print_function
+from __future__ import absolute_import
-from layersource import LayerSource
+from .layersource import LayerSource
from kartograph.errors import *
from kartograph.geometry import BBox, create_feature
from os.path import exists
from osgeo.osr import SpatialReference
import pyproj
-import shapefile
+from . import shapefile
verbose = False
@@ -107,7 +109,7 @@ def get_features(self, attr=None, filter=None, bbox=None, ignore_holes=False, mi
break
except:
if verbose:
- print 'warning: could not decode "%s" to %s' % (val, enc)
+ print('warning: could not decode "%s" to %s' % (val, enc))
if not decoded:
raise KartographError('having problems to decode the input data "%s"' % val)
if isinstance(val, (str, unicode)):
@@ -129,7 +131,7 @@ def get_features(self, attr=None, filter=None, bbox=None, ignore_holes=False, mi
feature = create_feature(geom, props)
res.append(feature)
if bbox is not None and ignored > 0 and verbose:
- print "-ignoring %d shapes (not in bounds %s )" % (ignored, bbox)
+ print("-ignoring %d shapes (not in bounds %s )" % (ignored, bbox))
return res
# # shape2geometry
diff --git a/kartograph/layersource/special/__init__.py b/kartograph/layersource/special/__init__.py
index d21621c..f0c199f 100644
--- a/kartograph/layersource/special/__init__.py
+++ b/kartograph/layersource/special/__init__.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
-from graticule import GraticuleLayer
-from sea import SeaLayer
\ No newline at end of file
+from .graticule import GraticuleLayer
+from .sea import SeaLayer
\ No newline at end of file
diff --git a/kartograph/map.py b/kartograph/map.py
index 059d39a..7e9395d 100644
--- a/kartograph/map.py
+++ b/kartograph/map.py
@@ -1,11 +1,13 @@
+from __future__ import print_function
+from __future__ import absolute_import
from shapely.geometry import Polygon
from shapely.geometry.base import BaseGeometry
-from maplayer import MapLayer
-from geometry.utils import geom_to_bbox
-from geometry import BBox, View
-from proj import projections
-from filter import filter_record
-from errors import KartographError
+from .maplayer import MapLayer
+from .geometry.utils import geom_to_bbox
+from .geometry import BBox, View
+from .proj import projections
+from .filter import filter_record
+from .errors import KartographError
import sys
# Map
@@ -154,7 +156,7 @@ def _init_bounds(self):
### Initialize bounding polygons and bounding box
### Compute the projected bounding box
"""
- from geometry.utils import bbox_to_polygon
+ from .geometry.utils import bbox_to_polygon
opts = self.options
proj = self.proj
@@ -306,7 +308,7 @@ def _simplify_layers(self):
"""
### Simplify geometries
"""
- from simplify import create_point_store, simplify_lines
+ from .simplify import create_point_store, simplify_lines
# We will use a glocal point cache for all layers. If the
# same point appears in more than one layer, it will be
@@ -421,7 +423,7 @@ def _join_features(self):
a single feature. Kartograph uses the geometry.union() method of shapely
to do that.
"""
- from geometry.utils import join_features
+ from .geometry.utils import join_features
for layer in self.layers:
if layer.options['join'] is not False:
@@ -517,7 +519,7 @@ def _join_features(self):
for feat in groupFeatures[g_id]:
exp[g_id].append(feat.props[join['export-ids']])
import json
- print json.dumps(exp)
+ print(json.dumps(exp))
layer.features = res
diff --git a/kartograph/maplayer.py b/kartograph/maplayer.py
index 9f8639e..d41510a 100644
--- a/kartograph/maplayer.py
+++ b/kartograph/maplayer.py
@@ -1,6 +1,7 @@
+from __future__ import absolute_import
-from layersource import handle_layer_source
-from filter import filter_record
+from .layersource import handle_layer_source
+from .filter import filter_record
_verbose = False
diff --git a/kartograph/options.py b/kartograph/options.py
index 650999f..e313259 100644
--- a/kartograph/options.py
+++ b/kartograph/options.py
@@ -3,10 +3,11 @@
API 2.0
helper methods for validating options dictionary
"""
+from __future__ import absolute_import
import os.path
-import proj
-import errors
+from . import proj
+from . import errors
import sys
Error = errors.KartographError
@@ -40,7 +41,7 @@ def read_map_config(f):
return cfg
elif ext in ('.yaml', '.yml'):
import yaml
- from yaml_ordered_dict import OrderedDictYAMLLoader
+ from .yaml_ordered_dict import OrderedDictYAMLLoader
try:
cfg = yaml.load(content, OrderedDictYAMLLoader)
except Exception:
diff --git a/kartograph/proj/__init__.py b/kartograph/proj/__init__.py
index de57fc0..17ba05f 100644
--- a/kartograph/proj/__init__.py
+++ b/kartograph/proj/__init__.py
@@ -15,11 +15,13 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import print_function
+from __future__ import absolute_import
projections = dict()
-from base import Proj
-from cylindrical import *
+from .base import Proj
+from .cylindrical import *
projections['lonlat'] = Equirectangular
projections['cea'] = CEA
@@ -30,7 +32,7 @@
projections['mercator'] = Mercator
projections['ll'] = LonLat
-from pseudocylindrical import *
+from .pseudocylindrical import *
projections['naturalearth'] = NaturalEarth
projections['robinson'] = Robinson
@@ -47,7 +49,7 @@
projections['winkel3'] = Winkel3
projections['nicolosi'] = Nicolosi
-from azimuthal import *
+from .azimuthal import *
projections['ortho'] = Orthographic
projections['laea'] = LAEA
@@ -58,11 +60,11 @@
projections['eda'] = EquidistantAzimuthal
projections['aitoff'] = Aitoff
-from conic import *
+from .conic import *
projections['lcc'] = LCC
-from proj4 import Proj4
+from .proj4 import Proj4
projections['proj4'] = Proj4
@@ -78,7 +80,7 @@
#assert (round(x,2),round(y,2)) == (3962799.45, -2999718.85), 'LAEA proj error'
from kartograph.geometry import BBox
- print Proj.fromXML(Robinson(lat0=3, lon0=4).toXML(), projections)
+ print(Proj.fromXML(Robinson(lat0=3, lon0=4).toXML(), projections))
Robinson(lat0=3, lon0=4)
@@ -87,10 +89,10 @@
bbox = BBox()
try:
proj = Proj(lon0=60)
- print proj.project(0, 0)
- print proj.world_bounds(bbox)
- print proj.toXML()
+ print(proj.project(0, 0))
+ print(proj.world_bounds(bbox))
+ print(proj.toXML())
except:
- print 'Error', pj
- print sys.exc_info()[0]
+ print('Error', pj)
+ print(sys.exc_info()[0])
raise
diff --git a/kartograph/proj/azimuthal/__init__.py b/kartograph/proj/azimuthal/__init__.py
index 383686d..1133c7a 100644
--- a/kartograph/proj/azimuthal/__init__.py
+++ b/kartograph/proj/azimuthal/__init__.py
@@ -15,12 +15,13 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from azimuthal import Azimuthal
-from ortho import Orthographic
-from laea import LAEA, P4_LAEA, LAEA_USA
-from stereo import Stereographic
-from satellite import Satellite
-from equi import EquidistantAzimuthal
+from .azimuthal import Azimuthal
+from .ortho import Orthographic
+from .laea import LAEA, P4_LAEA, LAEA_USA
+from .stereo import Stereographic
+from .satellite import Satellite
+from .equi import EquidistantAzimuthal
__all__ = ['Azimuthal', 'Orthographic', 'LAEA', 'LAEA_USA', 'P4_LAEA', 'Stereographic', 'Satellite', 'EquidistantAzimuthal']
diff --git a/kartograph/proj/azimuthal/azimuthal.py b/kartograph/proj/azimuthal/azimuthal.py
index 1322e8c..8bf172b 100644
--- a/kartograph/proj/azimuthal/azimuthal.py
+++ b/kartograph/proj/azimuthal/azimuthal.py
@@ -15,6 +15,7 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import print_function
import math
from kartograph.proj.base import Proj
@@ -62,7 +63,7 @@ def world_bounds(self, bbox, llbbox=(-180, -90, 180, 90)):
def sea_shape(self, llbbox=(-180, -90, 180, 90)):
out = []
if llbbox == (-180, -90, 180, 90) or llbbox == [-180, -90, 180, 90]:
- print "-> full extend"
+ print("-> full extend")
for phi in range(0, 360):
x = self.r + math.cos(math.radians(phi)) * self.r
y = self.r + math.sin(math.radians(phi)) * self.r
diff --git a/kartograph/proj/azimuthal/equi.py b/kartograph/proj/azimuthal/equi.py
index bf468aa..d0589c8 100644
--- a/kartograph/proj/azimuthal/equi.py
+++ b/kartograph/proj/azimuthal/equi.py
@@ -15,8 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from azimuthal import Azimuthal
+from .azimuthal import Azimuthal
import math
diff --git a/kartograph/proj/azimuthal/laea.py b/kartograph/proj/azimuthal/laea.py
index c93da2c..94ebab0 100644
--- a/kartograph/proj/azimuthal/laea.py
+++ b/kartograph/proj/azimuthal/laea.py
@@ -15,8 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from azimuthal import Azimuthal
+from .azimuthal import Azimuthal
import math
import pyproj
diff --git a/kartograph/proj/azimuthal/ortho.py b/kartograph/proj/azimuthal/ortho.py
index f9d3cb8..44f8d52 100644
--- a/kartograph/proj/azimuthal/ortho.py
+++ b/kartograph/proj/azimuthal/ortho.py
@@ -15,8 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from azimuthal import Azimuthal
+from .azimuthal import Azimuthal
import math
diff --git a/kartograph/proj/azimuthal/satellite.py b/kartograph/proj/azimuthal/satellite.py
index 0bf5cf3..3720c2a 100644
--- a/kartograph/proj/azimuthal/satellite.py
+++ b/kartograph/proj/azimuthal/satellite.py
@@ -15,8 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from azimuthal import Azimuthal
+from .azimuthal import Azimuthal
import math
@@ -41,8 +42,8 @@ def __init__(self, lat0=0.0, lon0=0.0, dist=1.6, up=0, tilt=0):
self.tilt_ = math.radians(tilt)
self.scale = 1
- xmin = sys.maxint
- xmax = sys.maxint * -1
+ xmin = sys.maxsize
+ xmax = sys.maxsize * -1
for lat in range(0, 180):
for lon in range(0, 361):
x, y = self.project(lon - 180, lat - 90)
diff --git a/kartograph/proj/azimuthal/stereo.py b/kartograph/proj/azimuthal/stereo.py
index aafba67..bf405ae 100644
--- a/kartograph/proj/azimuthal/stereo.py
+++ b/kartograph/proj/azimuthal/stereo.py
@@ -15,8 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from azimuthal import Azimuthal
+from .azimuthal import Azimuthal
class Stereographic(Azimuthal):
diff --git a/kartograph/proj/conic.py b/kartograph/proj/conic.py
index c72ede1..d435a52 100644
--- a/kartograph/proj/conic.py
+++ b/kartograph/proj/conic.py
@@ -15,9 +15,10 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from base import Proj
+from .base import Proj
import math
from math import radians as rad
diff --git a/kartograph/proj/cylindrical.py b/kartograph/proj/cylindrical.py
index 5e570c9..f24f4cc 100644
--- a/kartograph/proj/cylindrical.py
+++ b/kartograph/proj/cylindrical.py
@@ -15,8 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from base import Proj
+from .base import Proj
import math
from math import radians as rad
diff --git a/kartograph/proj/pseudocylindrical.py b/kartograph/proj/pseudocylindrical.py
index 3653eaa..71aa425 100644
--- a/kartograph/proj/pseudocylindrical.py
+++ b/kartograph/proj/pseudocylindrical.py
@@ -15,8 +15,9 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
"""
+from __future__ import absolute_import
-from cylindrical import Cylindrical
+from .cylindrical import Cylindrical
import math
from math import radians as rad
diff --git a/kartograph/renderer/__init__.py b/kartograph/renderer/__init__.py
index 4dab1cb..e6f8e8a 100644
--- a/kartograph/renderer/__init__.py
+++ b/kartograph/renderer/__init__.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
class MapRenderer(object):
@@ -9,12 +10,12 @@ def render(self):
pass
def write(self, filename):
- raise 'Not implemented yet'
+ raise NotImplementedError('Not implemented yet')
def preview(self):
- raise 'Not implemented yet'
+ raise NotImplementedError('Not implemented yet')
-from svg import SvgRenderer
+from .svg import SvgRenderer
__all__ = ['MapRenderer', 'SvgRenderer']
diff --git a/kartograph/renderer/svg.py b/kartograph/renderer/svg.py
index 40e6e44..8ea6c3a 100644
--- a/kartograph/renderer/svg.py
+++ b/kartograph/renderer/svg.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
from kartograph.renderer import MapRenderer
from kartograph.errors import KartographError
@@ -420,7 +421,7 @@ def write(self, outfile, pretty_print=False):
try:
raw = raw.encode('utf-8')
except:
- print 'warning: could not encode to unicode'
+ print('warning: could not encode to unicode')
outfile.write(raw)
outfile.close()
@@ -431,7 +432,7 @@ def preview(self, command, pretty_print=False):
import tempfile
tmpfile = tempfile.NamedTemporaryFile(suffix='.svg', delete=False)
self.write(tmpfile, pretty_print)
- print 'map stored to', tmpfile.name
+ print('map stored to', tmpfile.name)
from subprocess import call
call([command, tmpfile.name])
diff --git a/kartograph/simplify/__init__.py b/kartograph/simplify/__init__.py
index 34c9d69..73578b4 100644
--- a/kartograph/simplify/__init__.py
+++ b/kartograph/simplify/__init__.py
@@ -1,10 +1,11 @@
+from __future__ import absolute_import
__all__ = ['create_point_store', 'unify_polygon', 'unify_polygons', 'simplify_lines']
-from unify import *
-from distance import simplify_distance
-from douglas_peucker import simplify_douglas_peucker
-from visvalingam import simplify_visvalingam_whyatt
+from .unify import *
+from .distance import simplify_distance
+from .douglas_peucker import simplify_douglas_peucker
+from .visvalingam import simplify_visvalingam_whyatt
simplification_methods = dict()
diff --git a/kartograph/simplify/unify.py b/kartograph/simplify/unify.py
index dba9633..da1407b 100644
--- a/kartograph/simplify/unify.py
+++ b/kartograph/simplify/unify.py
@@ -1,5 +1,6 @@
+from __future__ import absolute_import
-from mpoint import MPoint
+from .mpoint import MPoint
"""
the whole point of the unification step is to convert all points into unique MPoint instances
diff --git a/kartograph/yaml_ordered_dict.py b/kartograph/yaml_ordered_dict.py
index dd04e99..7b0c208 100644
--- a/kartograph/yaml_ordered_dict.py
+++ b/kartograph/yaml_ordered_dict.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
import yaml
import yaml.constructor
@@ -40,7 +41,7 @@ def construct_mapping(self, node, deep=False):
key = self.construct_object(key_node, deep=deep)
try:
hash(key)
- except TypeError, exc:
+ except TypeError as exc:
raise yaml.constructor.ConstructorError('while constructing a mapping',
node.start_mark, 'found unacceptable key (%s)' % exc, key_node.start_mark)
value = self.construct_object(value_node, deep=deep)
@@ -63,4 +64,4 @@ def construct_mapping(self, node, deep=False):
data = yaml.load(textwrap.dedent(sample), OrderedDictYAMLLoader)
assert type(data) is OrderedDict
- print data
\ No newline at end of file
+ print(data)
\ No newline at end of file
diff --git a/tests/run_tests.py b/tests/run_tests.py
index cdd6970..6d18d7a 100644
--- a/tests/run_tests.py
+++ b/tests/run_tests.py
@@ -1,3 +1,4 @@
+from __future__ import print_function
from kartograph import Kartograph
import sys
from os import mkdir, remove
@@ -11,10 +12,10 @@
if not exists('data/ne_50m_admin_0_countries.shp'):
# download natural earth shapefile
- print 'I need a shapefile to test with. Will download one from naturalearthdata.com\n'
+ print('I need a shapefile to test with. Will download one from naturalearthdata.com\n')
from subprocess import call
call(['wget', 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip'])
- print '\nUnzipping...\n'
+ print('\nUnzipping...\n')
call(['unzip', 'ne_50m_admin_0_countries.zip', '-d', 'data'])
passed = 0
@@ -24,7 +25,7 @@
for fn in glob('configs/*.*'):
fn_parts = splitext(basename(fn))
- print 'running text', basename(fn), '...',
+ print('running text', basename(fn), '...', end=' ')
try:
cfg = read_map_config(open(fn))
K = Kartograph()
@@ -36,9 +37,9 @@
if exists(svg_url):
remove(svg_url)
K.generate(cfg, 'results/' + fn_parts[0] + '.svg', preview=False, format='svg', stylesheet=css)
- print 'ok.'
+ print('ok.')
passed += 1
- except Exception, e:
+ except Exception as e:
import traceback
ignore_path_len = len(__file__) - 7
exc = sys.exc_info()
@@ -47,7 +48,7 @@
log.write(' %s, in %s()\n %d: %s\n' % (filename, func, line, code))
log.write('\n')
log.write(str(e))
- print 'failed.'
+ print('failed.')
failed += 1
-print 'passed: %d\nfailed: %d' % (passed, failed)
+print('passed: %d\nfailed: %d' % (passed, failed))