Exemple #1
0
   def process(self, tile):
	z = str(tile.z)
	x_range = range( tile.x, tile.x + tile.dimensions[0] )
	y_range = range( tile.y, tile.y + tile.dimensions[1] )
	urls = [ [self.url % {'z':z, 'x':str(x), 'y':str(y)}, x - tile.x, y - tile.y] for x in x_range for y in y_range ]

	try:
		subTiles = map(getTile, urls)
	except Exception as detail:
		mq_logging.error('Could not read tile from aerial source: %s' % str(detail))
		raise
	
        if len( subTiles ) < tile.dimensions[0] * tile.dimensions[1] :
		mq_logging.warning("Result length too short, aborting")
		return None, None
        #
        #  make a composite image
        #
        features 	= None
        image		= PIL.Image.new( 'RGBA', tile.size )   
        
        for infoImage in subTiles:
            imageSubTile = PIL.Image.open( StringIO.StringIO( infoImage[0] ) )
            image.paste( imageSubTile, ( infoImage[1] * TILE_SIZE, infoImage[2] * TILE_SIZE ) )

        return RenderResult.from_image(tile, image)
Exemple #2
0
 def add_region(self,name,mapfile,wkt_mask_file):
     # ignore attempts to add regions when no mask has been
     # specified with a warning.
     if self.mask_map is not None:
         try:
             m = Map(0,0)
             load_map(m, mapfile)
             mask = Mask(wkt_mask_file)
             self.regions.append((name,m,mask))
         except Exception as ex:
             mq_logging.error("Exception caught adding region (%s)" % str(ex))
     else:
         mq_logging.warning("Cannot add mask (%s) because no mask_style was configured." % name)
    def _update_coverages(self, coverages, mixedCoverage, tile):
        renderer = []
        indices = {}
        #make sure all of the tiles have at least some rendering system
        for tileXY, coverage in coverages.iteritems():
            # did we have a coverage name. if not, then warn and
            # use the 'missing' one, which must exist as checked in the 
            # constructor.
            if len(coverage) > 0:
                # stupid config file results in names which are all in
                # lower case, so we have to follow that convention here.
                vend_name = coverage[0].lower()
            else:
                mq_logging.warning("No coverage for style '%s' at sub tile z=%s x=%s y=%s." % (tile.style, tile.z, tile.x + tileXY[0], tile.y + tileXY[1]))
                vend_name = 'missing'

            # check that the coverage name exists, or use the 'default'
            # keyed one, again checked in the constructor.
            if vend_name in self.coverages:
                style_name = self.coverages[vend_name]
            else:
                style_name = self.coverages['default']

            if style_name not in indices:
                indices[style_name] = len(renderer)
                    
                rend = self.factory.renderer_for(style_name)
                if rend is None:
                    raise Exception("Renderer for style name '%s' could not be retrieved." % style_name)

                renderer.append(rend)

            coverages[tileXY] = indices[style_name]

            #we are done if we dont need more than one renderer
            if mixedCoverage == False:
                break

        # return the list of renderers to use
        return renderer
                    if job.status!=dqueue.ProtoCommand.cmdDirty and job.status!=dqueue.ProtoCommand.cmdRenderBulk :
                        job.data = meta_tile
                    mq_logging.info("DONE METATILE %d:%d:%d:%s tile-size=%d" % (job.z,job.x,job.y,job.style,len(job.data)))
                    job.status = dqueue.ProtoCommand.cmdDone
                    job.last_modified = int(time.time())
                except Exception as detail:
                        mq_logging.error('%s' % (detail))
			job.satus = dqueue.ProtoCommand.cmdIgnore

                notify (job, queue)

        handle = None

        # try to run a garbage collection to keep memory usage under
        # control. but this might be quite slow, so only run it 
        # every 10th job.
        job_counter += 1
        if (job_counter % 10) == 0:
            gc.collect()

        # check memory usage and, if a limit has been set and it has
        # been exceeded, then drop out of the while loop and shut 
        # down. this should cause monit to re-start the process.
        if mem_limit is not None:
            mem_size = get_virtual_size()
            if mem_size > mem_limit:
                mq_logging.warning("Memory size %d is more than memory limit %d, shutting down." % (mem_size, mem_limit))
                break