import re import sys from mapnik_utils.version_adapter import Mapnik mapnik = Mapnik() # mapnik_utils from mapnik_utils.projection import EasyProjection if not hasattr(mapnik, 'ProjTransform'): from compatibility import ProjTransform BoostPythonMetaclass = mapnik.Coord.__class__ class _injector(object): class __metaclass__(BoostPythonMetaclass): def __init__(self, name, bases, dict): for b in bases: if type(b) not in (self, type): for k, v in dict.items(): setattr(b, k, v) return type.__init__(self, name, bases, dict) if not hasattr(mapnik, 'Box2d'): mapnik.Box2d = mapnik.Envelope class _Map(mapnik.Map, _injector):
parser.add_option('--mapnik-version', dest='mapnik_version', action='store', default=2, help='Use the mapnik2 python bindings if they exist', type='int') if __name__ == '__main__': (options, args) = parser.parse_args() # we're actually starting now so pull in mapnik # this version adapter is a nasty hack to globally # control usage of either mapnik or mapnik2 from mapnik_utils.version_adapter import Mapnik mapnik = Mapnik(options.mapnik_version) if not sys.stdin.isatty(): xml = sys.stdin.read() if hasattr(mapnik, 'load_map_from_string'): options.from_string = True mapfile = xml else: options.from_string = False (handle, mapfile) = tempfile.mkstemp('.xml', 'mapfile_string') os.close(handle) open(mapfile, 'w').write(xml) if len(args) > 0: options.image = args[0] elif len(args) == 0: parser.error(