[gdal-dev] ogr2ogr - output WKT to console?
Even Rouault
even.rouault at mines-paris.org
Wed Aug 31 18:28:56 EDT 2011
Le jeudi 01 septembre 2011 00:19:52, Elijah Robison a écrit :
> Rad. :)
>
> Thanks, Even.
>
> It took me a few minutes to realize that -f "CSV" still applied --- but
> now I'm catching on. I presume the following statement is true:
>
> The special "/vsistdout/" file path will output ogr2ogr results directly
> to the console, provided the output type is a text-based format for
> which OGR supports dataset creation.
Well, to be pedantic, the driver also needs to support the VSI Virtual File
API, which is now the case of most text based drivers that are converted over
time from the standard FILE IO API to the VSI Virtual File API.
>
> I wonder about that text-based caveat, but I wasn't able to push a
> shapefile to the console (and didn't expect to), yet I /was /able to
> push several pure text formats to the console.
This is not really a text-format versus binary-format issue. The problem with
shapefiles is that there are several files involved, and that you need to be
able to seek backward to those files to update their header. Both conditions
that make it impossible as a streaming format.
>
> For those keeping score, and for posterity within the nabble list cache,
> the following redactions of my initial ogr2ogr script send their result
> set directly to the console:
>
> ogr2ogr -f "CSV" "/vsistdout/"
> "C:\xData\CountyUpdate\GeoFix\feb16_polygons.shp" -sql "select * from
> feb16_polygons where objectid= 2126" -lco "GEOMETRY=AS_WKT" -lco
> "LINEFORMAT=CRLF" -lco "SEPARATOR=SEMICOLON"
>
> ogr2ogr -f "GML" "/vsistdout/"
> "C:\xData\CountyUpdate\GeoFix\feb16_polygons.shp" -sql "select * from
> feb16_polygons where objectid= 2126"
>
> ogr2ogr -f "KML" "/vsistdout/"
> "C:\xData\CountyUpdate\GeoFix\feb16_polygons.shp" -sql "select * from
> feb16_polygons where objectid= 2126"
>
> ogr2ogr -f "GeoJSON" "/vsistdout/"
> "C:\xData\CountyUpdate\GeoFix\feb16_polygons.shp" -sql "select * from
> feb16_polygons where objectid= 2126"
You can also add the BNA, PGDump, GeoRSS and GPX drivers to the list
>
> Many thanks to everyone who offered feedback.
>
> Best, Elijah
>
> Even Rouault wrote:
> > Le mercredi 31 août 2011 22:44:55, Elijah Robison a écrit :
> >> Hi Devs,
> >>
> >> When troubleshooting geodata integrity issues, we sometimes use ogr2ogr
> >> to push WKT expressions to a .csv file using a script like I show below.
> >> It uses an ogr sql statement to grab a single feature from a raw
> >> shapefile data source, then it saves the output to a CSV:
> >>
> >> ogr2ogr -f "CSV" "C:\xData\CountyData\Shps\OriginalParcelCSV"
> >> "C:\xData\CountyData\Shps\parcel_polygons.shp" -sql "select * from
> >> parcel_polygons where id= 9080" -lco "GEOMETRY=AS_WKT" -lco
> >> "LINEFORMAT=CRLF" -lco "SEPARATOR=SEMICOLON"
> >>
> >> As our needs in this situation are very transient, I'm curious if it is
> >> possible to output the WKT directly to the console?
> >
> > Yes, as a output filename, you can use the special name /vsistdout/ (you
> > need the trailing slash) . You likely need GDAL 1.8 or later for it to
> > work.
> >
> >> Very Best,
> >>
> >> Elijah Robison
> >> elijah at villagis.com
> >> _______________________________________________
> >> gdal-dev mailing list
> >> gdal-dev at lists.osgeo.org
> >> http://lists.osgeo.org/mailman/listinfo/gdal-dev
More information about the gdal-dev
mailing list