【问题标题】:Why django geo map not working correctly?为什么 django 地理地图无法正常工作?
【发布时间】:2021-04-04 10:35:27
【问题描述】:

我已经安装了 django、postgresql、postgis、Qgis 和 GDAL

这样的地图显示。

地图上无任何显示

如何解决 geoDjango 问题?

在models.py:

from django.contrib.gis.db import models

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

在setting.py:

INSTALLED_APPS = [ 
     'django.contrib.gis',   # geo,
     'geoshops',    # user apps
     
          ]
try:
    import gdal
    gdal_path = Path(gdal.__file__)
    OSGEO4W = os.path.join(gdal_path.parent, 'osgeo')
    os.environ["OSGEO4W_ROOT"] = OSGEO4W
    os.environ["GDAL_DATA"] = os.path.join(OSGEO4W, "data", "gdal")
    os.environ["PROJ_LIB"] = os.path.join(OSGEO4W, "data", "proj")
    os.environ["PATH"] = OSGEO4W + ";" + os.environ["PATH"]
    GEOS_LIBRARY_PATH = str(os.path.join(OSGEO4W, "geos_c.dll"))
    GDAL_LIBRARY_PATH = str(os.path.join(OSGEO4W, "gdal301.dll"))
except ImportError:
    GEOS_LIBRARY_PATH = None
    GDAL_LIBRARY_PATH = None

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']

【问题讨论】:

  • 看起来location 字段的小部件已加载,但地图的实际图块并未加载。你能分享你如何在管理员中注册你的模型吗?还值得检查浏览器控制台中是否有任何 JS 错误。
  • @rootart。没有 JS 错误。 # 将“Shop”模型注册到管理员 ===> admin.site.register(Shop)
  • 您可以尝试使用OSMGeoAdmin 类和自定义ShopAdmin 并使用它进一步注册模型。 ``` 类 ShopAdmin(OSMGeoAdmin): 传递 admin.site.register(Shop, ShopAdmin) ```

标签: python django postgresql postgis qgis


【解决方案1】:

你需要安装“django-geoposition-2”。

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2022-01-18
  • 1970-01-01
  • 1970-01-01
  • 2021-02-04
  • 2016-09-28
  • 1970-01-01
  • 2015-05-13
  • 1970-01-01
相关资源
最近更新 更多