1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
--- kartograph/cli.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/cli.py
@@ -6,7 +6,7 @@ command line interface for kartograph
import argparse
import os
import os.path
-from options import read_map_config
+from .options import read_map_config
import sys
@@ -37,7 +37,7 @@ parser.add_argument('--format', '-f', metavar='svg', h
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 +74,7 @@ def render_map(args):
# print str(r)
pass
- except Exception, e:
+ except Exception as e:
print_error(e)
exit(-1)
@@ -98,17 +98,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)
--- kartograph/kartograph.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/kartograph.py
@@ -1,11 +1,11 @@
-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 +64,14 @@ class Kartograph(object):
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:
--- kartograph/layersource/postgislayer.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/layersource/postgislayer.py
@@ -1,5 +1,5 @@
-from layersource import LayerSource
+from .layersource import LayerSource
from kartograph.errors import *
from kartograph.geometry import create_feature
import shapely.wkb
@@ -72,11 +72,11 @@ class PostGISLayer(LayerSource):
if fields[f] != self.geom_col:
# but ignore null values
if rec[f]:
- if isinstance(rec[f], (str, unicode)):
+ if isinstance(rec[f], str):
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]
@@ -84,7 +84,7 @@ class PostGISLayer(LayerSource):
# Store geometry
geom_wkb = rec[f]
- if filter is None or filter(meta):
+ if filter is None or list(filter(meta)):
# construct geometry
geom = shapely.wkb.loads(geom_wkb.decode('hex'))
# Finally we construct the map feature and append it to the
--- kartograph/layersource/shplayer.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/layersource/shplayer.py
@@ -1,11 +1,11 @@
-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
@@ -20,7 +20,7 @@ class ShapefileLayer(LayerSource):
"""
initialize shapefile reader
"""
- if isinstance(src, unicode):
+ if isinstance(src, str):
src = src.encode('ascii', 'ignore')
src = self.find_source(src)
self.shpSrc = src
@@ -93,7 +93,7 @@ class ShapefileLayer(LayerSource):
for j in range(len(self.attributes)):
drec[self.attributes[j]] = self.recs[i][j]
# For each record that is not filtered..
- if filter is None or filter(drec):
+ if filter is None or list(filter(drec)):
props = {}
# ..we try to decode the attributes (shapefile charsets are arbitrary)
for j in range(len(self.attributes)):
@@ -107,10 +107,10 @@ class ShapefileLayer(LayerSource):
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)):
+ if isinstance(val, str):
val = val.strip()
props[self.attributes[j]] = val
@@ -129,7 +129,7 @@ class ShapefileLayer(LayerSource):
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
--- kartograph/map.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/map.py
@@ -1,11 +1,11 @@
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 +154,7 @@ class Map(object):
### 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 +306,7 @@ class Map(object):
"""
### 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 +421,7 @@ class Map(object):
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 +517,7 @@ class Map(object):
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
--- kartograph/proj/__init__.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/proj/__init__.py
@@ -18,8 +18,8 @@
projections = dict()
-from base import Proj
-from cylindrical import *
+from .base import Proj
+from .cylindrical import *
projections['lonlat'] = Equirectangular
projections['cea'] = CEA
@@ -30,7 +30,7 @@ projections['balthasart'] = Balthasart
projections['mercator'] = Mercator
projections['ll'] = LonLat
-from pseudocylindrical import *
+from .pseudocylindrical import *
projections['naturalearth'] = NaturalEarth
projections['robinson'] = Robinson
@@ -47,7 +47,7 @@ projections['aitoff'] = Aitoff
projections['winkel3'] = Winkel3
projections['nicolosi'] = Nicolosi
-from azimuthal import *
+from .azimuthal import *
projections['ortho'] = Orthographic
projections['laea'] = LAEA
@@ -58,11 +58,11 @@ projections['satellite'] = Satellite
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 +78,7 @@ if __name__ == '__main__':
#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 +87,10 @@ if __name__ == '__main__':
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
--- kartograph/proj/azimuthal/azimuthal.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/proj/azimuthal/azimuthal.py
@@ -62,7 +62,7 @@ class Azimuthal(Proj):
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
--- kartograph/renderer/svg.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/renderer/svg.py
@@ -239,7 +239,7 @@ class SvgRenderer(MapRenderer):
key = labelOpts['key']
if not key:
- key = feature.props.keys()[0]
+ key = list(feature.props.keys())[0]
if key not in feature.props:
#sys.stderr.write('could not find feature property "%s" for labeling\n' % key)
return
@@ -411,7 +411,7 @@ class SvgDocument(object):
# Here we finally write the SVG file, and we're brave enough
# to try to write it in Unicode.
def write(self, outfile, pretty_print=False):
- if isinstance(outfile, (str, unicode)):
+ if isinstance(outfile, str):
outfile = open(outfile, 'w')
if pretty_print:
raw = self.doc.toprettyxml('utf-8')
@@ -420,7 +420,7 @@ class SvgDocument(object):
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 +431,7 @@ class SvgDocument(object):
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])
--- kartograph/yaml_ordered_dict.py.orig 2014-03-27 03:57:55 UTC
+++ kartograph/yaml_ordered_dict.py
@@ -19,8 +19,8 @@ class OrderedDictYAMLLoader(yaml.Loader):
def __init__(self, *args, **kwargs):
yaml.Loader.__init__(self, *args, **kwargs)
- self.add_constructor(u'tag:yaml.org,2002:map', type(self).construct_yaml_map)
- self.add_constructor(u'tag:yaml.org,2002:omap', type(self).construct_yaml_map)
+ self.add_constructor('tag:yaml.org,2002:map', type(self).construct_yaml_map)
+ self.add_constructor('tag:yaml.org,2002:omap', type(self).construct_yaml_map)
def construct_yaml_map(self, node):
data = OrderedDict()
@@ -40,7 +40,7 @@ class OrderedDictYAMLLoader(yaml.Loader):
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 +63,4 @@ two:
data = yaml.load(textwrap.dedent(sample), OrderedDictYAMLLoader)
assert type(data) is OrderedDict
- print data
\ No newline at end of file
+ print(data)
|