Beispiel #1
0
 def fetch_render(self, zoom_level, x, y, render_info, extent, label_geoms,
                  layers):
     if ((render_info.min_zoom != None
          and render_info.min_zoom > zoom_level)
             or (render_info.max_zoom != None
                 and render_info.max_zoom < zoom_level)):
         return None
     storage_manager = render_info.storage_manager
     renderer = render_info.renderer
     cutter = render_info.cutter
     try:
         result = storage_manager.fetch(zoom_level, x, y)
         if (render_info.name in layers):
             return result
         return None
     except tiletree.TileNotFoundException:
         bbox = tiletree.tile_coord_to_bbox(zoom_level, x, y, extent)
         geom = cutter.cut(bbox[0], bbox[1], bbox[2], bbox[3])
         node = tiletree.QuadTreeGenNode(None,
                                         bbox[0],
                                         bbox[1],
                                         bbox[2],
                                         bbox[3],
                                         zoom_level,
                                         None,
                                         geom=geom,
                                         tile_x=x,
                                         tile_y=y,
                                         label_geoms=label_geoms[0])
         renderer.tile_info(node, check_full=render_info.check_full)
         img_bytes = renderer.render(node)[1]
         storage_manager.store(node, img_bytes)
         label_geoms[0] = node.label_geoms
         if (render_info.name in layers):
             return StringIO.StringIO(img_bytes.getvalue())
         return None
Beispiel #2
0
	def fetch_render(self, zoom_level, x, y, render_info, extent, label_geoms, layers):
		if((render_info.min_zoom != None and render_info.min_zoom > zoom_level) or
				(render_info.max_zoom != None and render_info.max_zoom < zoom_level) ):
			return None
		storage_manager = render_info.storage_manager
		renderer = render_info.renderer
		cutter = render_info.cutter
		try:
			result =  storage_manager.fetch(zoom_level, x, y)
			if(render_info.name in layers):
				return result
			return None
		except tiletree.TileNotFoundException:
			bbox = tiletree.tile_coord_to_bbox(zoom_level, x, y, extent)
			geom = cutter.cut(bbox[0], bbox[1], bbox[2], bbox[3])
			node = tiletree.QuadTreeGenNode(None,  bbox[0], bbox[1], bbox[2], bbox[3], zoom_level, None,
				geom=geom, tile_x=x, tile_y=y, label_geoms=label_geoms[0])
			renderer.tile_info(node, check_full=render_info.check_full)
			img_bytes = renderer.render(node)[1]
			storage_manager.store(node, img_bytes)
			label_geoms[0] = node.label_geoms
			if(render_info.name in layers):
				return StringIO.StringIO(img_bytes.getvalue())
			return None
Beispiel #3
0
def create_machine_jobs(global_config):
    dist_render_config = global_config['dist_render']

    #override parameteres with render_extent if necessary
    render_extent = global_config['map_extent']
    if ('render_extent' in dist_render_config):
        render_extent = dist_render_config['render_extent']
        tile_coords = tiletree.extent_to_tile_coord(
            render_extent, global_config['map_extent'])
        print 'Root Tile Coordinate:', tile_coords
        dist_render_config['start_zoom'] = tile_coords[0]
        dist_render_config['start_tile_x'] = tile_coords[1]
        dist_render_config['start_tile_y'] = tile_coords[2]
        #get the extent of the root node
        render_extent = tiletree.tile_coord_to_bbox(
            tile_coords[0], tile_coords[1], tile_coords[2],
            global_config['map_extent'])

    total_num_threads = sum(x['num_threads']
                            for x in dist_render_config['render_nodes'])
    min_num_jobs = dist_render_config.get('min_num_jobs', 1)
    if (total_num_threads > min_num_jobs):
        min_num_jobs = total_num_threads
    map_extent = global_config['map_extent']

    jobs = split_bbox(min_num_jobs, dist_render_config['start_zoom'],
                      dist_render_config['start_tile_x'],
                      dist_render_config['start_tile_y'],
                      dist_render_config['stop_zoom'], *render_extent)

    fill_to_zoom_level = jobs[0].zoom_level - 1

    jobs_per_thread = int(math.ceil(len(jobs) / float(total_num_threads)))

    render_node_configs = {}
    for render_node in dist_render_config['render_nodes']:
        this_num_jobs = min(jobs_per_thread * render_node['num_threads'],
                            len(jobs))
        #inherit the stuff from the global config
        this_config = copy.copy(global_config)
        this_config.update({
            'address': render_node['address'],
            'num_threads': render_node['num_threads'],
            'jobs': []
        })
        for job in jobs[0:this_num_jobs]:
            this_config['jobs'].append({
                'extent': [job.min_x, job.min_y, job.max_x, job.max_y],
                'start_zoom':
                job.zoom_level,
                'stop_zoom':
                dist_render_config['stop_zoom'],
                'tile_x':
                job.tile_x,
                'tile_y':
                job.tile_y,
            })
        del jobs[0:this_num_jobs]
        render_node_configs[render_node['address']] = this_config

    #add in any left over bits at the top of the tree
    if (fill_to_zoom_level >= dist_render_config['start_zoom']):
        render_node_configs.values()[0]['jobs'].append({
            'extent':
            render_extent,
            'start_zoom':
            dist_render_config['start_zoom'],
            'stop_zoom':
            fill_to_zoom_level,
            'tile_x':
            dist_render_config['start_tile_x'],
            'tile_y':
            dist_render_config['start_tile_y'],
        })

    #print json.dumps(render_node_configs)

    return render_node_configs
