10

Is there any way I can import a shapefile into QGIS, then run spatial SQL queries against it?

I can obviously use ogr2ogr -sql to do this, but I have to import the output into QGIS each time to look at it, which is a pain.

It would be great if I could just import the shapefile into QGIS, then run SQL against it and see the results instantly.

1 Answer 1

19

You can use a virtual layer. Load your Shapefile in QGIS, then go to Layer / Add Layer / Add-Edit Virtual Layer. Type the SQL you want.

For instance, if your shapefile is named myshp and has attribute test you can query as:

select * from myshp a
where a.test = 1234;

Or you can make a spatial query using the geometry field:

select * from myshp 
where st_intersects(geometry, make_point(1,2));
0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.