GeoDjango:引发GDALException(“无法在“%s”处打开数据源”'%ds_input)

时间:2019-02-26 08:26:39

标签: geodjango

当我以https://docs.djangoproject.com/en/2.1/ref/contrib/gis/tutorial/

上的GeoDjango教程为例时

当我使用GeoDjango的DataSource界面时,出现问题:

$ python manage.py shell
>>> import os
>>> import world
>>> world_shp=os.path.abspath(os.path.join(os.path.dirname(world.__file__), 'data', 'TM_WORLD_BOARDERS-0.3.shp'))
>>> from django.contrib.gis.gdal import DataSource
>>> ds = DataSource(world_shp)
Traceback (most recent call last):
....
packages/django/contrib/gis/gdal/datasource.py", line 74, in __init__
   raise GDALException('Could not open the datasource at "%s"' % ds_input)
django.contrib.gis.gdal.error.GDALException: Could not open the datasource at "/home/robert/PycharmProjects/geodjango/world/data/TM_WORLD_BOARDERS-0.3.shp"

我已经使用ogrinfo检查TM_WORLD_BOARDERS-0.3.shp,没关系。但是数据源无法打开它。

2 个答案:

答案 0 :(得分:1)

我在尝试导入一个包含其他相关文件(例如 .shx 索引文件和 .dbf 属性格式)的文件夹中的 .shp 文件时遇到此错误。导入父目录而不是 .shp 文件本身似乎有效。

例如

# ds = DataSource('/tmp/parent/file.shp')
ds = DataSource('/tmp/parent')

答案 1 :(得分:0)

将world_shp路径对象传递给SourceData构造函数“ str(world_shp)”时进行字符串化。

ds = DataSource(str(world_shp))