Exemple #1
0
def newGetMap(self, params):
    # HACK: check if the image should be strechted
    bbox_ratio = float(params['bbox'][2] - params['bbox'][0]) / float(params['bbox'][3] - params['bbox'][1])
    image_ratio = float(params['width']) / float(params['height'])
    img_height = params['height']
    resize = False
    
    if int(bbox_ratio * 100) != int(image_ratio * 100):
        params['height'] = int(params['height'] / bbox_ratio)
        resize = True
    
    m = self._buildMap(params)
    im = Image(params['width'], params['height'])
    render(m, im)
    format = PIL_TYPE_MAPPING[params['format']]
    
    if resize:
        import Image as PILImage
        size = params['width'], params['height']
        im = PILImage.open(StringIO(im.tostring(format)))
        size = params['width'], img_height
        im = im.resize(size)
        output = StringIO()
        im.save(output, format=format)
        return Response(params['format'].replace('8',''), output.getvalue())
        
    return Response(params['format'].replace('8',''), im.tostring(format))
 def GetMap(self, params):
     if params["bbox"][0] >= params["bbox"][2]:
         raise OGCException("BBOX values don't make sense.  minx is greater than maxx.")
     if params["bbox"][1] >= params["bbox"][3]:
         raise OGCException("BBOX values don't make sense.  miny is greater than maxy.")
     if params.has_key("styles") and len(params["styles"]) != len(params["layers"]):
         raise OGCException("STYLES length does not match LAYERS length.")
     m = Map(params["width"], params["height"])
     if params.has_key("transparent") and params["transparent"] == "FALSE":
         m.background = params["bgcolor"]
     else:
         m.background = Color(0, 0, 0, 0)
     maplayers = self.mapfactory.layers
     mapstyles = self.mapfactory.styles
     for layername in params["layers"]:
         try:
             layer = maplayers[layername]
         except KeyError:
             raise OGCException('Layer "%s" not defined.' % layername, "LayerNotDefined")
         for stylename in layer.styles:
             if stylename in mapstyles.keys():
                 m.append_style(stylename, mapstyles[stylename])
             else:
                 raise ServerConfigurationError(
                     'Layer "%s" refers to non-existent style "%s".' % (layername, stylename)
                 )
         m.layers.append(layer)
     m.zoom_to_box(Envelope(params["bbox"][0], params["bbox"][1], params["bbox"][2], params["bbox"][3]))
     im = Image(params["width"], params["height"])
     render(m, im)
     im = fromstring("RGBA", (params["width"], params["height"]), rawdata(im))
     fh = StringIO()
     im.save(fh, PIL_TYPE_MAPPING[params["format"]], quality=100)
     fh.seek(0)
     return Response(params["format"], fh.read())
 def GetMap(self, params):
     m = self._buildMap(params)
     im = Image(params['width'], params['height'])
     render(m, im)
     im = fromstring('RGBA', (params['width'], params['height']), rawdata(im))
     fh = StringIO()
     im.save(fh, PIL_TYPE_MAPPING[params['format']], quality=100)
     fh.seek(0)
     return Response(params['format'], fh.read())
Exemple #4
0
 def GetMap(self, params):
     m = self._buildMap(params)
     im = Image(params['width'], params['height'])
     render(m, im)
     im = fromstring('RGBA', (params['width'], params['height']),
                     rawdata(im))
     fh = StringIO()
     im.save(fh, PIL_TYPE_MAPPING[params['format']], quality=100)
     fh.seek(0)
     return Response(params['format'], fh.read())
Exemple #5
0
 def GetMap(self, params):
     if params['bbox'][0] >= params['bbox'][2]:
         raise OGCException(
             "BBOX values don't make sense.  minx is greater than maxx.")
     if params['bbox'][1] >= params['bbox'][3]:
         raise OGCException(
             "BBOX values don't make sense.  miny is greater than maxy.")
     if params.has_key('styles') and len(params['styles']) != len(
             params['layers']):
         raise OGCException('STYLES length does not match LAYERS length.')
     m = Map(params['width'], params['height'])
     if params.has_key('transparent') and params['transparent'] == 'FALSE':
         m.background = params['bgcolor']
     else:
         m.background = Color(0, 0, 0, 0)
     maplayers = self.mapfactory.layers
     mapstyles = self.mapfactory.styles
     for layername in params['layers']:
         try:
             layer = maplayers[layername]
         except KeyError:
             raise OGCException('Layer "%s" not defined.' % layername,
                                'LayerNotDefined')
         for stylename in layer.styles:
             if stylename in mapstyles.keys():
                 m.append_style(stylename, mapstyles[stylename])
             else:
                 raise ServerConfigurationError(
                     'Layer "%s" refers to non-existent style "%s".' %
                     (layername, stylename))
         m.layers.append(layer)
     m.zoom_to_box(
         Envelope(params['bbox'][0], params['bbox'][1], params['bbox'][2],
                  params['bbox'][3]))
     im = Image(params['width'], params['height'])
     render(m, im)
     im = fromstring('RGBA', (params['width'], params['height']),
                     rawdata(im))
     fh = StringIO()
     im.save(fh, PIL_TYPE_MAPPING[params['format']], quality=100)
     fh.seek(0)
     return Response(params['format'], fh.read())