Django:GeoDjango是否适合我的网站? [英] Django : is GeoDjango a Good Fit for my Website?

查看:132
本文介绍了Django:GeoDjango是否适合我的网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Django建立一个房地产网站,并拥有一个Home模式,它存储各种信息,包括地址。数据库后端正在使用MySQL。



想要像搜索一样创建一个 Yelp




  • 搜索用户可以输入邮政编码或城市名称,然后在该区域获取首页搜索结果。


  • 用户还可以从中选择半径(5 mi,10 mi ...),获得更多/更少的结果。


  • 搜索结果将在谷歌地图上,用户可以放大/缩小地图中的新搜索结果。




Geo Django 在这里很适合吗?猜猜没有太多的人使用GeoDjango,因为我找不到很多文档来解决上面提到的问题。



查看官方文档几个小时,我无法真正找到我的问题的相关示例,不知道如何使用MySQL与现有网站集成。也许太复杂了我的简单的位置使用?



如果Geo Django是一个很好的合适,我真的很好奇,如果是这样,那我会更积极地研究深深地如果没有,我会尝试自行构建它。



GeoDjango的任何指导或提示或如何构建系统将是非常有帮助的,将不胜感激

解决方案

GeoDjango可以处理这样的事情。假设您的首页模型如下所示:

  from django.contrib。 gis.db.models import PointField 

class Home(Model):
location = PointField()
.. etc
pre>

您可以在这样一个点的x英里内获取所有首页模型:

$ b django.contrib.gis.geos导入点
$ b

 从django.contrib.gis.measure导入D 
导入点

Home.objects.filter(location__distance_lte =(Point([...]),D(mi = x)))

基本上,您需要提供给过滤器的是一个包含几何的元组(在您的情况下为 Point )和距离( D 对象。您有大量单位来表示距离,在您的情况下 mi )。



此外,这在MySQL中不起作用,因为没有后端功能来处理它。你最好的选择是PostgreSQL。


I'm building a real estate site in Django and have a Home model, which stores various information including the address. Database backend is using MySQL.

Want to create a Yelp like search.

  • A search where users can enter in zip code or city name, then get Home results in that area.

  • Users can also choose the radius(5 mi, 10 mi...) from the point and get more/less results.

  • Search results will be on google map and users can zoom in/out to get new search results within the map.

Is Geo Django a good fit here? Guessing not too many people use GeoDjango, because I can't find many docs to solve problems mentioned above.

After looking at its official doc for about couple hours, I can't really find relevant example for my problems and not sure how well it integrates with existing website using MySQL. Maybe too sophisticated for my simple location usage?

I'm really curious if Geo Django is a good fit, if so..then I'll look into it more aggressively and deeply. If not, I'll try to build it on my own.

Any guidance or tips on GeoDjango or on how to build the system would be very helpful and will be appreciated so much.

解决方案

GeoDjango could handle something like that. Supposing your Home model looks like this:

from django.contrib.gis.db.models import PointField

class Home(Model):
    location = PointField()
    .. etc

You could fetch all Home models within x miles of a point like this:

from django.contrib.gis.measure import D
from django.contrib.gis.geos import Point

Home.objects.filter(location__distance_lte=(Point([...]), D(mi=x)))

Basically, what you need to give to the filter is a tuple containing a Geometry (Point in your case), and the distance(with the D object. You have a large range of units to represent the distance, in your case mi).

Also, this won't work in MySQL because there is no backend function to handle it. Your best bet is PostgreSQL.

这篇关于Django:GeoDjango是否适合我的网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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