在Fiona1.5.0上(我很困惑为什么不同的文件(如.dbf和.gdb)没有打印我的“!”(这是我希望在文件不是.shp的任何时候)退出前的警告。
import fiona
import sys
def process_file(self, in_file, repair_file):
with fiona.open(in_file, 'r', encoding='utf-8') as input:
# check that the file type is a shapefile
if input.driver == 'ESRI Shapefile':
print "in_file is a Shapefile!"
else:
print "NOT a Shapefile!"
exit()
with fiona.open(repair_file, 'r') as repair:
# check that the file type is a shapefile
if repair.driver == 'ESRI Shapefile':
print "Verified that repair_file is a Shapefile!"
else:
print "NOT a Shapefile!"
exit()对于gdb,我得到一个fiona不支持驱动程序的错误(因为ogr会让我感到惊讶)-并且没有print语句:
>> fiona.errors.DriverError: unsupported driver: u'OpenFileGDB'对于一个.dbf,我实际上得到了以下内容:
>> Verified that in_file is a Shapefile!
>> Verified that repair_file is a Shapefile!发布于 2015-06-03 01:51:31
使用OGR,ESRI Shapefile驱动程序读取DBF文件。要检查数据源是否只有属性,而没有几何学(即DBF文件),请检查元数据中的几何图形类型,以确定它是否为'None'。
import fiona
with fiona.open(file_name) as ds:
geom_type = ds.meta['schema']['geometry']
print('geometry type: ' + geom_type)
if geom_type == 'None':
print('no geometry column, so probably just a DBF file')此外,对OpenFileGDB的只读支持最近被添加到fiona中。更新您的包,看看它是否有效。
发布于 2015-04-28 21:09:14
支持的驱动程序的fiona数量比由ogr支持的驱动程序的数量要低得多,甚至fiona也是ogr的包装器。
ESRI shapefile文件具有误导性,因为该格式包含一个具有公共文件名前缀的文件集合,存储在同一个目录中。有三个强制文件
所以dbf是一个ESRI格式文件。
因为需要存在一个.shp文件,所以可以先测试该文件的.shp扩展名,然后使用fiona测试它是否是“exist”
https://stackoverflow.com/questions/29832301
复制相似问题