Geodjango OGR故障问题-GDAL异常 [英] Issue with Geodjango OGR failure - GDAL Exception

查看:20
本文介绍了Geodjango OGR故障问题-GDAL异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功构建了Django中的模型,但一旦添加数据并单击保存我的应用程序就会崩溃

我得到GDAL异常-OGR失败,并且它在崩溃页面中突出显示为错误的原因{{field.field}}。 以下是屏幕截图Admin view for adding data to the model

i get this right away after clicking save

有人经历过这种情况吗?有帮助吗?

谢谢

更新: 我收到此错误:

[12/Apr/2019 14:38:46] "GET /static/admin/img/gis/move_vertex_off.svg HTTP/1.1"
200 1129
[12/Apr/2019 14:39:14] "GET /static/admin/img/gis/move_vertex_on.svg HTTP/1.1" 2
00 1129
GDAL_ERROR 4: b'Unable to open EPSG support file gcs.csv.
Try setting the GDAL_
DATA environment variable to point to the
directory containing EPSG csv files.'

Internal Server Error: /admin/trial2/shop/add/
Traceback (most recent call last):
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocore
handlersexception.py", line 34, in inner
    response = get_response(request)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocore
handlersase.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocore
handlersase.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibadminoptions.py", line 606, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoutils
decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoviews
decoratorscache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibadminsites.py", line 223, in inner
    return view(request, *args, **kwargs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibadminoptions.py", line 1634, in add_view
    return self.changeform_view(request, None, form_url, extra_context)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoutils
decorators.py", line 45, in _wrapper
    return bound_method(*args, **kwargs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoutils
decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibadminoptions.py", line 1522, in changeform_view
    return self._changeform_view(request, object_id, form_url, extra_context)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibadminoptions.py", line 1554, in _changeform_view
    form_validated = form.is_valid()
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoforms
forms.py", line 185, in is_valid
    return self.is_bound and not self.errors
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoforms
forms.py", line 180, in errors
    self.full_clean()
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoforms
forms.py", line 381, in full_clean
    self._clean_fields()
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangoforms
forms.py", line 399, in _clean_fields
    value = field.clean(value)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisformsfields.py", line 79, in clean
    geom.transform(self.srid)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisgeosgeometry.py", line 471, in transform
    g = gdal.OGRGeometry(self._ogr_ptr(), srid)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisgdalgeometries.py", line 115, in __init__
    self.srs = srs
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisgdalgeometries.py", line 284, in _set_srs
    sr = SpatialReference(srs)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisgdalsrs.py", line 92, in __init__
    self.import_epsg(srs_input)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisgdalsrs.py", line 277, in import_epsg
    capi.from_epsg(self.ptr, epsg)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisgdalprototypeserrcheck.py", line 118, in check_errcode
    check_err(result, cpl=cpl)
  File "C:UserslgcgeDocumentscopypostgisvenvlibsite-packagesdjangocontr
ibgisgdalerror.py", line 59, in check_err
    raise e(msg)
django.contrib.gis.gdal.error.GDALException: OGR failure.
[12/Apr/2019 14:39:45] "POST /admin/trial2/shop/add/ HTTP/1.1" 500 160518

admin.py:

from django import forms
from django.contrib.gis import admin

from django.contrib.gis.db import models



from django.contrib.gis.admin import OSMGeoAdmin
from .models import Shop

@admin.register(Shop)
class ShopAdmin(OSMGeoAdmin):
    list_display = ('name', 'location')

Model.py

from __future__ import unicode_literals

from django.contrib.gis.db import models
from django.contrib.gis.geos import Point


class Shop(models.Model):
    name = models.CharField(max_length=100)
    location = models.PointField()
    address = models.CharField(max_length=100)
    city = models.CharField(max_length=50)

推荐答案

抱歉复制/粘贴,仅对@kiwi的回答稍加修改。我尝试向原始答案添加注释,但无法添加格式化代码。

现在,您似乎不能再安装64位版本的OSGEO4W。我安装了唯一可用的here版本,并修改了@Kiwi的答案以反映64位的缺失。我使用的是Windows 10。以下操作系统都可以正常运行。

import platform
import environ

WINDOWS = platform.system() == "Windows"

if WINDOWS:
    # the below needs to change for linux
    GDAL_LIBRARY_PATH = r'C:OSGeo4Wingdal303.dll'
    GEOS_LIBRARY_PATH = r'C:OSGeo4Wingeos_c.dll'
    OSGEO4W = r"C:OSGeo4W"
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = "C:Program FilesGDALgdal-data"  # OSGEO4W + r"sharegdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"shareproj"
    os.environ['PATH'] = OSGEO4W + r"in;" + os.environ['PATH']

这篇关于Geodjango OGR故障问题-GDAL异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