Django : is GeoDjango a Good Fit for my Website?

折月煮酒 提交于 2019-12-03 09:14:34

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.

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.

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).

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 :)

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