[gdal-dev] Re: OGR GML and other drivers producing text output: stdout, /dev/stdout and /vsistdout/ (was: ogr2ogr - output WKT to console?)

Even Rouault even.rouault at mines-paris.org
Thu Sep 1 07:33:51 EDT 2011


> About the GML driver:
>
> I was just wondering where the .xsd file is written to when using:
> ogr2ogr -f gml /vsistdout/. According to the gml file's
> xsi:schemaLocation attribute, the schema file is `.xsd', see [1]. I
> can't find `.xsd' locally.
>
> When using /dev/stdout rather than /vsistdout/, I receive an error,
> which tells me that the schema file can't be created, see [2].
>
> Another observation with the gml driver: stdout is defined as an alias
> for /vsistdout/ (rather than /dev/stdout). When using the alias,
> xsi:schemaLocation tells me that the schema file is `stdout.xsd', see
> [3]. I can't find `stdout.xsd' locally.

stdout output for GML is a bit particular. No schema file is written in that
case (people using stdout want likely to use it for pipeling, so there's nothing
we can do with the schema). The value of the xsi:schemaLocation attribute is
more or less garbage in that case. There are also limitations. For example the
global <boundedBy> element cannot be written in that case (would need to seek
backward...).

But yes, it lacks the special case to recognize /dev/stdout as a particular
value where you must not try to write a file, which would avoid error [2].

>
>
> About other drivers producing text output:
>
> There seem to be several options about how to alias (/dev/)stdout and
> /vsistdout/. The current practice is perhaps somewhat inconsistent, see
> [4]. IMO, Even's recently added /dev/stdout -> /vsistdout/ alias looks
> most appropriate, I am however not so sure about non-Unix OSs.
>
> Finally, only drv_pgdump.html seems to mention /vsistdout/ as an option
> for writing to standard output, see [5]. Perhaps other relevant driver
> pages should also mention this option ?
>
>
> Would it be worth creating a ticket (or two) related to the above
> observations?

Yes we probably lack consistency in that area. I think the stdout case should be
removed (should not affect many people as it was unadvertized feature), and only
accept /dev/stdout and /vsistdout/ which are less hacky solutions.

>
>
> Hermann
>
>
> [1]
>
> $ ogr2ogr -f gml /vsistdout/ test.shp
> <?xml version="1.0" encoding="utf-8" ?>
> <ogr:FeatureCollection
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xsi:schemaLocation="http://ogr.maptools.org/ .xsd"
>       xmlns:ogr="http://ogr.maptools.org/"
>       xmlns:gml="http://www.opengis.net/gml">
>    <gml:featureMember>
>      <ogr:test fid="F0">
>      (...)
>
>
> [2]
>
> ERROR 4: Failed to open file /dev/stdout.xsd for schema output.
>
>
> [3]
>
> $ ogr2ogr -f gml stdout test.shp
> <?xml version="1.0" encoding="utf-8" ?>
> <ogr:FeatureCollection
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xsi:schemaLocation="http://ogr.maptools.org/ stdout.xsd"
>       xmlns:ogr="http://ogr.maptools.org/"
>       xmlns:gml="http://www.opengis.net/gml">
>    <gml:featureMember>
>      <ogr:test fid="F0">
>      (...)
>
>
> [4]
>
> ./gpx/ogrgpxdatasource.cpp:    if( EQUAL(pszFilename,"stdout") ||
> EQUAL(pszFilename,"/vsistdout/"))
> ./gml/ogrgmldatasource.cpp:    if( EQUAL(pszFilename,"stdout") ||
> EQUAL(pszFilename,"/vsistdout/"))
> ./kml/ogrkmldatasource.cpp:    if( EQUAL(pszName, "stdout") ||
> EQUAL(pszName, "/vsistdout/") )
> ./csv/ogrcsvdriver.cpp:    if (strcmp(pszName, "/dev/stdout") == 0)
> ./bna/ogrbnadatasource.cpp:    if( EQUAL(pszFilename,"stdout") )
> ./georss/ogrgeorssdatasource.cpp:    if( EQUAL(pszFilename,"stdout") )
> ./geojson/ogrgeojsondatasource.cpp:    if( EQUAL( pszName, "stdout" ) )
>
>
> [5]
>
> $ find ogr/ -name '*.html' | xargs grep "/vsistdout/"
> ogr/ogrsf_frmts/pgdump/drv_pgdump.html:to specify /vsistdout/ as output
> file to output on the standard output.<p>
> ogr/ogrsf_frmts/pgdump/drv_pgdump.html:% ogr2ogr --config PG_USE_COPY
> YES -f PGDump /vsistdout/ abc.shp | psql -d my_dbname -f -
>




More information about the gdal-dev mailing list