Django : is GeoDjango a Good Fit for my Website?

谁都会走 提交于 2019-12-04 14:55:10

问题


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.


回答1:


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.




回答2:


I built a site on Django with similar features (MySQL database full of addresses and lat/long coordinates). I talked with cohorts that are more familiar with Django and GeoDjango and they recommended that it might be a bit overkill for my project.

So if migrating the database is a huge pain and not necessary, it seems you may be well off just sticking to your current database and just using a Haversine formula query to find closest points to a location.




回答3:


GeoDjango makes a lot of sense if you're already using Django. However, you should also consider using Lucene for your use case. It can handle geographical queries, and probably performs better than mysql queries if you need to do multi-faceted queries and fuzzy search (something I would want to use on a site with a lot of homes).




回答4:


GeoDjango works but it is very hard to install for novice user. Also GeoDjango has some limitations on MySQL. As I know it shows the best on the postgresql.

What exactly problem do you experience in geodjango installation?

I've wasted about 10-20 hours before I began understand the geodjango installation process :)



来源:https://stackoverflow.com/questions/6229827/django-is-geodjango-a-good-fit-for-my-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!