コード例 #1
0
ファイル: mapnik.py プロジェクト: joto/MapQuest-Render-Stack
    def process(self, tile):
        #from lat,lng bbox to mapnik bbox
        p0 = self.map_proj.forward(Coord(tile.bbox[0][1],tile.bbox[0][0]))
        p1 = self.map_proj.forward(Coord(tile.bbox[1][1],tile.bbox[1][0]))
        bbox = Box2d(p0,p1)        
        image = Image(tile.size[0],tile.size[1])
        features = None
        
        result = self._check_region(bbox)
        if result is not None:
            if result[0]:
                result[1].resize(image.width(),image.height())
                result[1].zoom_to_box(bbox)
                self.adjust_language(result(1), tile.lang)
                render(result[1],image)
                features = self.save_rendered_metadata(result[1], tile.size, tile.dimensions)
            else :
                mq_logging.info("COMPOSITE MAP: %s" % result[2])
                default_image = Image(tile.size[0],tile.size[1])
                # mask style
                self.mask_map.resize(image.width(),image.height())
                self.mask_map.zoom_to_box(bbox)
                self.adjust_language(self.mask_map, tile.lang)
                render(self.mask_map,image)
                
                # default style
                self.default_map.resize(default_image.width(),default_image.height())
                self.default_map.zoom_to_box(bbox)
                self.adjust_language(self.default_map, tile.lang)
                render(self.default_map,default_image)
                features = self.save_rendered_metadata(self.default_map, tile.size, tile.dimensions)
                
                # composite DST_OUT
                default_image.composite(image,CompositeOp.dst_out)
                
                # current style
                result[1].resize(image.width(),image.height())
                result[1].zoom_to_box(bbox)
                image.set_alpha(0)
                self.adjust_language(result[1], tile.lang)
                render(result[1],image)
                if features is not None:
                    features.features.extend(self.save_rendered_metadata(result[1], tile.size, tile.dimensions).features)
                else:
                    features = self.save_rendered_metadata(result[1], tile.size, tile.dimensions)

                # blend 
                image.blend(0,0,default_image,1.0)                
        else :
            # use default style
            self.default_map.resize(image.width(),image.height())
            self.default_map.zoom_to_box(bbox)
            self.adjust_language(self.default_map, tile.lang)
            render(self.default_map,image)
            features = self.save_rendered_metadata(self.default_map, tile.size, tile.dimensions)

        #convert to PIL image
        image = PIL.Image.frombuffer('RGBA', (image.width(), image.height()), image.tostring(), 'raw', 'RGBA', 0, 3)

        return RenderResult.from_image(tile, image, features)
コード例 #2
0
ファイル: aerial.py プロジェクト: abta/MapQuest-Render-Stack
   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)
コード例 #3
0
ファイル: terrain.py プロジェクト: abta/MapQuest-Render-Stack
	def process(self, tile):
		#mq_logging.info(str(tile.bbox))
    	
		#http://mq-aerial-lm01.ihost.aol.com:8000/ter/z/x/y.png   NOTE:  file format ignored; PNG always returned
		theURL = "http://%s:%d/ter/%d/%d/%d.png" % ( self.host, self.port, tile.z, tile.x, tile.y )

		returnData = getTile( theURL )

		if returnData is None or len(returnData) < 1:
			return None, None

		try:
			image = PIL.Image.open( StringIO.StringIO( returnData ) )
		except Exception as detail:
			#use the land tile for places we dont have terrain
			#image = self.blank
			return None, None
		
		#hand back the image
		return RenderResult.from_image(tile, image)