示例#1
0
文件: wms.py 项目: demiurg/ga_ows
 def from_request(cls, request):
     request['layers'] = request.get('layers').split(',')
     request['srs'] = request.get('srs', None)
     request['filter'] = request.get('filter')
     request['bbox'] = request.get('bbox')
     request['width'] = int( request.get('width') )
     request['height'] = int( request.get('height') )
     request['styles'] = request.get('styles')
     request['format'] = request.get('format', 'png')
     request['bgcolor'] = request.get('bgcolor')
     request['transparent'] = request.get('transparent', False) == 'true'
     request['time'] = utils.parsetime(request.get('time'))
     request['elevation'] = request.get('elevation', None)
     request['v'] = request.get('v', None)
     request['fresh'] = request.get('fresh', False)
示例#2
0
文件: base.py 项目: kb9zzw/mn_climate
 def from_request(cls, request):
     request['layers'] = request.get('layers').split(',')
     request['srs'] = request.get('srs', None)
     request['filter'] = request.get('filter')
     request['bbox'] = request.get('bbox')
     request['width'] = int( request.get('width') )
     request['height'] = int( request.get('height') )
     request['styles'] = request.get('styles').split(',')
     request['format'] = request.get('format', 'png')
     request['bgcolor'] = request.get('bgcolor')
     request['transparent'] = request.get('transparent', False) == 'true'
     request['time'] = utils.parsetime(request.get('time'))
     request['elevation'] = request.get('elevation', None)
     request['v'] = request.get('v', None)
     request['fresh'] = request.get('fresh', False)
示例#3
0
def maybedate(value):
    return parsetime(value)
示例#4
0
文件: wms.py 项目: gijs/ga_ows
    def GetMap(self,  
        r,
        layers=None, 
        srs=None,
        bbox=None,
        width=None, 
        height=None, 
        styles=None, 
        format='image/png', 
        bgcolor=None,
        transparent=True,
        exceptions='application/vnd.ogc.se_xml',
        times=None,
        elevations=None,
        **kwargs
    ):

        if not width:
            raise common.MissingParameterValue.at('width')
        if not height:
            raise common.MissingParameterValue.at('height')
        if not layers:
            raise common.MissingParameterValue.at('layers')
        if self.adapter.requires_time and not times:
            raise common.MissingParameterValue.at('times')
        if self.adapter.requires_elevation and not elevations:
            raise common.MissingParameterValue.at('elevations')

        d = {
            'layers' : layers, 'srs' : srs, 'bbox' : bbox, 'width' : width, 'height' : height, 
            'styles' : styles, 'format' : format, 'bgcolor' : bgcolor, 'transparent' : transparent, 
            'exceptions' : exceptions, 'times' : times, 'elevations' : elevations
        }
        for k,v in kwargs.items():
            d[k] = v

        cache_key = self.adapter.get_cache_key(**d)
        if cache_key:
            r = Cache.retrieve(self.adapter.application, cache_key)
            if r:
                return HttpResponse(r, mimetype=format)

        layers = layers.split(',')
        width = int(width)
        height = int(height)

        bbox = [float(x) for x in bbox.split(',')]
        
        if times:
            times = [utils.parsetime(t) for t in times.split(',')]

        if elevations:
            elevations = [float(e) for e in elevations.split(',')]

        if format.startswith('image/'):
            format = format[len('image/'):]

        ds = self.adapter.get_2d_dataset(
            query_layers=layers, 
            srs=srs, 
            bbox=bbox, 
            width=width, 
            height=height, 
            styles=styles, 
            bgcolor=bgcolor, 
            transparent=transparent, 
            times=times, 
            elevations=elevations,
            **kwargs
        )
 
        tmp = None
        if type(ds) is not gdal.Dataset: # then it == a Cairo imagesurface or numpy array, or at least... it'd BETTER be
            if ds.__class__.__base__ is cairo.Surface:
                tmp = tempfile.NamedTemporaryFile(suffix='.png')
                ds.write_to_png(tmp.name)
                ds = gdal.Open(tmp.name)
                # TODO add all the appropriate metadata from the request into the dataset if this == being returned as a GeoTIFF
            else:
                tmp = tempfile.NamedTemporaryFile(suffix='.tif')
                scipy.misc.imsave(tmp.name, ds)
                ds = gdal.Open(tmp.name)
                # TODO add all the appropriate metadata from the request into the dataset if this == being returned as a GeoTIFF

        if format == 'tiff' or format == 'geotiff':
            tmp = tempfile.NamedTemporaryFile(suffix='.tif')
            ds2 = gdal.GetDriverByName('GTiff').CreateCopy(tmp.name, ds)
            del ds2
            tmp.seek(0)
            ret = HttpResponse(tmp.read(), mimetype='image/' + format)
        elif format == 'png':
            tmp = tempfile.NamedTemporaryFile(suffix='.png')
            ds2 = gdal.GetDriverByName('png').CreateCopy(tmp.name, ds)
            del ds2
            tmp.seek(0)
            ret = HttpResponse(tmp.read(), mimetype='image/' + format)
        elif format == 'jpg' or format == 'jpeg':
            tmp = tempfile.NamedTemporaryFile(suffix='.jpg')
            ds2 = gdal.GetDriverByName('jpeg').CreateCopy(tmp.name, ds)
            del ds2
            tmp.seek(0)
            ret = HttpResponse(tmp.read(), mimetype='image/' + format)
        elif format == 'jp2k' or format == 'jpeg2000':
            tmp = tempfile.NamedTemporaryFile(suffix='.jp2')
            ds2 = gdal.GetDriverByName('jpeg2000').CreateCopy(tmp.name, ds)
            del ds2
            tmp.seek(0)
            ret = HttpResponse(tmp.read(), mimetype='image/' + format)
        elif format == 'gif':
            tmp = tempfile.NamedTemporaryFile(suffix='.gif')
            ds2 = gdal.GetDriverByName('gif').CreateCopy(tmp.name, ds)
            del ds2
            tmp.seek(0)
            ret = HttpResponse(tmp.read(), mimetype='image/' + format)
        else:
            try:
                tmp = tempfile.NamedTemporaryFile(suffix='.' + format)
                ds2 = gdal.GetDriverByName(format.encode('ascii')).CreateCopy(tmp.name, ds)
                del ds2
                tmp.seek(0)
                ret = HttpResponse(tmp.read(), mimetype='image/' + format)
            except Exception as ex:
                del tmp
                raise common.NoApplicableCode(str(ex))

        if cache_key and tmp:
            expiration = self.expires(datetime.datetime.now())
            tmp.seek(0)
            Cache.add(self.adapter.application, tmp.read(), cache_key, expires=expiration)
        return ret