安装GeoDjango后,我想在管理面板中创建一个“位置”对象,该对象使用地图上的地址和点。提交表单后,我收到错误,如此...
GDALException at /admin/maps/location/add/
OGR failure.
我试过看类似的问题,like here,但没有一个解决方案有效。此外,搜索“无法加载PROJ.4库”(第一个追溯线)没有取得任何成功。
任何帮助,将不胜感激! - 如果我应该使用settings.py或其他相关文件更新此问题,请与我们联系。
完全追溯:
GDAL_ERROR 6: Unable to load PROJ.4 library (libproj.dylib), creation of OGRCoordinateTransformation failed.
Internal Server Error: /admin/maps/location/add/
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py", line 551, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py", line 57, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py", line 224, in inner
return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py", line 1508, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py", line 149, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py", line 1408, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py", line 1440, in _changeform_view
if form.is_valid():
File "/Library/Python/2.7/site-packages/django/forms/forms.py", line 183, in is_valid
return self.is_bound and not self.errors
File "/Library/Python/2.7/site-packages/django/forms/forms.py", line 175, in errors
self.full_clean()
File "/Library/Python/2.7/site-packages/django/forms/forms.py", line 384, in full_clean
self._clean_fields()
File "/Library/Python/2.7/site-packages/django/forms/forms.py", line 402, in _clean_fields
value = field.clean(value)
File "/Library/Python/2.7/site-packages/django/contrib/gis/forms/fields.py", line 75, in clean
geom.transform(self.srid)
File "/Library/Python/2.7/site-packages/django/contrib/gis/geos/geometry.py", line 527, in transform
g.transform(ct)
File "/Library/Python/2.7/site-packages/django/contrib/gis/gdal/geometries.py", line 408, in transform
capi.geom_transform_to(self.ptr, sr.ptr)
File "/Library/Python/2.7/site-packages/django/contrib/gis/gdal/prototypes/errcheck.py", line 119, in check_errcode
check_err(result, cpl=cpl)
File "/Library/Python/2.7/site-packages/django/contrib/gis/gdal/error.py", line 73, in check_err
raise e(msg)
GDALException: OGR failure.
编辑:为Location添加了我的models.py和admin.py
models.朋友:
from __future__ import unicode_literals
from django.contrib.gis.db import models
from django.contrib.gis.geos import Point
from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings
from . import utils
COUNTRIES=((0,'UK'),(1,'USA'),(2,'CA'),(3,'AUS'),(4,'JP'),(5,'FR'))
class Location(models.Model):
name=models.CharField(max_length=120,verbose_name='House name/number',blank=True)
first_addr=models.CharField(max_length=45,verbose_name='Address line 1',blank=False)
second_addr=models.CharField(max_length=45,verbose_name='Address line 2',blank=True)
town=models.CharField(max_length=45,verbose_name='Town/City',blank=False)
state=models.CharField(max_length=45,verbose_name='State/Province',blank=False)
zip_code=models.CharField(max_length=12,verbose_name='Postal/Zip Code',blank=False)
country=models.IntegerField(verbose_name='Country',blank=False,null=False,choices=COUNTRIES)
point=models.PointField(default='POINT (0 0)',srid=4326)
dt_created=models.DateTimeField(auto_now_add=True)
dt_updated=models.DateTimeField(auto_now=True)
class Meta:
verbose_name = 'Location'
def __unicode__(self):
return self.name
def __str__(self):
return self.name
@property
def longitude(self):
return self.point[0]
@property
def latitude(self):
return self.point[1]
admin.朋友:
from __future__ import unicode_literals
from django.contrib.gis import admin
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.auth.admin import UserAdmin
from maps.models import *
class LocationAdmin(admin.OSMGeoAdmin):
model = Location
list_display = ['name','first_addr','second_addr','town','state','zip_code','country','longitude','latitude','dt_created','dt_updated']
search_fields = ['first_addr','second_addr','town','state','zip_code']
admin.site.register(Location,LocationAdmin)
如果在setting.py文件的顶部添加以下命令,则会修复此错误
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']