Try this,
ogr2ogr -f "ESRI Shapefile" out.shp road.shp \
-dialect sqlite -sql "\
select ST_Diffrence(road.geometry, seg_buff.geometry) \
from road, 'seg_buff.shp'.seg_buff seg_buff \
"
Putting an extra seg_buff
at the end makes the query work.
This extra word is needed because ogr2ogr
only automatically generates SQL table names for files passed to it directly. When specifying an additional file from within the SQL statement you must supply an arbitrary table name1 to refer to it elsewhere in the SQL statement. In this instance:
The shapefile
| The table within the shapefile
| | The name we're going to use to refer to the
| | table elsewhere in the SQL statement
| | |
------------ -------- --------
'seg_buff.shp'.seg_buff seg_buff
1 The supplied table name doesn't have to match the filename (or its contained table). For example, the following works as well:
ogr2ogr -f "ESRI Shapefile" out.shp road.shp \
-dialect sqlite -sql "\
select ST_Diffrence(road.geometry, foo.geometry) \
from road, 'seg_buff.shp'.seg_buff foo \
"
In either example, out.shp
will contain only the parts of road.shp
that are not contained within seg_buff.shp
.