I have two overlapping vector files (polygons and sample) and want to do a spatial join from the command line to extract all features in polygons that intersect with sample. Essentially I want to have the same result as if I was using the "Join attributes by location" function in QGIS with "Only keep matching records" including the attribute table.
This should be possible with OGR and a SQL query, but I can't get the syntax to work. So far I have tried with a vrt file following this description
And then something like:
ogrinfo -sql "SELECT * FROM sample WHERE ST_INTERSECTS (polygons,sample)" -dialect SQLITE plogonesandsample.vrt
However I find this very cumbersome and not generic.
I seek a solution that works from the command line.