我发现了一个奇怪的东西:
在python manage.py shell之后,当我尝试使用GDAL接口创建一个使用django.contrib.gis.gdal.DataSource的数据源时,它将首先抛出一个错误,然后第二次尝试将成功。
from django.contrib.gis.gdal import DataSource
shp = 'someshapefile.shp'
ds = DataSource(shp)这将引发代码字符串随时间变化的GDALException: : Unknown error code: "-474873798"。
但是当重试时:ds = DataSource(shp)数据源对象被实例化。
类似的问题也发生在ogrinspect命令和通过LayerMapping对象加载数据上。
以下是完整的错误提示:
from django.contrib.gis.gdal import DataSource
shp = 'province.shp'
DataSource(shp)
GDALException Traceback (most recent call last)
<ipython-input-3-c4eb8c662773> in <module>()
----> 1 DataSource(shp)
//anaconda/lib/python3.5/site-packages/django/contrib/gis/gdal/datasource.py in __init__(self, ds_input, ds_driver, write, encoding)
62 self.encoding = encoding
63
---> 64 Driver.ensure_registered()
65
66 if isinstance(ds_input, six.string_types):
//anaconda/lib/python3.5/site-packages/django/contrib/gis/gdal/driver.py in ensure_registered(cls)
81 if not cls.driver_count():
82 vcapi.register_all()
---> 83 rcapi.register_all()
84
85 @classmethod
//anaconda/lib/python3.5/site-packages/django/contrib/gis/gdal/prototypes/errcheck.py in check_errcode(result, func, cargs, cpl)
117 Check the error code returned (c_int).
118 """
--> 119 check_err(result, cpl=cpl)
120
121
//anaconda/lib/python3.5/site-packages/django/contrib/gis/gdal/error.py in check_err(code, cpl)
72 raise e(msg)
73 else:
---> 74 raise GDALException('Unknown error code: "%s"' % code)
GDALException: Unknown error code: "-474873798"
DataSource(shp)
<django.contrib.gis.gdal.datasource.DataSource at 0x10cd6f4a8>发布于 2017-03-19 23:32:26
我可以尝试导入gpx来复制此行为。调用DataSource = DataSource(gpx)两次会实例化datasource。
我希望暂时的解决方案是在我的应用程序中做到这一点:
try:
datasource = DataSource(gpx)
except:
datasource = DataSource(gpx)我filed a ticket为姜戈。
正因为如此,我的问题现在已经解决了。参见ticket comment。
https://stackoverflow.com/questions/41775536
复制相似问题