在QGIS中对shapefile运行SQL查询吗?


9

有什么方法可以将shapefile导入QGIS,然后对它运行空间SQL查询?

我显然ogr2ogr -sql可以这样做,但是每次都要将输出导入QGIS来查看它,这很痛苦。

如果我可以将shapefile导入QGIS,然后对它运行SQL并立即查看结果,那将是很好的。

Answers:


15

您可以使用虚拟层。将您的Shapefile加载到QGIS中,然后转到Layer / Add Layer / Add-Edit Virtual Layer。键入所需的SQL。

例如,如果您的shapefile被命名myshp并具有属性test,则可以查询为:

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

或者,您可以使用geometry字段进行空间查询:

select * from myshp 
where st_intersects(geometry, make_point(1,2));
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.