Changeset 3634 for TI05-delivery


Ignore:
Timestamp:
17/03/08 16:44:21 (11 years ago)
Author:
spascoe
Message:

Test for GDAL support. Not completely working yet.

Location:
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common
Files:
4 added
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/wms_gdal.py

    r3621 r3634  
    44relies on a further interface, IGDALDataSource, to provide the data. 
    55 
     6@todo: The source is a little confused about the difference between 
     7    Dataset (i.e. a GDAL Dataset object) and DataSource (A wrapper 
     8    around a GDAL dataset defined in IGDALDataSource).  Fix this. 
     9 
    610""" 
    711 
    812from ows_common.service.wms_iface import * 
    913from ows_common.bbox_util import geoToPixel 
     14 
     15import Image 
    1016 
    1117import logging 
     
    8793 
    8894    def _getCRSs(self): 
    89         return [self._ds.crs] + self._warpCRS.keys() 
     95        return [self._ds.crs] + self.warpCRS.keys() 
    9096    crss = property(_getCRSs) 
    9197 
    9298    def getBBox(self, crs): 
    9399        src_bb = self._ds.getBBox() 
    94         if self.crs == self._ds.crs: 
     100        if crs == self.sourceCRS: 
    95101            return src_bb 
    96102 
     
    128134        self.dimValues = dimValues 
    129135        self.rendOpts = renderOpts 
    130         self.bbox = layer.getBBOX(crs) 
     136        self.bbox = layer.getBBox(crs) 
    131137         
    132138        if crs == layer.sourceCRS: 
     
    137143    def getImage(self, bbox, width, height):         
    138144        # Calculate the pixel coordinates of bbox within self.bbox 
    139         xoff, yoff = geoToPixel(bbox[0], bbox[1], self.bbox, width, height) 
    140         xsize, ysize = geoToPixel(bbox[2], bbox[3], self.bbox, width, height) 
     145        w, h = self._data.RasterXSize, self._data.RasterYSize 
     146        llx, lly = geoToPixel(bbox[0], bbox[1], self.bbox, w, h) 
     147        urx, ury = geoToPixel(bbox[2], bbox[3], self.bbox, w, h) 
     148        xoff, yoff = llx, ury 
     149        xsize, ysize = urx-llx, lly-ury 
    141150 
    142         return datasetToImage(self._data, xoff, yoff, xsize, ysize) 
    143  
     151        img = datasetToImage(self._data, xoff, yoff, xsize, ysize) 
     152        return img.resize((width, height)) 
    144153 
    145154#----------------------------------------------------------------------------- 
     
    151160 
    152161    """ 
    153     ds = self._ds 
    154162    bandImages = [] 
    155163    for iband in range(1, ds.RasterCount+1): 
    156164        band = ds.GetRasterBand(iband) 
    157         bandImages.append(Image.fromstring('L', (x, y), 
     165        bandImages.append(Image.fromstring('L', (xsize, ysize), 
    158166                                           band.ReadRaster(xoff, yoff, 
    159167                                                           xsize, ysize))) 
     
    175183    ds = dataSource.getDataset() 
    176184    dr = gdal.GetDriverByName(driverName) 
    177     # ... 
    178     #dsOut = dr.Create(datasetName, ds. 
     185    #!TODO: How big should the image be? Just fudge the issue for now. 
     186    dsOut = dr.Create(datasetName, ds.RasterXSize, ds.RasterYSize, 4, 
     187                      gdal.GDT_Byte) 
     188    dsOut.SetProjection(wkt) 
     189 
     190    gdal.ReprojectImage(ds, dsOut, ds.GetProjection, wkt) 
     191    return dsOut 
    179192     
    180193 
Note: See TracChangeset for help on using the changeset viewer.