0

我使用以下命令通过空间方言从带有 ogr2ogr 的地理数据库文件生成 shapefile:

ogr2ogr -f "ESRI Shapefile" ./clipped.shp -dialect sqlite -sql "SELECT * FROM table_name WHERE ST_Intersects(SHAPE, GeomFromText('POLYGON ((46.93 -17.48, 46.91 -17.55, 47.01 -17.56, 47.01 -17.46, 46.93 -17.48))'))" ./geodatabase_file.gdb

该命令本身完全按预期工作 - 仅返回与给定空间查询相交的记录。

但是,有时交集没有返回任何记录。发生这种情况时,会生成不包含任何条目的空 shapefile。如果提供的交集没有返回记录,有没有办法阻止 ogr2ogr 生成文件?

4

1 回答 1

0

我得出的结论是,这是不可能的,因为ogr2ogr首先创建一个 shapefile,然后在找到它们时向其中添加功能。相反,可以使用该ogrinfo命令来确定Feature Countshapefile 的名称,然后采取相应的行动。

ogrinfo -so -al ./geodatabase_file.gdb

此答案的信息来自对此问题的评论 - https://gis.stackexchange.com/questions/366599/is-it-possible-to-prevent-ogr2ogr-from-generating-a-shapefile-if-no -记录-是

于 2020-09-30T09:56:55.493 回答