0

我正在使用 geo django 并在 Windows 上运行。我确实在设置中配置了 GDAL 和 OSGEOS。

这是我的 gdal 的 settings.py 代码。

   import os
    if os.name == 'nt':
        import platform
        OSGEO4W = r"C:\OSGeo4W"
        if '64' in platform.architecture()[0]:
            OSGEO4W += "64"
        assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
        os.environ['OSGEO4W_ROOT'] = OSGEO4W
        os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
        os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
        os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']

我有一个具有点场的模型。模型:

class Event(models.Model):
    user = models.ForeignKey(User, on_delete=models.SET, blank=True)
    name = models.CharField(max_length=100)
    category = models.ForeignKey(Category, on_delete=models.CASCADE)
    location = models.PointField(srid=4326, blank=True)

每当我尝试创建事件并设置点域值时,都会收到此错误:

GDAL_ERROR 6: b'Unable to load PROJ.4 library (proj.dll), creation of\nOGRCoordin
ateTransformation failed.'
Error transforming geometry from srid '4326' to srid '3857' (OGR failure.)

这个问题似乎是一个只有 Windows 的问题。当我在我的 virtualbox 上的 ubuntu 上运行此应用程序时,一切似乎都运行良好。

4

2 回答 2

0

尝试将此添加到设置文件

os.environ['GDAL_DATA'] = "C:\\OSGeo4W64\\share\\epsg_csv" <- (path to gcs.csv file)
于 2020-05-05T13:02:06.223 回答
0

不幸的是,我无法为 Windows 解决这个问题。我为绕过这个问题所做的就是使用 oracle virtualbox 在 Windows 上安装 ubuntu。

https://www.virtualbox.org/wiki/Downloads

于 2020-05-02T02:29:13.103 回答