[gdal-dev] Re: VRT creation with Python
Even Rouault
even.rouault at mines-paris.org
Fri Mar 26 15:19:45 EDT 2010
Michael,
In case you're not aware of it, you don't have to write the VRT in a on-disk
file. You can store it into a Python string instead, like :
vrt_desc = """
<VRTDataset rasterXSize="20" rasterYSize="20">
<SRS>PROJCS["NAD27 / UTM zone
11N",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke
1866",6378206.4,294.9786982139006,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4267"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-117],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","26711"]]</SRS>
<GeoTransform> 4.4072000000000000e+05, 6.0000000000000000e+01,
0.0000000000000000e+00, 3.7513200000000000e+06,
0.0000000000000000e+00, -6.0000000000000000e+01</GeoTransform>
<Metadata>
<MDI key="AREA_OR_POINT">Area</MDI>
</Metadata>
<VRTRasterBand dataType="Byte" band="1">
<Metadata/>
<ColorInterp>Gray</ColorInterp>
<SimpleSource>
<SourceFilename relativeToVRT="1">byte.tif</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize="20" RasterYSize="20" DataType="Byte"
BlockXSize="20" BlockYSize="20"/>
<SrcRect xOff="0" yOff="0" xSize="20" ySize="20"/>
<DstRect xOff="0" yOff="0" xSize="20" ySize="20"/>
</SimpleSource>
</VRTRasterBand>
</VRTDataset>
"""
ds = gdal.Open(vrt_desc)
"<VRTDataset" must be the first bytes of the "filename".
Le Friday 26 March 2010 20:12:43 Michael Aye, vous avez écrit :
> Frank Warmerdam wrote:
> > There is no public GDAL API for modifying the sourcefilename of a VRT.
> > Can you not just create the VRT files programmatically by inserting the
> > filename in a template text file?
>
> I can, but that's still more coding than with my idea of manipulating
> meta-data, basically I was thinking
> of something like:
> * ds = gdal.Open('some.vrt')
> * (maybe a ds2 = ds.Copy() or so here?)
> * ds2.SetMetaDataItem('SourceFilename', 'newFileName')
> * ds2.Reload() (or ds2.Open() if it's thinkable to have a ds handle while
> it's 'closed'?)
>
> Frank Warmerdam wrote:
> > I don't understand your point about metadata. Were you hoping the
> > metadata for the underlying file would be passed through the VRT to
> > the application? This does not occur with VRTs even when they reference
> > a GDAL supported (rather than raw) file.
>
> I understood this sentence from the http://www.gdal.org/gdal_vrttut.html
>
> VRT description :
> > . A special attribute of VRT datasets is that sources can be added to the
> > VRTRasterBand (but not to VRTRawRasterBand) by passing the XML describing
> > the source into SetMetadata() on the special domain target
> > "new_vrt_sources".
>
> like that there is at least some kind of machinery there to provide sources
> to an existing VRT dataset. I read that this is not possible for
> RawRasterBands, but was hoping that there are other possibles in GDAL,
> where this would be possible. Anyhow, I did it myself know, creating a new
> VRT for all images just before I read it.
>
> Frank Warmerdam wrote:
> > Is the .img file a PDS file? Are you aware there is a PDS driver for
> > GDAL? Are you sure you can't just access the PDS image directly?
>
> I am aware and tried it, but got the 'unsupported format' message. I am
> using PyPDS now to read the header and adapt the settings for the vrt
> creation with a self-made mini xml writer.
> Our PDS images are, I think, some of the most complex PDS data that there
> is, with several binary subframes inside, so I guess, the gdal driver still
> has to be improved for that.
> I asked our team leader, if I could provide you with an example image (it's
> as of yet non-public data), and he agreed. So if you like, I could send you
> an FC image by email, so that you could have a look at it, and hopefully
> implement it into the PDS driver.
>
> Have a good weekend!
> Michael
More information about the gdal-dev
mailing list