本文整理汇总了Python中mapnik2.mapnik_version函数的典型用法代码示例。如果您正苦于以下问题:Python mapnik_version函数的具体用法?Python mapnik_version怎么用?Python mapnik_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mapnik_version函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serialize
def serialize(xml, options):
try:
try:
import mapnik2 as mapnik
except ImportError:
import mapnik
except ImportError:
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",
)
)
示例2: 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)
# Ensure the tile isn't blank before saving
if not im.tostring("png") == self.blankTileStr:
im.save(tile_uri, "png256")
# Return True if the tile was saved
return True
else:
return False
示例3: render_legend
def render_legend(mapfile, tile_uri):
m = mapnik.Map(1024, 2048)
# Load style XML
mapnik.load_map(m, mapfile, True)
# Obtain <Map> projection
prj = mapnik.Projection(m.srs)
# Projects between tile pixel co-ordinates and LatLong (EPSG:4326)
tileproj = GoogleProjection(20)
# Convert to map projection (e.g. mercator co-ords EPSG:900913)
c0 = prj.forward(mapnik.Coord(14.4503,50.0673))
c1 = prj.forward(mapnik.Coord(14.457,50.0678))
# 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_x = 1024
render_size_y = 1500
m.resize(render_size_x, render_size_y)
m.zoom_to_box(bbox)
m.buffer_size = 128
# Render image with default Agg renderer
im = mapnik.Image(render_size_x, render_size_y)
mapnik.render(m, im)
im.save(tile_uri, 'png256')
surface = cairo.SVGSurface('legend.svg', render_size_x, render_size_y)
mapnik.render(m, surface)
surface.finish()
示例4: render_tile
def render_tile(self, x, y, z):
# Calculate pixel positions of bottom-left & top-right
p0 = (x * TILE_SIZE, (y + 1) * TILE_SIZE)
p1 = ((x + 1) * TILE_SIZE, y * TILE_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:
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 = TILE_SIZE
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)
self.writer.write(x, y, z, im)
示例5: 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)
if(self.m.buffer_size < 128):
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')
示例6: generate_map_tile
def generate_map_tile(self, m, filename, z, x, y):
# Code taken from OSM generate_tiles.py
proj = GoogleProjection()
mprj = mapnik.Projection(m.srs)
p0 = (x * 256, (y + 1) * 256)
p1 = ((x + 1) * 256, y * 256)
l0 = proj.fromPixelToLL(p0, z);
l1 = proj.fromPixelToLL(p1, z);
c0 = mprj.forward(mapnik.Coord(l0[0], l0[1]))
c1 = mprj.forward(mapnik.Coord(l1[0], l1[1]))
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.resize(256, 256)
m.zoom_to_box(bbox)
im = mapnik.Image(256, 256)
mapnik.render(m, im)
# See https://github.com/mapnik/mapnik/wiki/OutputFormats for output
# formats and special parameters. The default here is 32 bit PNG with 8
# bit per component and alpha channel.
if mapnik_version == 2:
im.save(str(filename), "png32")
else:
im.save(str(filename), "png")
示例7: kml_hex_to_mapnik_color
def kml_hex_to_mapnik_color(key_color):
"""Convert a kml color string to a mapnik.Color"""
c = str(key_color)
a,b,g,r = tuple(map(lambda s: int(s, 16),(c[:2],c[2:4],c[4:6],c[6:])))
if mapnik.mapnik_version() >= 800:
pass #a *= 255
#print a,b,g,r
#return (r,g,b)
return mapnik.Color(r,g,b,a)
示例8: 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 in feat:
writer.addattribute(prop[0], prop[1])
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 in feat:
writer.addattribute(prop[0], prop[1])
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))
示例9: render_to_file
def render_to_file(mapnik_map,output,format):
# get the full path for a users directory
if '~' in output:
output = os.path.expanduser(output)
# mapnik won't create directories so
# we have to make sure they exist first...
dirname = os.path.dirname(output)
if not os.path.exists(dirname):
os.makedirs(dirname)
# render out to the desired format
if format in ('png','png256','jpeg') or (hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 700):
try:
mapnik.render_to_file(mapnik_map,output,format)
except Exception, e:
return (False,e)
示例10: 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')
grid_uri = tile_uri.replace('.png','.grid.json')
# new mapnik.Grid api, works like mapnik.Image
# with the exception that you can only render one
# layer to it with the mapnik.render_layer function
# create grid as same size as map/image
grid = mapnik.Grid(render_size, render_size)
# render a layer to that grid array
mapnik.render_layer(self.m,grid,layer=0,fields=['POP2005','NAME'])
# then encode the grid array as utf, resample to 1/4 the size, and dump features
grid_utf = grid.encode('utf',resolution=4,add_features=True)
# below is the old grid api - will be removed soon, don't use
#grid_utf = mapnik.render_grid(self.m,0,key='__id__',resolution=4,fields=['POP2005','NAME'])
# client code uses jsonp, so fake by wrapping in grid() callback
open(grid_uri,'wb').write('grid(' + json.dumps(grid_utf) + ')')
示例11: render_image
def render_image(start_time, end_time):
ll = (30.708, -27.414, 32.179, -25.652)
prj = mapnik.Projection("+init=epsg:900913")
c0 = prj.forward(mapnik.Coord(ll[0], ll[1]))
c1 = prj.forward(mapnik.Coord(ll[2], ll[3]))
z = 3
imgx = 336 * z
imgy = 450 * z
m = mapnik.Map(imgx, imgy)
mapnik.load_map(m, "gpx-nolayer.xml")
db_params = dict(
dbname="gpx-merc",
user="gpx",
password="gpx",
host="localhost",
port=5433,
estimate_extent=False,
extent="3390650.221286806, -3163145.87245787, 3609898.596229789, -2956043.104540316",
)
lyr = Layer("points", "+init=epsg:900913")
db_params["table"] = (
"(select gps_points.geom as geom, gpx_files.gps_name as gps_name from gps_points INNER join gpx_files on gpx_files.id = gps_points.gpx_id where gps_points.timestamp >= '"
+ start_time
+ "' and gps_points.timestamp < '"
+ end_time
+ "') as points"
)
lyr.datasource = PostGIS(**db_params)
lyr.styles.append("points")
m.layers.append(lyr)
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
view.save("frames/" + start_time + ".png", "png")
示例12: complexRun
def complexRun(image, stylesheet, extent, size):
mapfile = stylesheet
map_uri = image
imgx = size[0]
imgy = size[1]
m = mapnik.Map(imgx,imgy)
mapnik.load_map(m,mapfile)
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(extent[0],extent[2],extent[1],extent[3])
else:
bbox = mapnik.Envelope(extent[0],extent[2],extent[1],extent[3])
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
view.save(map_uri,'png')
示例13: ogc_filter_to_mapnik
def ogc_filter_to_mapnik(ogc_filter):
if hasattr(ogc_filter,'PropertyIsGreaterThan'):
prop = ogc_filter.PropertyIsGreaterThan
operator = '>'
#cql = "[%s] > %s" % (prop.PropertyName,prop.Literal)
elif hasattr(ogc_filter,'PropertyIsLessThan'):
prop = ogc_filter.PropertyIsLessThan
operator = '<'
elif hasattr(ogc_filter,'PropertyIsEqualTo'):
prop = ogc_filter.PropertyIsEqualTo
operator = '='
elif hasattr(ogc_filter,'PropertyIsNotEqualTo'):
prop = ogc_filter.PropertyIsNotEqualTo
operator = '!='
if is_number(prop.Literal.text):
cql = "[%s] %s %s" % (prop.PropertyName,operator,prop.Literal)
else:
cql = "[%s] %s '%s'" % (prop.PropertyName,operator,prop.Literal.text)
if mapnik.mapnik_version() >= 800:
return mapnik.Expression(str(cql))
else:
return mapnik.Filter(str(cql))
示例14: render_tile
def render_tile(self, tile_uri, x, y, z):
# Calculate pixel positions of bottom-left & top-right
p0 = (x * TILES_SIZE, (y + 1) * TILES_SIZE)
p1 = ((x + 1) * TILES_SIZE, y * TILES_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:
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 = TILES_SIZE
self.m.resize(render_size, render_size)
self.m.zoom_to_box(bbox)
self.m.buffer_size = 128
if FORMAT == 'grid':
grid = mapnik.Grid(render_size, render_size)
# mapnik.render_layer(self.m, grid, layer=64, fields=['name'])
for n, l in enumerate(self.m.layers):
if l.name != 'admin-012345678':
if 'name' in l.datasource.fields():
mapnik.render_layer(self.m, grid, layer=n, fields=['name'])
utfgrid = grid.encode('utf', resolution=4)
f = open(tile_uri + '.' + FILE_EXTENSION, 'w')
f.write(json.dumps(utfgrid))
f.close()
else:
# Render image with default Agg renderer
im = mapnik.Image(render_size, render_size)
mapnik.render(self.m, im)
im.save(tile_uri + '.' + FILE_EXTENSION, FORMAT)
示例15: generate_map_tile
def generate_map_tile(self, m, filename, z, x, y):
# Code taken from OSM generate_tiles.py
proj = GoogleProjection()
mprj = mapnik.Projection(m.srs)
p0 = (x * 256, (y + 1) * 256)
p1 = ((x + 1) * 256, y * 256)
l0 = proj.fromPixelToLL(p0, z);
l1 = proj.fromPixelToLL(p1, z);
c0 = mprj.forward(mapnik.Coord(l0[0], l0[1]))
c1 = mprj.forward(mapnik.Coord(l1[0], l1[1]))
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.resize(256, 256)
m.zoom_to_box(bbox)
im = mapnik.Image(256, 256)
mapnik.render(m, im)
im.save(str(filename), "png256")