I'm running up against an issue doing a spatial operation requiring multiple input shapefiles using ogr2ogr and SQLite.

I have:

ogr2ogr -f "ESRI Shapefile" output.shp input.shp -dialect sqlite -sql "CREATE VIRTUAL TABLE 'overlap' USING VirtualOGR('overlap.shp'); SELECT ST_SymDifference('input','overlap')"

Where 'output' is my output shape, 'input' is one input shape and 'overlap' is the other input shape. I can't seem to get any output, or if I do, it's just a DBF file? Any assistance?

I suspect it's to do with the Virtual Table not having any geometry but I can't seem to do a "RecoveryGeometryColumn" that actually works.

Both 'input' and 'overlap' have the same projection and overlap nicely in QGIS.

I'm on version "GDAL 1.10.0, released 2013/04/24"


Edit: Fixed typos in my sqlite command


ogr2ogr -f "ESRI Shapefile" output.shp input.shp -dialect sqlite -sql "SELECT ST_SymDifference(GEOMETRY,'overlap.sqlite.GEOMETRY'),* FROM input"

Just returns the input shape. I think I've completely missed something obvious...

1 Answer 1


Firstly, wrap your input.shp and overlap.shp into an OGR VRT file (e.g. test.vrt) :

    <OGRVRTLayer name="input">
    <OGRVRTLayer name="overlap">

Then you can execute:

ogr2ogr output.shp test.vrt -dialect sqlite -sql "SELECT ST_SymDifference(g1.geometry,g2.geometry) AS geometry FROM input AS g1, overlap AS g2"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.