[gdal-dev] VRT pixel functions on tiled vrt

William Kyngesburye woklist at kyngchaos.com
Thu Apr 26 06:22:05 PDT 2018


I'm trying to add a pixel function (Python) to a vrt where there are multiple rasters (ComplexSource) tiled together (that is, not stacked like an RGB image).  When I translate the vrt to a tif, only the first ComplexSource is processed, the rest on the raster is set to 0.

I got the basics of the functin from the vrt docs, and it does work, for the first raster tile.  Maybe the python notation for calculating the numpy array is wrong?

The original vrt is created from gdalbuildvrt.  This is the vrt thru the first 2 rasters:

<VRTDataset rasterXSize="14401" rasterYSize="4801">
 <SRS>GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4326"]]</SRS>
 <GeoTransform> -2.5000416666666666e+01,  8.3333333333333263e-04,  0.0000000000000000e+00,  6.7000416666666666e+01,  0.0000000000000000e+00, -8.3333333333333263e-04</GeoTransform>
 <VRTRasterBand dataType="Byte" band="1" subClass="VRTDerivedRasterBand">
   <PixelFunctionType>land</PixelFunctionType>
   <PixelFunctionLanguage>Python</PixelFunctionLanguage>
   <PixelFunctionCode><![CDATA[
import numpy
def land(in_ar, out_ar, xoff, yoff, xsize, ysize, raster_xsize, raster_ysize, buf_radius, gt, **kwargs):
	out_ar[:] = (in_ar[0] > 0)
]]>
   </PixelFunctionCode>
   <ColorInterp>Gray</ColorInterp>
   <ComplexSource>
     <SourceFilename relativeToVRT="1">n63w017.tif</SourceFilename>
     <SourceBand>1</SourceBand>
     <SourceProperties RasterXSize="1201" RasterYSize="1201" DataType="Int16" BlockXSize="1201" BlockYSize="3" />
     <SrcRect xOff="0" yOff="0" xSize="1201" ySize="1201" />
     <DstRect xOff="9600" yOff="3600" xSize="1201" ySize="1201" />
     <NODATA>-32768</NODATA>
   </ComplexSource>
   <ComplexSource>
     <SourceFilename relativeToVRT="1">n63w018.tif</SourceFilename>
     <SourceBand>1</SourceBand>
     <SourceProperties RasterXSize="1201" RasterYSize="1201" DataType="Int16" BlockXSize="1201" BlockYSize="3" />
     <SrcRect xOff="0" yOff="0" xSize="1201" ySize="1201" />
     <DstRect xOff="8400" yOff="3600" xSize="1201" ySize="1201" />
     <NODATA>-32768</NODATA>
   </ComplexSource>
...
 </VRTRasterBand>
</VRTDataset>


-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

The equator is so long, it could encircle the earth completely once.



More information about the gdal-dev mailing list