GeoDjango GDAL_ERROR 上传 .shp 时

GeoDjango GDAL_ERROR when uplading .shp

尝试在 django 中解析一个 .shp shell:

from django.contrib.gis.gdal import DataSource
ds = DataSource('/Users/.../Downloads/Iceland.shp')

得到:

GDAL_ERROR 4: Unable to open /Users/.../Downloads/Iceland.shx or /Users/.../Downloads/Iceland.SHX.

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/.../lib/python2.7/site-packages/django/contrib/gis/gdal/datasource.py", line 78, in __init__
    raise GDALException('Could not open the datasource at "%s"' % ds_input)
GDALException: Could not open the datasource at "/Users/.../Downloads/Iceland.shp"

文件存在,chmod为755,.shx文件正确(在线服务测试)。 然后我尝试测试 .kml 文件并且它有效

OS: Mac OS X 10.10.5

您缺少 "Iceland.shx" 文件。它应该与 Iceland.shp 在同一个存档中。放在同一个目录下就行了。我试过这个文件:http://www.eea.europa.eu/data-and-maps/data/eea-reference-grids-2/gis-files/iceland-shapefile 并发现了同样的错误。

如果没有帮助,还有一些其他选项可以调试:

  1. 检查强制性的 .shx、.shp 和 .dbf 文件是否在同一目录中。
  2. 检查没有其他程序打开(并锁定)shapefile。
  3. 打开 QGIS/ArcGIS 中的 shapefile 并验证几何。
  4. 尝试另一个 shapefile

我需要补充一点,我在尝试 运行 命令时遇到了同样的错误:

python manage.py ogrinspect /map/data/points.shp BuildingFootprints --srid=4326 --mapping --multi

而且这个错误是因为map前面有一个反斜杠,所以在我运行:

的时候就通过了
python manage.py ogrinspect map/data/points.shp BuildingFootprints --srid=4326 --mapping --multi

当我在寻找我的解决方案时,我发现了这个问题,它已得到解答。无论如何,我想 post 为那些像我几分钟前一样来到这里的人回答这个问题。也许有人帮忙。

python manage.py ogrinspect map/data/points.shp BuildingFootprints --srid=4326 --mapping --multi

确保您的数据位于文件夹中... map/data/points.shp BuildingFootprints