Exemple #1
0
	def fetch(self, zoom_level, x, y):
		#first, try to find the tile at this zoom level
		#if we don't then that means somewhere above us in the tree is a leaf node
		#find that leaf node and return its image
		curs = self.conn.cursor()

		#print '===================='
		#print zoom_level, x, y

		node_ids = []
		for z in range(zoom_level, -1, -1):
			#print z, x, y
			node_ids.append(tiletree.build_node_id(z, x, y))

			x = int(math.floor(x/2.0))
			y = int(math.floor(y/2.0))

		id_clause = ' OR '.join('nodes.node_id = %s' for id in node_ids)
		curs.execute(\
"""
SELECT images.img_bytes
FROM %(node_table)s nodes, %(image_table)s images
WHERE images.image_id = nodes.image_id AND (%(id_clause)s) AND
	(nodes.zoom_level = %%s OR (nodes.is_leaf and (nodes.is_full or nodes.is_blank)))
ORDER BY nodes.zoom_level DESC
""" % {'node_table':self.node_table, 'image_table':self.image_table,
	'id_clause':id_clause,}, node_ids + [zoom_level] )
		result = curs.fetchone()
		if(result):
			return StringIO.StringIO(result[0])
		raise tiletree.TileNotFoundException()
Exemple #2
0
 def build_image(self, surface, node):
     img_bytes = StringIO.StringIO()
     img_id = tiletree.build_node_id(node.zoom_level, node.tile_x,
                                     node.tile_y)
     surface.write_to_png(img_bytes)
     img_bytes = tiletree.palette_png_bytes(
         StringIO.StringIO(img_bytes.getvalue()))
     return (img_id, img_bytes)
Exemple #3
0
	def fetch_helper(self, zoom_level, x, y, layers, fetch_func, do_palette=True):
		cache_id = self.compute_layer_key(layers) + str(tiletree.build_node_id(zoom_level, x, y))
		png_bytes = self.cache.get(cache_id)	
		if(png_bytes == None):
			png_byte_stream = fetch_func(zoom_level, x, y, layers, do_palette)
			self.cache.set(cache_id, png_byte_stream.getvalue())
			return png_byte_stream

		return StringIO.StringIO(png_bytes)
Exemple #4
0
    def fetch_helper(self,
                     zoom_level,
                     x,
                     y,
                     layers,
                     fetch_func,
                     do_palette=True):
        cache_id = self.compute_layer_key(layers) + str(
            tiletree.build_node_id(zoom_level, x, y))
        png_bytes = self.cache.get(cache_id)
        if (png_bytes == None):
            png_byte_stream = fetch_func(zoom_level, x, y, layers, do_palette)
            self.cache.set(cache_id, png_byte_stream.getvalue())
            return png_byte_stream

        return StringIO.StringIO(png_bytes)
Exemple #5
0
	def fetch_info(self, zoom_level, x, y):
		#first, try to find the tile at this zoom level
		#if we don't then that means somewhere above us in the tree is a leaf node
		curs = self.conn.cursor()

		for z in range(zoom_level, -1, -1):
			node_id = tiletree.build_node_id(z, x, y)
			curs.execute(\
	"""
	SELECT nodes.is_blank, nodes.is_full, nodes.is_leaf, nodes.metadata
	FROM %s nodes
	WHERE nodes.node_id = %%s
	""" % (self.node_table,), (node_id,) )
			result = curs.fetchone()
			if(result):
				return result

			x = int(math.floor(x/2.0))
			y = int(math.floor(y/2.0))

		raise tiletree.TileNotFoundException()
Exemple #6
0
	def build_image(self, surface, node):
		img_bytes = StringIO.StringIO()
		img_id = tiletree.build_node_id(node.zoom_level, node.tile_x, node.tile_y)
		surface.write_to_png(img_bytes)
		img_bytes = tiletree.palette_png_bytes(StringIO.StringIO(img_bytes.getvalue()))
		return (img_id, img_bytes)