[gdal-dev] VSIF and Python

Ari Jolma ari.jolma at gmail.com
Mon Nov 14 09:55:43 EST 2011

On 11/14/2011 02:44 PM, Frank Broniewski wrote:
> I want to do: read geodata with ogr, do some work with it and dump the 
> result, in case of a text file format, to string instead to file. 
> Right now I am doing the same with an extra step (save the result to 
> file and read it again with python).
> There's no way to inject a file like object (file, stringio) to gdal 
> instead of path names, isn't there?

This is not an answer and I don't speak for the Python bindings. Instead 
I'm looking at this from the
point of view of Perl bindings.

Latest Perl bindings do have the VSIF{Open,Close,Seek,Tell,Write}L API 
but they are not documented[1]. Mostly because I haven't used/tried 
them. The following is some quick thoughts on how they might be used.

This prints out a shapefile in GML (works now)

use Geo::GDAL;
$datasource = Geo::OGR::Open('/home/ajolma/shapefile.shp');
Geo::OGR::Driver('GML')->Copy($datasource, '/dev/stdout');

The problem with this is I seem to be unable to use any Perl XML/GML 
processing tools. It might be useful to do something like this:

use Geo::GDAL;
use XML::Parser;
$datasource = Geo::OGR::Open('/home/ajolma/shapefile.shp');
$handle = Geo::OGR::Driver('GML')->Copy($datasource);
$p = new XML::Parser();

It seems to me that I'm at least missing a method to get the VSILFILE 
name to be able to build the support for the latter. The $handle should 
also be something like a standard Perl IO::Handle object. The point here 
is to avoid writing to and reading from a file. I think I don't even 
have to possibility to write to a string .. maybe though a memory file yes.

Just thinking,


[1] http://geoinformatics.tkk.fi/doc/Geo-GDAL/html/

More information about the gdal-dev mailing list