def renderTile(tx, ty, zoom, polygons, borders = True, width = 256, height = 256):
"""
renderTile -- return a numpy array of uint32
tx -- tile x coord
ty -- tile y coord
zoom -- tile zoom
polygon -- a polygon locator
"""
# FORMAT_ARGB32 is premultiplied, which results in loss of precision and thus cannot be used.
# FORMAT_RGB30 offers up 30bits, (1 billion uniques),
# but isn't available until 1.12 (we have 1.10)
# FORMAT_RGB24 will have to be used.
# Another option would be to render a 2nd channel with the alpha info.
#borders = False
surface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
ctx = getContext(surface, tx, ty, zoom)
bsurface = cairo.ImageSurface(cairo.FORMAT_RGB24, width, height)
ctx2 = getContext(bsurface, tx, ty, zoom)
simple_level = zoom if zoom < 10 else -1
extents = ctx.clip_extents()
for pid in polygons.overlapping(extents):
polygon = polygons.source.get(pid)
if simple_level > -1:
polygon = simple(polygon, zoom)
drawPoly(ctx, ctx2, polygon, pid)
#if borders:
# for width in range(10,0,-1):
# ctx2.set_source_rgb(0.0,0.0,width/256.)
# width = width/ctx2.get_matrix()[0]
# ctx2.set_line_width(width)
# ctx2.stroke_preserve()
surface.flush() #make sure operations are finished
#surface.write_to_png ("example.png") # Output to PNG
a = numpy.frombuffer(surface.get_data(), 'uint32') & 0x00ffffff
surface.finish()
if borders:
bsurface.flush()
b = numpy.frombuffer(bsurface.get_data(), 'uint32') & 0x00ffffff
#bsurface.write_to_png ("example2.png") # Output to PNG
bsurface.finish()
return a,b
# get_data returns buffer
# FORMAT_RGB24 consists of 32bit pixel in system byteorder
# as A,R,G,B values.
# The Alpha channel is present but unused, however
# it still contains data and must be zeroed.
return a,None
评论列表
文章目录