【问题标题】:GeoDjango, Cordinates from Google maps are getting plotted wrong on leaflet using PointFieldGeoDjango,来自谷歌地图的坐标在使用 PointField 的传单上绘制错误
【发布时间】:2020-02-07 07:22:53
【问题描述】:

请帮我解决这个问题。

class RecievingImages(models.Model):
    """Original and Masked Images"""
    name          = models.CharField(max_length = 100, unique = True, primary_key=True)
    cordinate_X   = models.FloatField()
    cordinate_Y   = models.FloatField()
    point         = models.PointField(srid=4326, geography=True, default='POINT(0.0 0.0)')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name_plural = 'Image Mapping'



我有从谷歌地图 API 获得的坐标 此处示例

cordinate_X : 21.2166277
cordinate_Y : 72.7763859

从技术上讲,这些坐标位于印度古吉拉特邦 actual link of the coordinates

现在要在传单上绘图,我参考此链接将其转换为点字段 https://stackoverflow.com/a/48293443/7999665

from django.contrib.gis.geos import Point

for l in RecievingImages.objects.all():
...     l.point = Point(x=l.cordinate_X, y=l.cordinate_Y, srid=4326)
...     l.save()

现在,当我返回 Django 管理页面时,它在 Sea 的某处错误地标记了坐标

感谢您的宝贵时间。

问候


更新

经过大量谷歌搜索,我发现可能存在 srid 使用的问题,即谷歌地图可能使用“3587”而我使用了“4326” 我尝试更改此设置,但出现错误。

    raise NotSupportedError('PostGIS only supports geography columns with an SRID of 4326.')
django.db.utils.NotSupportedError: PostGIS only supports geography columns with an SRID of 4326.

我使用的数据库是PostGIS。

【问题讨论】:

    标签: django google-maps django-admin postgis geodjango


    【解决方案1】:

    我认为你的坐标被交换了。 X是经度,Y是纬度。

    您的链接在此处显示坐标: 21°12'59.9"N 72°46'35.0"E。 Google 将纬度放在首位。

    试试这个:

    cordinate_X : 72.7763859
    cordinate_Y : 21.2166277
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-23
      • 1970-01-01
      相关资源
      最近更新 更多