本文整理汇总了Python中mapnik.mapnik_version函数的典型用法代码示例。如果您正苦于以下问题:Python mapnik_version函数的具体用法?Python mapnik_version怎么用?Python mapnik_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapnik_version函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: finish_initializing
def finish_initializing(self, builder): # pylint: disable=E1002
"""Set up the main window"""
super(GeneralcartoWindow, self).finish_initializing(builder)
self.AboutDialog = AboutGeneralcartoDialog
self.PreferencesDialog = PreferencesGeneralcartoDialog
####
#initialize some global variables
self.checkbutton_open = False
self.shapefile = ''
# Get a reference to the builder and set up the signals.
self.builder = builder
self.ui = builder.get_ui(self)
#initialize the entry for the zoomlevels for the tile rendering
self.ui.entry1.set_text('0')
self.ui.entry2.set_text('18')
print 'Mapnik_version = %s' %mapnik.mapnik_version()
if mapnik.mapnik_version() < 200100:
print "You're having a too old version of mapnik...install minimum version 2.1.0!!!"
sys.exit()
#initialize the size of the tile buffer
self.buffer_size = 128
self.ui.entry_buffer.set_text(str(self.buffer_size))
home = os.getenv("HOME")
self.generalHome = home + '/GeneralCarto/'
if not os.path.isdir(self.generalHome):
os.mkdir(self.generalHome)
self.logs = self.generalHome + 'log-files/'
if not os.path.isdir(self.logs):
os.mkdir(self.logs)
self.tile_dir = self.generalHome + 'tiles/'
if not os.path.isdir(self.tile_dir):
os.mkdir(self.tile_dir)
self.previewImage = self.generalHome + "user_image.png"
self.path = ""
self.xml_files_folder = self.generalHome + 'xmlfiles/'
if not os.path.isdir(self.xml_files_folder):
os.mkdir(self.xml_files_folder)
self.menuItemIndicator = "< "
self.textEditor = 'gedit'
#self.loadWindows()
self.tileButtonVisibility(False)
self.initializedMapfile = False
self.initialLoad = True
示例2: render_tile
def render_tile(self, x, y, z, utf_grid):
# Calculate pixel positions of bottom-left & top-right
p0 = (x * 256, (y + 1) * 256)
p1 = ((x + 1) * 256, y * 256)
# Convert to LatLong (EPSG:4326)
l0 = self.tileproj.fromPixelToLL(p0, z);
l1 = self.tileproj.fromPixelToLL(p1, z);
# Convert to map projection (e.g. mercator co-ords EPSG:900913)
c0 = self.prj.forward(mapnik.Coord(l0[0],l0[1]))
c1 = self.prj.forward(mapnik.Coord(l1[0],l1[1]))
# Bounding box for the tile
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(c0.x,c0.y, c1.x,c1.y)
else:
bbox = mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
render_size = 256
self.m.resize(render_size, render_size)
self.m.zoom_to_box(bbox)
if(self.m.buffer_size < 128):
self.m.buffer_size = 128
if utf_grid is True:
grid = mapnik.Grid(self.m.width,self.m.height)
mapnik.render_layer(self.m, grid, layer=0, fields=['html_exp'])
utfgrid = grid.encode('utf', resolution=4)
return json.dumps(utfgrid);
else:
im = mapnik.Image(render_size, render_size)
mapnik.render(self.m, im)
return im.tostring('png');
示例3: render_tile
def render_tile(self, tile_uri, x, y, z):
# Calculate pixel positions of bottom-left & top-right
p0 = (x * 256, (y + 1) * 256)
p1 = ((x + 1) * 256, y * 256)
# Convert to LatLong (EPSG:4326)
l0 = self.tileproj.fromPixelToLL(p0, z);
l1 = self.tileproj.fromPixelToLL(p1, z);
# Convert to map projection (e.g. mercator co-ords EPSG:900913)
c0 = self.prj.forward(mapnik.Coord(l0[0],l0[1]))
c1 = self.prj.forward(mapnik.Coord(l1[0],l1[1]))
# Bounding box for the tile
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(c0.x,c0.y, c1.x,c1.y)
else:
bbox = mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
render_size = 256
self.m.resize(render_size, render_size)
self.m.zoom_to_box(bbox)
self.m.buffer_size = 128
# Render image with default Agg renderer
im = mapnik.Image(render_size, render_size)
mapnik.render(self.m, im)
im.save(tile_uri, 'png256')
示例4: render_tile
def render_tile(self, tile_uri, x, y, z, buffer_size):
tile = (x,y)
c0, c1 = self.calcTileCoordinates(tile, z)
tile_extent = (c0.x,c0.y, c1.x,c1.y)
#dest_file = "WebGen_WPS_file.xml"
#folder = "/home/klammer/Software/Quickly/tilegen/data/media/"
#test = makeWPSfile(tile_extent, folder+dest_file)
#if test > 0:
# sendFile(dest_file, folder)
# Bounding box for the tile
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(c0.x,c0.y, c1.x,c1.y)
else:
bbox = mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
render_size = 256
self.m.resize(render_size, render_size)
self.m.zoom_to_box(bbox)
self.m.buffer_size = buffer_size
# Render image with default Agg renderer
im = mapnik.Image(render_size, render_size)
mapnik.render(self.m, im)
im.save(tile_uri, 'png256')
示例5: fews_point_style
def fews_point_style(jdbc_source, filterkey, locationkey, parameterkey,
nodata=False, styles=None, lookup=None):
"""
Make mapnik point_style for fews point with given filterkey.
Copied from lizard_fewsunblobbed.
"""
point_style_name, output_filename = fews_symbol_name(
jdbc_source, filterkey, locationkey, parameterkey,
nodata, styles, lookup)
output_filename_abs = os.path.join(
settings.MEDIA_ROOT, 'generated_icons', output_filename)
# use filename in mapnik pointsymbolizer
if mapnik.mapnik_version() < 800:
point_looks = mapnik.PointSymbolizer(
str(output_filename_abs), 'png', 16, 16)
else:
point_looks = mapnik.PointSymbolizer(
mapnik.PathExpression(str(output_filename_abs)))
point_looks.allow_overlap = True
layout_rule = mapnik.Rule()
layout_rule.symbols.append(point_looks)
# We use 'class' to filter the correct style for the locations
layout_rule.filter = mapnik.Filter(
"[style] = '%s'" % str(point_style_name))
point_style = mapnik.Style()
point_style.rules.append(layout_rule)
return point_style_name, point_style
示例6: run
def run(self):
while True:
if not self.queue.empty():
# get point from queue
point = self.queue.get() # point is a tuple
# print point in gui
self.object_map["work_frame"].text.insert(tk.END, "%i,%i\n" % (point[0], point[1]))
self.object_map["work_frame"].text.yview(tk.END)
# make point
pds = mapnik.PointDatasource()
pds.add_point(point[0], point[1], "Name", "d")
# create point symbolizer for blue icons
if mapnik.mapnik_version() >= 800:
point = mapnik.PointSymbolizer(mapnik.PathExpression("y2.png"))
else:
point = mapnik.PointSymbolizer("y2.png", "png", 25, 25)
point.allow_overlap = True
s = mapnik.Style()
r = mapnik.Rule()
r.symbols.append(point)
s.rules.append(r)
self.layer2 = mapnik.Layer("GPS Coord")
self.layer2.datasource = pds
self.layer2.styles.append("Style")
self.map.append_style("Style", s)
self.map.layers.append(self.layer2)
self.draw()
示例7: renderPage
def renderPage(ll,file):
z = 2
#imgx = 987 * z
#imgy = 801 * z
imgx = int(987 * z )
imgy = int(987 * z *0.77 )
m = mapnik.Map(imgx,imgy)
mapnik.load_map(m,mapfile)
prj = mapnik.Projection("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m [email protected] +no_defs +over")
c0 = prj.forward(mapnik.Coord(ll[0],ll[1]))
c1 = prj.forward(mapnik.Coord(ll[2],ll[3]))
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(c0.x,c0.y,c1.x,c1.y)
else:
bbox = mapnik.Envelope(c0.x,c0.y,c1.x,c1.y)
m.zoom_to_box(bbox)
im = mapnik.Image(imgx,imgy)
mapnik.render(m, im)
view = im.view(0,0,imgx,imgy) # x,y,width,height
map_uri=file + '.png'
view.save(map_uri,'png')
file=open(file+'.svg' ,'w')
surface=cairo.SVGSurface(file.name,imgx,imgy)
mapnik.render(m,surface)
#c = cairo.Context(surface)
#c.move_to(50,50)
#c.show_text('testing')
surface.finish();
示例8: render
def render(self, stylefile, bbox, output, width, height):
"""
Render the specified bbox (minx, miny, maxx, maxy) with Mapnik
"""
if not self._mapnik:
self._mapnik = mapnik.Map(width, height)
# Load style XML
mapnik.load_map(self._mapnik, stylefile, True)
# Obtain <Map> projection
self._prj = mapnik.Projection(self._mapnik.srs)
# Convert to map projection
assert len(bbox) == 4, "Provide a bounding box tuple (minx, miny, maxx, maxy)"
c0 = self._prj.forward(mapnik.Coord(bbox[0],bbox[1]))
c1 = self._prj.forward(mapnik.Coord(bbox[2],bbox[3]))
# Bounding box for the tile
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(c0.x,c0.y, c1.x,c1.y)
else:
bbox = mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
self._mapnik.resize(width, height)
self._mapnik.zoom_to_box(bbox)
self._mapnik.buffer_size = 128
# Render image with default Agg renderer
im = mapnik.Image(width, height)
mapnik.render(self._mapnik, im)
im.save(output, 'png256')
示例9: GetFeatureInfo
def GetFeatureInfo(self, params, querymethodname='query_point'):
m = self._buildMap(params)
if params['info_format'] == 'text/plain':
writer = TextFeatureInfo()
elif params['info_format'] == 'text/xml':
writer = XMLFeatureInfo()
if params['query_layers'] and params['query_layers'][0] == '__all__':
for layerindex, layer in enumerate(m.layers):
featureset = getattr(m, querymethodname)(layerindex, params['i'], params['j'])
features = featureset.features
if features:
writer.addlayer(layer.name)
for feat in features:
writer.addfeature()
if mapnik_version() >= 800:
for prop,value in feat.attributes.iteritems():
writer.addattribute(prop, value)
else:
for prop in feat.properties:
writer.addattribute(prop[0], prop[1])
else:
for layerindex, layername in enumerate(params['query_layers']):
if layername in params['layers']:
# TODO - pretty sure this is bogus, we can't pull from m.layers by the layerindex of the
# 'query_layers' subset, need to pull from:
# self.mapfactory.layers[layername]
if m.layers[layerindex].queryable:
featureset = getattr(m, querymethodname)(layerindex, params['i'], params['j'])
features = featureset.features
if features:
writer.addlayer(m.layers[layerindex].name)
for feat in features:
writer.addfeature()
if mapnik_version() >= 800:
for prop,value in feat.attributes.iteritems():
writer.addattribute(prop, value)
else:
for prop in feat.properties:
writer.addattribute(prop[0], prop[1])
else:
raise OGCException('Requested query layer "%s" is not marked queryable.' % layername, 'LayerNotQueryable')
else:
raise OGCException('Requested query layer "%s" not in the LAYERS parameter.' % layername)
return Response(params['info_format'], str(writer))
示例10: GetMap
def GetMap(self, params):
m = self._buildMap(params)
im = Image(params['width'], params['height'])
render(m, im)
format = PIL_TYPE_MAPPING[params['format']]
if mapnik_version() >= 200300:
# Mapnik 2.3 uses png8 as default, use png32 for backwards compatibility
if format == 'png':
format = 'png32'
return Response(params['format'].replace('8',''), im.tostring(format))
示例11: serialize
def serialize(xml,options):
try:
import mapnik
except:
sys.exit(color_text(1,'Error: saving xml requires Mapnik python bindings to be installed'))
m = mapnik.Map(1,1)
if options.from_string:
mapnik.load_map_from_string(m,xml,True)
else:
mapnik.load_map(m,xml,True)
if options.output:
mapnik.save_map(m,options.output)
else:
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 700:
print mapnik.save_map_to_string(m)
else:
sys.exit(color_text(1,'Minor error: printing XML to stdout requires Mapnik >=0.7.0, please provide a second argument to save the output to a file'))
示例12: get_bbox
def get_bbox(self, x, y, z):
# Calculate pixel positions of bottom-left & top-right
p0 = (x * self.render_size, (y + 1) * self.render_size)
p1 = ((x + 1) * self.render_size, y * self.render_size)
# Convert to LatLong (EPSG:4326)
l0 = self.tileproj.fromPixelToLL(p0, z);
l1 = self.tileproj.fromPixelToLL(p1, z);
# Convert to map projection (e.g. mercator co-ords EPSG:900913)
c0 = self.prj.forward(mapnik.Coord(l0[0],l0[1]))
c1 = self.prj.forward(mapnik.Coord(l1[0],l1[1]))
# Bounding box for the tile
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
return mapnik.Box2d(c0.x,c0.y, c1.x,c1.y)
else:
return mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
示例13: get_bbox
def get_bbox(self):
# Calculate pixel positions of bottom-left & top-right
p0 = (self.mtx0 * TILE_SIZE, (self.mty0 + self.metatile) * TILE_SIZE)
p1 = ((self.mtx0 + self.metatile) * TILE_SIZE, self.mty0 * TILE_SIZE)
# Convert to LatLong (EPSG:4326)
l0 = self.tileproj.fromPixelToLL(p0, self.zoom);
l1 = self.tileproj.fromPixelToLL(p1, self.zoom);
# Convert to map projection (e.g. mercator co-ords EPSG:900913)
c0 = self.prj.forward(mapnik.Coord(l0[0],l0[1]))
c1 = self.prj.forward(mapnik.Coord(l1[0],l1[1]))
# Bounding box for the tile
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(c0.x,c0.y, c1.x,c1.y)
else:
bbox = mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
return bbox
示例14: render_image
def render_image(self, extent, img_size, settings):
# Выбираем объекты по экстенту
feature_query = self.layer.feature_query()
feature_query.intersects(box(*extent, srid=self.layer.srs_id))
feature_query.geom()
features = feature_query()
ds = mapnik.MemoryDatasource()
for (id, f) in enumerate(features):
if mapnik.mapnik_version() < 200100:
feature = mapnik.Feature(id)
else:
feature = mapnik.Feature(mapnik.Context(), id)
feature.add_geometries_from_wkb(f.geom.wkb)
ds.add_feature(feature)
style_content = str(self.style_content)
m = mapnik.Map(img_size[0], img_size[1])
mapnik.load_map_from_string(m, style_content)
m.zoom_to_box(mapnik.Box2d(*extent))
layer = mapnik.Layer('main')
layer.datasource = ds
root = ET.fromstring(style_content)
styles = [s.attrib.get('name') for s in root.iter('Style')]
for s in styles:
layer.styles.append(s)
m.layers.append(layer)
img = mapnik.Image(img_size[0], img_size[1])
mapnik.render(m, img)
data = img.tostring('png')
# Преобразуем изображение из PNG в объект PIL
buf = StringIO()
buf.write(data)
buf.seek(0)
img = Image.open(buf)
return img
示例15: render_tile
def render_tile(self, w, h):
self.m.resize(w, h)
#self.m.zoom_to_box(self.lyr.envelope())
bb = (self.lyr.envelope().minx,self.lyr.envelope().miny,self.lyr.envelope().maxx,self.lyr.envelope().maxy)
lW = bb[2] - bb[0]
lH = bb[3] - bb[1]
lR = lW/lH
r = w/h
mW = 0
mH = 0
if lR > r:
mH = (lW * h)/(w * lH)
elif r < lR:
mW = (w * lH) / (lW * h)
x1 = bb[0] - 0.5*mW
x2 = bb[2] + 0.5*mW
y1 = bb[1] - 0.5*mH
y2 = bb[3] + 0.5*mH
c0 = self.prj.forward(mapnik.Coord(x1, y1))
c1 = self.prj.forward(mapnik.Coord(x2,y2))
# Bounding box for the tile
if hasattr(mapnik, 'mapnik_version') and mapnik.mapnik_version() >= 800:
bb = mapnik.Box2d(c0.x, c0.y, c1.x, c1.y)
else:
bb = mapnik.Envelope(c0.x, c0.y, c1.x, c1.y)
self.m.zoom_to_box(bb)
self.m.buffer_size = 128
# Render image with default Agg renderer
im = mapnik.Image(w, h)
mapnik.render(self.m, im)
im.save(str(self.png), 'png')