I have a shape with some features (let's say 100) and a second shape with some of this features (50) buffered (5 meters inside buffer). I want to select and write in a new shape every feature of the first shape which doesn't contain the buffered feature of the second shape. I tried two different approaches with no success:
1) Select by location. Select the features of shape 1 which doesn't intersect with shape2 (ST_difference):
ogr2ogr diff.shp parcels1.shp -dialect SQLite -sql "select st_difference(a.geometry, b.geometry) as geometry from parcels1 as a, """parcels1_buffer5m.shp""".parcels1_buffer5m as b"
No error, but every feature is selected.
2) Select ID (in my case DN_OID) which is not included in the list of DN_OID of second shape:
import fiona with fiona.open("parcels1.shp") as input: meta = input.meta with fiona.open('diff.shp', 'w',**meta) as output: for feature in input: if feature['properties']['DN_OID'] not in ("SELECT DN_OID FROM parcels1_buffer5m.geom"): output.write(feature)
Any advice is welcomed.