运行的 Django 应用程序通过 django-geojson 在其中一个模型中存储了 GeoJSON 数据。 .在管理界面中,此字段可通过 django-leaflet 进行编辑.当我使用 ./manage.py runserver
在本地运行应用程序时,界面运行正常,页面是这样的。
但是,当我部署到构建良好的 Heroku 并在管理界面中打开相同的 Location 实例时,蓝色标记不在 map 上的任何位置, map 正常加载,并且我收到此错误消息:
Error creating geometry from value '{
"coordinates":[
"-105.2449000",
"40.0474000"
],
"type":"Point"
}' (Initializing geometry from JSON input requires GDAL.)
我只是在
models.py
中记录简单的 Point 数据from djgeojson.fields import PointField
from django.db import models
class Location(models.Model):
"""
A model subclass for recording geographic data.
"""
service_id = models.CharField(max_length=255, blank=True, null=True)
name = models.CharField(max_length=255, blank=True, null=True)
geom = PointField() # GeoJSON (remember, coordinates: [long, lat])
def __str__(self):
return self.name
这是我第一次使用 geoJson、Leaflet 和 Heroku。我是否缺少一些依赖项,是否有一些我忽略的 Heroku 配置?这是我的
requirements.txt
.dj-database-url==0.4.1
Django==1.10
django-filter==0.13.0
django-geojson==2.9.0
django-leaflet==0.18.1
gunicorn==19.6.0
httplib2==0.9.2
jsonfield==1.0.3
oauth2==1.9.0.post1
oauthlib==1.1.2
psycopg2==2.6.2
PyJWT==1.4.1
python-openid==2.2.5
requests==2.10.0
requests-oauthlib==0.6.2
six==1.10.0
wheel==0.24.0
whitenoise==3.2
最佳答案
Heroku 目前正在运行 heroku-18 堆栈,对于 python 项目,默认构建包具有地理空间库 https://github.com/heroku/heroku-buildpack-python
要使用它们运行 heroku config:set BUILD_WITH_GEO_LIBRARIES=1
并添加
GDAL_LIBRARY_PATH = os.environ.get('GDAL_LIBRARY_PATH')
GEOS_LIBRARY_PATH = os.environ.get('GEOS_LIBRARY_PATH')
至
settings.py
.另见 https://github.com/heroku/heroku-buildpack-python/issues/752
关于heroku - Heroku 上缺少 GDAL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39027688/