Beispiel #4
0
def create_machine_jobs(global_config):
	dist_render_config = global_config['dist_render']

	#override parameteres with render_extent if necessary
	render_extent = global_config['map_extent']
	if('render_extent' in dist_render_config):
		render_extent = dist_render_config['render_extent']
		tile_coords = tiletree.extent_to_tile_coord(render_extent, global_config['map_extent'])
		print 'Root Tile Coordinate:', tile_coords
		dist_render_config['start_zoom'] = tile_coords[0]
		dist_render_config['start_tile_x'] = tile_coords[1]
		dist_render_config['start_tile_y'] = tile_coords[2]
		#get the extent of the root node
		render_extent = tiletree.tile_coord_to_bbox(tile_coords[0], tile_coords[1], tile_coords[2],
				global_config['map_extent'])


	total_num_threads = sum(x['num_threads'] for x in dist_render_config['render_nodes'])
	min_num_jobs = dist_render_config.get('min_num_jobs', 1)
	if(total_num_threads > min_num_jobs):
		min_num_jobs = total_num_threads
	map_extent = global_config['map_extent']

	jobs = split_bbox(min_num_jobs, dist_render_config['start_zoom'],
			dist_render_config['start_tile_x'], dist_render_config['start_tile_y'],
			dist_render_config['stop_zoom'], *render_extent)

	fill_to_zoom_level = jobs[0].zoom_level - 1

	jobs_per_thread = int(math.ceil(len(jobs) / float(total_num_threads)))

	render_node_configs = {}
	for render_node in dist_render_config['render_nodes']:
		this_num_jobs = min(jobs_per_thread * render_node['num_threads'], len(jobs))
		#inherit the stuff from the global config
		this_config = copy.copy(global_config)
		this_config.update({
			'address': render_node['address'],
			'num_threads': render_node['num_threads'],
			'jobs': []
		})
		for job in jobs[0:this_num_jobs]:
			this_config['jobs'].append({
				'extent': [job.min_x, job.min_y, job.max_x, job.max_y],
				'start_zoom': job.zoom_level,
				'stop_zoom': dist_render_config['stop_zoom'],
				'tile_x':job.tile_x,
				'tile_y':job.tile_y,
			})
		del jobs[0:this_num_jobs]
		render_node_configs[render_node['address']] = this_config

	#add in any left over bits at the top of the tree
	if(fill_to_zoom_level >= dist_render_config['start_zoom']):
		render_node_configs.values()[0]['jobs'].append({
			'extent': render_extent,
			'start_zoom': dist_render_config['start_zoom'],
			'stop_zoom': fill_to_zoom_level,
			'tile_x': dist_render_config['start_tile_x'],
			'tile_y': dist_render_config['start_tile_y'],
		})

	#print json.dumps(render_node_configs)

	return render_node_configs