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):
import os import sys import timeit from mapnik_utils.version_adapter import Mapnik mapnik = Mapnik() class Load(object): def __init__(self,mapfile,variables={},from_string=False): self.mapfile = mapfile self.from_string = from_string self.variables = variables self.start_time = 0 self.load_map_time = 0 self.mapfile_types = {'xml':'XML mapfile','mml':'Mapnik Markup Language', 'py':'Python map variable'} if self.from_string: self.file_type = 'xml' else: self.file_type = self.get_type() self.validate() def timer(self): self.start_time = timeit.time.time() def stop(self): self.load_map_time = timeit.time.time() - self.start_time
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(
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): def set_easy_srs(self,srs): self.srs = EasyProjection(srs).params()
parser.add_option( '--aspect-fix-mode', dest='aspect_fix_mode', type='string', help= 'Pass an aspect_fix_mode string (case-insensitive match of http://media.mapnik.org/api_docs/python/mapnik._mapnik.aspect_fix_mode-class.html)', action='store') 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 options.scale_factor: if not mapnik.mapnik_version() >= 800: parser.error( '\nPassing a scale factor requires at least mapnik >= 0.8.0 (aka Mapnik2)\n' ) if len(args) == 0: parser.error( '\nPlease provide the path to a Mapnik xml or Cascadenik mml file\n' ) elif len(args) == 1 and not options.dry_run: parser.error('\nPlease provide an output image name\n')
help='Pass a scale factor to the Mapnik renderer (experimental)', action='store') parser.add_option('--aspect-fix-mode', dest='aspect_fix_mode', type='string', help='Pass an aspect_fix_mode string (case-insensitive match of http://media.mapnik.org/api_docs/python/mapnik._mapnik.aspect_fix_mode-class.html)', action='store') 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 options.scale_factor: if not mapnik.mapnik_version() >= 800: parser.error('\nPassing a scale factor requires at least mapnik >= 0.8.0 (aka Mapnik2)\n') if len(args) == 0: parser.error('\nPlease provide the path to a Mapnik xml or Cascadenik mml file\n') elif len(args) == 1 and not options.dry_run: parser.error('\nPlease provide an output image name\n') if args[0] == '-' and not sys.stdin.isatty(): xml = sys.stdin.read() if hasattr(mapnik,'load_map_from_string'): options.from_string = True