本文整理汇总了Python中mapnik.render_layer函数的典型用法代码示例。如果您正苦于以下问题:Python render_layer函数的具体用法?Python render_layer怎么用?Python render_layer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_layer函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_render_layer_to_cairo_surface
def test_render_layer_to_cairo_surface():
ds = mapnik.MemoryDatasource()
context = mapnik.Context()
context.push('Name')
f = mapnik.Feature(context, 1)
f['Name'] = 'poly'
f.geometry = mapnik.Geometry.from_wkt(
'POLYGON ((1 1, -1 1, -1 -1, 1 -1, 1 1))')
ds.add_feature(f)
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.PolygonSymbolizer()
symb.fill = mapnik.Color('red')
r.symbols.append(symb)
s.rules.append(r)
lyr = mapnik.Layer('poly')
lyr.datasource = ds
lyr.styles.append('poly')
m = mapnik.Map(256, 256)
m.append_style('poly', s)
m.layers.append(lyr)
m.zoom_all()
surface = cairo.ImageSurface(
cairo.FORMAT_ARGB32, m.width, m.height)
mapnik.render_layer(m, surface, lyr)
im = mapnik.Image.from_cairo(surface)
eq_(im.is_solid(), True)
c = im.get_pixel(0, 0, True)
eq_(c.r, 255)
eq_(c.g, 0)
eq_(c.b, 0)
eq_(c.a, 255)
开发者ID:mapycz,项目名称:python-mapnik,代码行数:35,代码来源:render_test.py
示例2: test_render_grid_new
def test_render_grid_new():
""" test old against new"""
width,height = 256,256
m = create_grid_map(width,height)
ul_lonlat = mapnik.Coord(142.30,-38.20)
lr_lonlat = mapnik.Coord(143.40,-38.80)
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
# new method
grid = mapnik.Grid(m.width,m.height,key='Name')
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
utf1 = grid.encode('utf',resolution=4)
eq_(utf1,grid_correct_new2,show_grids('new-markers',utf1,grid_correct_new2))
# check a full view is the same as a full image
grid_view = grid.view(0,0,width,height)
# for kicks check at full res too
utf3 = grid.encode('utf',resolution=1)
utf4 = grid_view.encode('utf',resolution=1)
eq_(utf3['grid'],utf4['grid'])
eq_(utf3['keys'],utf4['keys'])
eq_(utf3['data'],utf4['data'])
eq_(resolve(utf4,0,0),None)
# resolve some center points in the
# resampled view
utf5 = grid_view.encode('utf',resolution=4)
eq_(resolve(utf5,25,10),{"Name": "North West"})
eq_(resolve(utf5,25,46),{"Name": "North East"})
eq_(resolve(utf5,38,10),{"Name": "South West"})
eq_(resolve(utf5,38,46),{"Name": "South East"})
开发者ID:chriskoli,项目名称:mapnik,代码行数:32,代码来源:render_grid_test.py
示例3: test_line_rendering
def test_line_rendering():
ds = mapnik.MemoryDatasource()
context = mapnik.Context()
context.push('Name')
pixel_key = 1
f = mapnik.Feature(context,pixel_key)
f['Name'] = str(pixel_key)
f.add_geometries_from_wkt('LINESTRING (30 10, 10 30, 40 40)')
ds.add_feature(f)
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.LineSymbolizer()
r.symbols.append(symb)
s.rules.append(r)
lyr = mapnik.Layer('Places')
lyr.datasource = ds
lyr.styles.append('places_labels')
width,height = 256,256
m = mapnik.Map(width,height)
m.append_style('places_labels',s)
m.layers.append(lyr)
m.zoom_all()
#mapnik.render_to_file(m,'test.png')
grid = mapnik.Grid(m.width,m.height,key='__id__')
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
utf1 = grid.encode()
eq_(utf1,line_expected,show_grids('line',utf1,line_expected))
开发者ID:1060460048,项目名称:mapnik,代码行数:27,代码来源:render_grid_test.py
示例4: test_render_grid3
def test_render_grid3():
""" test using feature id"""
width, height = 256, 256
m = create_grid_map(width, height)
ul_lonlat = mapnik.Coord(142.30, -38.20)
lr_lonlat = mapnik.Coord(143.40, -38.80)
m.zoom_to_box(mapnik.Box2d(ul_lonlat, lr_lonlat))
grid = mapnik.Grid(m.width, m.height, key="__id__")
mapnik.render_layer(m, grid, layer=0, fields=["__id__", "Name"])
utf1 = grid.encode("utf", resolution=4)
eq_(utf1["keys"], grid_feat_id["keys"])
eq_(utf1["grid"], grid_feat_id["grid"])
eq_(utf1["data"], grid_feat_id["data"])
eq_(utf1, grid_feat_id)
# check a full view is the same as a full image
grid_view = grid.view(0, 0, width, height)
# for kicks check at full res too
utf3 = grid.encode("utf", resolution=1)
utf4 = grid_view.encode("utf", resolution=1)
eq_(utf3["grid"], utf4["grid"])
eq_(utf3["keys"], utf4["keys"])
eq_(utf3["data"], utf4["data"])
eq_(resolve(utf4, 0, 0), None)
# resolve some center points in the
# resampled view
utf5 = grid_view.encode("utf", resolution=4)
eq_(resolve(utf5, 25, 10), {"Name": "North West"})
eq_(resolve(utf5, 25, 46), {"Name": "North East"})
eq_(resolve(utf5, 38, 10), {"Name": "South West"})
eq_(resolve(utf5, 38, 46), {"Name": "South East"})
开发者ID:repos-map,项目名称:mapnik,代码行数:33,代码来源:render_grid_test.py
示例5: 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');
开发者ID:orfon,项目名称:ringo-mapnik,代码行数:34,代码来源:render_tile.py
示例6: renderTile
def renderTile(self, width, height, srs, coord):
"""
"""
if self.mapnik is None:
self.mapnik = get_mapnikMap(self.mapfile)
# buffer as fraction of tile size
buffer = float(self.buffer) / 256
nw = self.layer.projection.coordinateLocation(coord.left(buffer).up(buffer))
se = self.layer.projection.coordinateLocation(coord.right(1 + buffer).down(1 + buffer))
ul = self.mercator.locationProj(nw)
lr = self.mercator.locationProj(se)
self.mapnik.width = width + 2 * self.buffer
self.mapnik.height = height + 2 * self.buffer
self.mapnik.zoom_to_box(mapnik.Box2d(ul.x, ul.y, lr.x, lr.y))
# create grid as same size as map/image
grid = mapnik.Grid(width + 2 * self.buffer, height + 2 * self.buffer)
# render a layer to that grid array
mapnik.render_layer(self.mapnik, grid, layer=self.layer_index, fields=self.fields)
# extract a gridview excluding the buffer
grid_view = grid.view(self.buffer, self.buffer, width, height)
# then encode the grid array as utf, resample to 1/scale the size, and dump features
grid_utf = grid_view.encode('utf', resolution=self.scale, add_features=True)
if self.wrapper is None:
return SaveableResponse(json.dumps(grid_utf))
else:
return SaveableResponse(self.wrapper + '(' + json.dumps(grid_utf) + ')')
开发者ID:Algotricx,项目名称:python-geospatial-analysis-cookbook,代码行数:31,代码来源:MapnikGrid.py
示例7: test_render_grid3
def test_render_grid3():
""" test using feature id"""
width,height = 256,256
sym = mapnik.MarkersSymbolizer()
sym.width = mapnik.Expression('10')
sym.height = mapnik.Expression('10')
m = create_grid_map(width,height,sym)
ul_lonlat = mapnik.Coord(142.30,-38.20)
lr_lonlat = mapnik.Coord(143.40,-38.80)
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
grid = mapnik.Grid(m.width,m.height,key='__id__')
mapnik.render_layer(m,grid,layer=0,fields=['__id__','Name'])
utf1 = grid.encode('utf',resolution=4)
eq_(utf1,grid_feat_id3,show_grids('id-markers',utf1,grid_feat_id3))
# check a full view is the same as a full image
grid_view = grid.view(0,0,width,height)
# for kicks check at full res too
utf3 = grid.encode('utf',resolution=1)
utf4 = grid_view.encode('utf',resolution=1)
eq_(utf3['grid'],utf4['grid'])
eq_(utf3['keys'],utf4['keys'])
eq_(utf3['data'],utf4['data'])
eq_(resolve(utf4,0,0),None)
# resolve some center points in the
# resampled view
utf5 = grid_view.encode('utf',resolution=4)
eq_(resolve(utf5,25,10),{"Name": "North West","__id__": 3})
eq_(resolve(utf5,25,46),{"Name": "North East","__id__": 4})
eq_(resolve(utf5,38,10),{"Name": "South West","__id__": 2})
eq_(resolve(utf5,38,46),{"Name": "South East","__id__": 1})
开发者ID:1060460048,项目名称:mapnik,代码行数:33,代码来源:render_grid_test.py
示例8: renderTile
def renderTile(self, width, height, srs, coord):
"""
"""
if self.mapnik is None:
self.mapnik = mapnik.Map(0, 0)
mapnik.load_map(self.mapnik, str(self.mapfile))
nw = self.layer.projection.coordinateLocation(coord)
se = self.layer.projection.coordinateLocation(coord.right().down())
ul = self.mercator.locationProj(nw)
lr = self.mercator.locationProj(se)
self.mapnik.width = width
self.mapnik.height = height
self.mapnik.zoom_to_box(mapnik.Box2d(ul.x, ul.y, lr.x, lr.y))
# create grid as same size as map/image
grid = mapnik.Grid(width, height)
# render a layer to that grid array
mapnik.render_layer(self.mapnik, grid, layer=self.layer_index, fields=self.fields)
# then encode the grid array as utf, resample to 1/scale the size, and dump features
grid_utf = grid.encode('utf', resolution=self.scale, features=True)
if self.wrapper is None:
return SaveableResponse(json.dumps(grid_utf))
else:
return SaveableResponse(self.wrapper + '(' + json.dumps(grid_utf) + ')')
开发者ID:paulsmith,项目名称:TileStache,代码行数:28,代码来源:MapnikGrid.py
示例9: renderArea
def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
"""
"""
start_time = time()
#
# Mapnik can behave strangely when run in threads, so place a lock on the instance.
#
if global_mapnik_lock.acquire():
try:
if self.mapnik is None:
self.mapnik = get_mapnikMap(self.mapfile)
logging.debug('TileStache.Mapnik.GridProvider.renderArea() %.3f to load %s', time() - start_time, self.mapfile)
self.mapnik.width = width
self.mapnik.height = height
self.mapnik.zoom_to_box(Box2d(xmin, ymin, xmax, ymax))
if self.layer_id_key is not None:
grids = []
for (index, fields) in self.layers:
datasource = self.mapnik.layers[index].datasource
if isinstance(fields, list):
fields = [str(f) for f in fields]
else:
fields = datasource.fields()
grid = mapnik.Grid(width, height)
mapnik.render_layer(self.mapnik, grid, layer=index, fields=fields)
grid = grid.encode('utf', resolution=self.scale, features=True)
for key in grid['data']:
grid['data'][key][self.layer_id_key] = self.mapnik.layers[index].name
grids.append(grid)
# global_mapnik_lock.release()
outgrid = reduce(merge_grids, grids)
else:
grid = mapnik.Grid(width, height)
for (index, fields) in self.layers:
datasource = self.mapnik.layers[index].datasource
fields = (type(fields) is list) and map(str, fields) or datasource.fields()
mapnik.render_layer(self.mapnik, grid, layer=index, fields=fields)
# global_mapnik_lock.release()
outgrid = grid.encode('utf', resolution=self.scale, features=True)
except:
self.mapnik = None
raise
finally:
global_mapnik_lock.release()
logging.debug('TileStache.Mapnik.GridProvider.renderArea() %dx%d at %d in %.3f from %s', width, height, self.scale, time() - start_time, self.mapfile)
return SaveableResponse(outgrid, self.scale)
开发者ID:TileStache,项目名称:TileStache,代码行数:59,代码来源:Mapnik.py
示例10: render
def render(self, path, tile_x, tile_y, zoom):
"""
Render a single tile to a given filename.
"""
print 'Rendering %s' % (path)
# Calculate pixel positions of bottom-left & top-right
half_width = self.width / 2
half_height = self.height / 2
px0 = (tile_x * self.width, (tile_y + 1) * self.height)
px1 = ((tile_x + 1) * self.width, tile_y * self.height)
# Convert tile coords to LatLng
ll0 = self.tile_projection.fromPixelToLL(px0, zoom);
ll1 = self.tile_projection.fromPixelToLL(px1, zoom);
# Convert LatLng to map coords
c0 = self.map_projection.forward(mapnik.Coord(ll0[0], ll0[1]))
c1 = self.map_projection.forward(mapnik.Coord(ll1[0], ll1[1]))
# Create bounding box for the render
bbox = mapnik.Box2d(c0.x, c0.y, c1.x, c1.y)
self.mapnik_map.zoom_to_box(bbox)
self.mapnik_map.buffer_size = self.buffer_size
if self.filetype == 'svg':
surface = cairo.SVGSurface(path, self.width, self.height)
mapnik.render(self.mapnik_map, surface)
surface.finish()
else:
image = mapnik.Image(self.width, self.height)
mapnik.render(self.mapnik_map, image)
image.save(path, self.filetype)
if self.grid:
if self.key:
grid = mapnik.Grid(self.width, self.height)
else:
grid = mapnik.Grid(self.width, self.height, key=self.key)
fields = []
if self.fields:
fields.extend(self.fields)
mapnik.render_layer(self.mapnik_map,grid, layer=0, fields=fields)
# then encode the grid array as utf, resample to 1/4 the size, and dump features
# this comes from https://github.com/springmeyer/gridsforkids/blob/master/generate_tiles.py
# with little consideration
grid_utf = grid.encode('utf', resolution=4, features=True)
# client code uses jsonp, so fake by wrapping in grid() callback
base, ext = os.path.splitext(path)
grid_filename = '%s.grid.json' % base
print 'Rendering %s' % (grid_path)
with open(grid_path, 'wb') as f:
f.write('grid(' + json.dumps(grid_utf) + ')')
开发者ID:HydroLogic,项目名称:invar,代码行数:59,代码来源:renderer.py
示例11: test_clearing_grid_data
def test_clearing_grid_data():
g = mapnik.Grid(256, 256)
utf = g.encode()
# make sure it equals itself
eq_(g.encode(), utf)
m = make_map()
mapnik.render_layer(m, g, layer=0, fields=['__id__', 'Name'])
eq_(g.encode() != utf, True)
# clear grid, should now match original
g.clear()
eq_(g.encode(), utf)
开发者ID:cbenz,项目名称:python-mapnik,代码行数:11,代码来源:buffer_clear_test.py
示例12: test_point_symbolizer_grid
def test_point_symbolizer_grid():
width,height = 256,256
sym = mapnik.PointSymbolizer()
sym.file = '../data/images/dummy.png'
m = create_grid_map(width,height,sym)
ul_lonlat = mapnik.Coord(142.30,-38.20)
lr_lonlat = mapnik.Coord(143.40,-38.80)
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
grid = mapnik.Grid(m.width,m.height)
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
utf1 = grid.encode()
eq_(utf1,point_expected,show_grids('point-sym',utf1,point_expected))
开发者ID:1060460048,项目名称:mapnik,代码行数:12,代码来源:render_grid_test.py
示例13: render_grid
def render_grid(self, bbox, grid_fields, layer, width=None, height=None):
"""
Render the specified grid with Mapnik
"""
width = width or self.tilesize
height = height or self.tilesize
self._prepare_rendering(bbox, width=width, height=height)
grid = mapnik.Grid(width, height)
mapnik.render_layer(self._mapnik, grid, layer=layer, fields=grid_fields)
grid = grid.encode()
return json.dumps(grid)
开发者ID:omni-earth,项目名称:landez,代码行数:12,代码来源:sources.py
示例14: _renderGridinfo
def _renderGridinfo(self,x,y,z,l0,l1,tile_uris):
for i in range(int(self.tile_countX)):
for j in range(int(self.tile_countY)):
pt0 = (x + self.tile_size*i, y + self.tile_size*(j+1))
pt1 = (x + self.tile_size*(i+1), y + self.tile_size*j)
# Convert to LatLong (EPSG:4326)
lt0 = self.tileproj.fromPixelToLL(pt0, z);
lt1 = self.tileproj.fromPixelToLL(pt1, z);
# Convert to map projection (e.g. mercator co-ords EPSG:900913)
ct0 = self.prj.forward(mapnik.Coord(lt0[0],lt0[1]))
ct1 = self.prj.forward(mapnik.Coord(lt1[0],lt1[1]))
if self.gridMap:
mi = 0
for country,_gridMap in self.gridMap.items():
if self.countries[country].intersects(mapnik.Box2d(l0[0],l0[1],l1[0],l1[1])):
try:
_gridMap.zoom_to_box(mapnik.Box2d(ct0.x,ct0.y, ct1.x,ct1.y))
_gridMap.resize(int(self.tile_size), int(self.tile_size))
_gridMap.buffer_size = 0
grid = mapnik.Grid(int(self.tile_size), int(self.tile_size))
mapnik.render_layer(_gridMap, grid, layer = 1, fields=['symbol_name','wiki'])
mapnik.render_layer(_gridMap, grid, layer = 0, fields=['highway','grade','surface','smoothness','ref','int_ref','tracktype','name'])
utfgrid = grid.encode('utf',resolution=4)
for key1 in utfgrid['data']:
for key2,val2 in utfgrid['data'][key1].items():
if val2 in (None,'no',''):
del utfgrid['data'][key1][key2]
gridname = tile_uris[i*self.tile_countY +j].replace(".jpg",".js")
f = codecs.open(gridname + '.tmp','w','utf-8')
f.write(json.dumps(utfgrid, ensure_ascii = False))
f.close()
if mi > 0:
os.system('gzip -f %s' % (gridname + '.tmp'))
if os.path.getsize(gridname + '.tmp.gz') > os.path.getsize(gridname+'.gz'):
os.remove(gridname + '.gz')
os.rename(gridname + '.tmp.gz',gridname+'.gz')
else:
os.remove(gridname + '.tmp.gz')
else:
os.rename(gridname + '.tmp.gz',gridname+'.gz')
except Exception as E:
print E
mi += 1
开发者ID:bigr,项目名称:map1,代码行数:49,代码来源:generate_tiles.py
示例15: __call__
def __call__(self, layers, system):
request = system['request']
# get image width and height
width = 256
height = 256
# get image bbox
z = int(request.matchdict['z'])
x = int(request.matchdict['x'])
y = int(request.matchdict['y'])
step = max/(2**(int(z) - 1))
xmin = x*step-max
ymin = max-y*step
xmax = (x+1)*step-max
ymax = max-(y+1)*step
bbox = Box2d(xmin, ymax, xmax, ymin)
m = Map(width, height)
load_map(m, abspath_from_asset_spec('osmtm:views/map.xml'))
for l in layers:
m.layers.append(l)
m.zoom_to_box(bbox)
format = request.matchdict['format']
if format == 'png':
im = Image(width, height)
render(m, im, 1, 1)
request.response_content_type = 'image/png'
return im.tostring('png')
elif format == 'json':
grid = Grid(width, height)
render_layer(m, grid, layer=0, fields=['id'])
utfgrid = grid.encode('utf', resolution=4)
return json.dumps(utfgrid)
开发者ID:mvexel,项目名称:osm-tasking-manager2,代码行数:41,代码来源:resources.py
示例16: test_render_grid2
def test_render_grid2():
""" test old against new"""
width, height = 256, 256
m = create_grid_map(width, height)
ul_lonlat = mapnik.Coord(142.30, -38.20)
lr_lonlat = mapnik.Coord(143.40, -38.80)
m.zoom_to_box(mapnik.Box2d(ul_lonlat, lr_lonlat))
# new method
grid = mapnik.Grid(m.width, m.height, key="Name")
mapnik.render_layer(m, grid, layer=0, fields=["Name"])
utf1 = grid.encode("utf", resolution=4)
eq_(utf1, grid_correct_new)
# old method - to be removed
utf2 = mapnik.render_grid(m, 0, key="Name", resolution=4, fields=["Name"])
eq_(utf2, grid_correct)
# for complex polygons these will not be true
eq_(len(utf2["grid"]), len(utf1["grid"]))
eq_(len(utf2["keys"]), len(utf1["keys"]))
eq_(len(utf2["data"]), len(utf1["data"]))
# check a full view is the same as a full image
grid_view = grid.view(0, 0, width, height)
# for kicks check at full res too
utf3 = grid.encode("utf", resolution=1)
utf4 = grid_view.encode("utf", resolution=1)
eq_(utf3["grid"], utf4["grid"])
eq_(utf3["keys"], utf4["keys"])
eq_(utf3["data"], utf4["data"])
eq_(resolve(utf4, 0, 0), None)
# resolve some center points in the
# resampled view
utf5 = grid_view.encode("utf", resolution=4)
eq_(resolve(utf5, 25, 10), {"Name": "North West"})
eq_(resolve(utf5, 25, 46), {"Name": "North East"})
eq_(resolve(utf5, 38, 10), {"Name": "South West"})
eq_(resolve(utf5, 38, 46), {"Name": "South East"})
开发者ID:repos-map,项目名称:mapnik,代码行数:41,代码来源:render_grid_test.py
示例17: test_render_to_grid_multiple_times
def test_render_to_grid_multiple_times():
# create map with two layers
m = mapnik.Map(256,256)
s = mapnik.Style()
r = mapnik.Rule()
sym = mapnik.MarkersSymbolizer()
sym.allow_overlap = True
r.symbols.append(sym)
s.rules.append(r)
m.append_style('points',s)
# NOTE: we use a csv datasource here
# because the memorydatasource fails silently for
# queries requesting fields that do not exist in the datasource
ds1 = mapnik.Datasource(**{"type":"csv","inline":'''
wkt,Name
"POINT (143.10 -38.60)",South East'''})
lyr1 = mapnik.Layer('One')
lyr1.datasource = ds1
lyr1.styles.append('points')
m.layers.append(lyr1)
ds2 = mapnik.Datasource(**{"type":"csv","inline":'''
wkt,Value
"POINT (142.48 -38.60)",South West'''})
lyr2 = mapnik.Layer('Two')
lyr2.datasource = ds2
lyr2.styles.append('points')
m.layers.append(lyr2)
ul_lonlat = mapnik.Coord(142.30,-38.20)
lr_lonlat = mapnik.Coord(143.40,-38.80)
m.zoom_to_box(mapnik.Box2d(ul_lonlat,lr_lonlat))
grid = mapnik.Grid(m.width,m.height)
mapnik.render_layer(m,grid,layer=0,fields=['Name'])
# should throw right here since Name will be a property now on the `grid` object
# and it is not found on the second layer
mapnik.render_layer(m,grid,layer=1,fields=['Value'])
utf1 = grid.encode()
开发者ID:1060460048,项目名称:mapnik,代码行数:39,代码来源:render_grid_test.py
示例18: 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
if utf_grid == "true":
grid = mapnik.Grid(self.m.width,self.m.height)
mapnik.render_layer(self.m, grid, layer=0, fields=['html_exp'])
tilefilename = tile_uri[:-4] + '.json'
utfgrid = grid.encode('utf', resolution=4)
with open(tilefilename, 'w') as file:
file.write(json.dumps(utfgrid))
else:
# Render image with default Agg renderer
im = mapnik.Image(render_size, render_size)
mapnik.render(self.m, im)
im.save(tile_uri, 'png256')
开发者ID:orfon,项目名称:ringo-mapnik,代码行数:38,代码来源:generate_tiles.py
示例19: gen_grid_for_id
def gen_grid_for_id(pixel_key):
ds = mapnik.MemoryDatasource()
context = mapnik.Context()
context.push('Name')
f = mapnik.Feature(context,pixel_key)
f['Name'] = str(pixel_key)
f.geometry = mapnik.Geometry.from_wkt('POLYGON ((0 0, 0 256, 256 256, 256 0, 0 0))')
ds.add_feature(f)
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.PolygonSymbolizer()
r.symbols.append(symb)
s.rules.append(r)
lyr = mapnik.Layer('Places')
lyr.datasource = ds
lyr.styles.append('places_labels')
width,height = 256,256
m = mapnik.Map(width,height)
m.append_style('places_labels',s)
m.layers.append(lyr)
m.zoom_all()
grid = mapnik.Grid(m.width,m.height,key='__id__')
mapnik.render_layer(m,grid,layer=0,fields=['__id__','Name'])
return grid
开发者ID:sebastic,项目名称:python-mapnik,代码行数:24,代码来源:render_grid_test.py
示例20: gen_grid_for_id
def gen_grid_for_id(pixel_key):
ds = mapnik.MemoryDatasource()
context = mapnik.Context()
context.push("Name")
f = mapnik.Feature(context, pixel_key)
f["Name"] = str(pixel_key)
f.add_geometries_from_wkt("POLYGON ((0 0, 0 256, 256 256, 256 0, 0 0))")
ds.add_feature(f)
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.PolygonSymbolizer()
r.symbols.append(symb)
s.rules.append(r)
lyr = mapnik.Layer("Places")
lyr.datasource = ds
lyr.styles.append("places_labels")
width, height = 256, 256
m = mapnik.Map(width, height)
m.append_style("places_labels", s)
m.layers.append(lyr)
m.zoom_all()
grid = mapnik.Grid(m.width, m.height, key="__id__")
mapnik.render_layer(m, grid, layer=0, fields=["__id__", "Name"])
return grid
开发者ID:repos-map,项目名称:mapnik,代码行数:24,代码来源:render_grid_test.py
注:本文中的mapnik.render_layer函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论