GeoDjango,什么SRID用于PointField与Google Maps V3 API接口? [英] GeoDjango, what SRID to use for PointField interfacing with Google Maps V3 API?

查看:177
本文介绍了GeoDjango,什么SRID用于PointField与Google Maps V3 API接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点困惑,应该在我的GeoDjango PointField中设置我的SRID值,以便通过谷歌地图API将地理编码的地址的上下文保留在通过django-postgis查询的坐标和距离中?



我得到混合的意见阅读网络和堆栈流的线程,我不确定该怎么做。正如你可以看到我的应用程序正在使用geopy与google maps api地理编码地址。现在我的坐标字段没有默认为4326的SRID集(EPSG:4326)。现在显然,这将地球视为地球,而不是平坦的表面。



根据以下问题的答案,谷歌地图使用的(EPSG 3857)显然SRID为900913。https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326 -for-googlemaps-openstreetmap-and-leaflet



这是否意味着我应该将SRID设置为900913?所有我的餐厅模型的坐标使用地理编码器以下面所示的相同方法进行保存。我会假设这样。



现在这是我被抛弃的地方,以下教程 http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html 使用一个点域,其SRID设置为4326(默认),并显示其标记点完美的谷歌地图。



目前我的查询是非常准确的,但仍然觉得似乎有点儿。



帮助感谢,谢谢!

 从geopy.geocoders导入GoogleV3 
从django.contrib.gis.geos import *
from django.contrib.gis.measure import D

geo = GoogleV3()
def home_page(request):
distance = 3680
地址,坐标= geo.geocode('Swanston Street,Melbourne Australia')
ref_location = Point(coordinates)
query = Restaurant.objects.filter(restaurant_location__distance_lte =(ref_location,D(m = distance)))distance (ref_loc atorder_by('distance')
return render(request,'swings / home.html',{'restaurants':query})

餐厅模型

  class Restaurant(models.Model):
name = models.CharField(max_length = 25,blank = False)
user = models.ForeignKey(User)
address = models.CharField(max_length = 50,blank = False)
restaurant_location = models.PointField(null = False,blank = False)
objects = models.GeoManager()

def __str __(self):
return self.name


解决方案

您应该使用4326(这意味着纬度和经度,使用WGS84基准和球体来模拟全球的形状),以向Google地图添加分数。在全球范围内记录您的位置的GPS等设备将保存4326中的数据,然后将其在Google Maps内部投影到3857(以米为单位)。如果您查看加载GeoJSON 的示例,您将看到点数在4326。



900913(这只是GOOGLE在计算器写作中)引起了很多混乱,并且源自于最初的EPSG对他们所关心的内容非常嗅闻作为一个不准确的预测,主要是因为它假设世界是一个球体。由于Google在全球的突出地位和数学易处理性,它变得流行起来。随后,EPSG给了一个新的官方名称3857(技术上也有另一个,3587,只是为了引起更多的混乱)。所以,虽然人们还在谈论900913,但官方你应该使用3587.3587以米为单位,用于生成在Google地图中显示的图块,但不应该用于添加点源,您绝对希望使用4326 。



如果您想了解更多有关此历史记录的信息,请参阅这篇文章: http://alastaira.wordpress.com/2011/01/23/the-google-maps -bing-maps-spherical-mercator-projection /


I am a bit confused, what should I set my SRID value to in my GeoDjango PointField to stay accurate in the context of addresses being geocoded via google maps api into coordinates and distances being queried via django-postgis?

Im getting mixed opinions reading the threads around the net and stackover flow and am unsure what to do. As you can see my application is using geopy with google maps api to geocode an address. Right now my coordinates field doesn't have an SRID set which defaults to 4326 which is (EPSG: 4326). Now apparently this sees the earth as a globe, not a flat surface.

According to the answer in the following question things such as google maps use (EPSG 3857) which apparently has an SRID of 900913. https://gis.stackexchange.com/questions/48949/epsg-3857-or-4326-for-googlemaps-openstreetmap-and-leaflet

So does this mean I should set my SRID to 900913? All my restaurant model's coordinates are saved in the same method seen below using the geocoder. I would assume so.

Now this is where I get thrown off, the following tutorial http://invisibleroads.com/tutorials/geodjango-googlemaps-build.html uses a pointfield with their SRID set to 4326 (default) and their marker points appear perfectly on google maps.

Currently my queries are decently accurate but still feels seems a bit off.

Help is appreciated, thanks!

from geopy.geocoders import GoogleV3
from django.contrib.gis.geos import *
from django.contrib.gis.measure import D

geo = GoogleV3()
def home_page(request):
distance = 3680
address, coordinates = geo.geocode('Swanston Street, Melbourne Australia')
ref_location = Point(coordinates)
query = Restaurant.objects.filter(restaurant_location__distance_lte=(ref_location, D(m=distance))).distance(ref_location).order_by('distance')
    return render(request, 'swings/home.html', {'restaurants': query})

Restaurant Model

class Restaurant(models.Model):
    name = models.CharField(max_length=25, blank=False)
    user = models.ForeignKey(User)
    address = models.CharField(max_length=50, blank=False)
    restaurant_location = models.PointField(null=False, blank=False)
    objects = models.GeoManager()

    def __str__(self):
        return self.name

解决方案

You should use 4326 (which means latitude and longitude, using the WGS84 datum and spheroid to model the globe's shape) to add points to Google Maps. Devices, such as GPS, which record your position on the globe, will save data in 4326, which will then be projected internally within Google Maps to 3857 (which is in meters). If you look at the example for loading GeoJSON you will see that the points are in 4326.

900913 (which is just GOOGLE in calculator writing) has caused a lot of confusion and arose out of the fact that initially the EPSG was very sniffy about what they regard as an inaccurate projection, mostly because it assumes the world to be a sphere. It became popular anyway because of Google's global prominence and for its mathematical tractability. Subsequently, the EPSG gave it a new official designation of 3857 (well technically there was another one too, 3587, just to cause yet more confusion). So, while people still talk about 900913, officially you should use 3587. 3587 is projected in meters and used to generate tiles for display in Google Maps, but should not be used to add point sources to it, where you definitely want to use 4326.

There is a good article here if you want to know any more about the history of this: http://alastaira.wordpress.com/2011/01/23/the-google-maps-bing-maps-spherical-mercator-projection/

这篇关于GeoDjango,什么SRID用于PointField与Google Maps V3 API接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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