2

我有一个 shapefile,我想通过执行 SQL 脚本来查询几何(多边形)内部的特征。我正在使用 Python osgeo 库来运行查询:

shapefile = osgeo.ogr.Open(file)
layer = shapefile.GetLayer()
driver = osgeo.ogr.GetDriverByName('ESRI Shapefile')
layer = shapefile.GetLayer()
test = shapefile.ExecuteSQL('select * from "%s"' % layer.GetName())

However, I have no idea how to alter this select statement to select items that are inside of the polygon (ie POLYGON(12.578608968 55.6344916225, 12.578625747 55.6344383472, 12.5791438324 55.633937277, 12.5792915832 55.6339468684, 12.5793944291 55.6340760336, 12.578608968 55.6344916225)). 我的直觉说它会是这样的:

select * from layer
where geometry in Polygon(.....)

我可以使用 QuantumGIS 桌面中的 GUI 来做到这一点,因此必须也可以在 SQL 中查询功能,尽管我无法在线找到任何资源。

对此有什么想法吗?

4

1 回答 1

0

我认为 GDAL 的Intersects方法是您需要的方法,它通过比较来确定两个几何图形是否相互交叉,如下所示:

geomA.Intersects(geomB)

使用这种方法,您可以将要比较的多边形保存到几何中,然后迭代 shapefile 中的特征,比较每个特征以查看它是否与所需的多边形相交(使用GetNextFeature(),或通过执行一些查询然后迭代结果集)。

于 2018-01-08T17:21:59.090 回答