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.
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 :)
Related
I am looking for a simple way to create geographical maps in Django, in which I could then select, highlight and annotate countries or groups thereof.
"Annotate": insert a label displaying textual information about the said country.
Is there anything that comes to mind?
Many thanks
EDIT: I checked GeoDjango already and it looks like much work in order to get where I need to. Don't get me wrong: I'm not trying to minimize my own investment in learning new tools, but for this project, I have a trade-off between time allocated to learning and the relative importance of this geographical feature in my app. It's more of a nice-to-have feature I'd like to add to an already 'complete' app. So I wondered whether there exists a 'simpler' python library for this task.
I think this is more of a question for if there is a front-end library to elegantly handle this. However if you need to generate the maps you could try something like this
https://kartograph.org/
I have personally used this http://jvectormap.com/ and found it to be really good.
In your database you could just have a Countries model with any associated information you might need to display, and create a view to handle that appropriately.
I'm build a Django app with Neo4j (along with Postgres), I found this Django integration called neo4django, I was wondering if it's possible to use neo4restclient only, like, what would be the disadvantages of not using Neo4django? Does using neo4-rest-client only, give me more flexibility?
When I was creating my models with Neo4Django, it seemed that there is no difference between modeling a graph db and relational db. Am I missing anything?
Thanks!
You can absolutely go ahead with neo4j-rest-client or py2neo, without using neo4django. In the same way, you can use any other database driver you'd like any time using Django, any REST client, etc.
What'll you lose? The model DSL, the built-in querying (eg, Person.objects.filter(name="Mohamed")), the built-in indexing, and the Lucene, Gremlin and Cypher behind that. Some things will be much easier- like setting an arbitrary property on a node- but you'll need to learn more about how Neo4j works.
You'll also lose some of the shortcuts Django provides that work with neo4django, like get_object_or_404() and some of the class-based views that work with querysets.
What'll you gain? Absolute power over the DB, and an easier time tweaking DB performance. Though neo4django isn't nearly as good a lib as some traditional ORMs in the Python sphere, the trade-off of power vs provided ease is similar.
That said, the two can work together- you can drop down from neo4django to the underlying REST client nodes and relationships anytime. Just use model_instance.node to get the underlying neo4j-rest-client node object from a model, and from neo4django.db import connection to get a wrapped neo4j-rest-client GraphDatabase.
On whether you're missing something: neo4django was written to re-use a powerful developer interface- the Django ORM- so it should feel similar to writing models for Postgres. I've written a bit about that odd feeling in the past. I think part of the problem might be that the lib doesn't highlight the graph terminology new graph-interested devs expect- like traversals and pattern matching- and instead dresses those techniques in Django query clothing.
I'd love your thoughts, or to know anything you'd like the library to do that it isn't doing :) Good luck!
I'm currently building my first Django-based app, which is proceeding
fairly well, thus far. One of the goals is to allow users to post
information (text, pics, video) and for the app to be able to
automatically detect the location where they posted this information
(i.e., pulling location info from the browser). That data would then ideally
be able to be filtered later, such as viewing the posts that were made within
a specific radius.
I've been reading a bit about GeoDjango and it sounds intriguing,
if perhaps more sophisticated than the requirements of this project.The querying aspects appear promising.
A colleague, though, suggested everything that can be done using
GeoDjango is equally efficient utilizing the Google Maps API with
JavaScript or JQuery to obtain the proper coordinates.
Essentially, I'm looking to see what benefits GeoDjango would offer
this fairly straightforward project over using just the Google Maps API. If I've already
started a project in basic Django; is incorporating GeoDjango
problematic? I'm still attempting to master the basics of Django and
venturing into GeoDjango may be too much for a novice developer. Or not.
Any insight appreciated.
To accurately find geolocated posts within a given radius of a location, you need to calculate distances between geographic locations. The calculations are not trivial. To quote the Django docs (with a minor grammatical correction):
Distance calculations with spatial data are tricky because,
unfortunately, the Earth is not flat.
Fortunately using GeoDjango hides this complexity. Distance queries are as simple as the following:
qs = SouthTexasCity.objects.filter(point__distance_lte=(pnt, 7000))
Although one could program this logic using JavaScript/JQuery, I don't see a reason to because you are already using Django. Unless if you are:
unable to use a spatial database. GeoDjango distance queries are only available if you use PostGIS, Oracle, or SpatiaLite as your database. (i.e. MySQL does not support distance queries)
unable to install the geospatial libraries that GeoDjango depends on.
I am developing a gis application using Google maps API. Currently I am using Postgis db.
I am considering switching to mongodb and I have following questions about this,
Is mongodb a viable choice for storing GIS data. ( Is any other NoSQL engine viable?)
Does django-nonrel has modified django.contrib.gis module for mongodb support? and how well does it work?
Thanks in advance :)
As stated by Sergio Tulentsev, MongoDB has spatial indexes. But, not all geometry types can be stored. As far as I know, currently only points can be stored. You can, however, query using a polygon.
Since MongoDB is very flexible, you could store geometry as a text, but also as a JSON object. For example, you could store a coordinate like: { lon: 52.1234, lat: 14.1245 }. You can interpret this is on your own application as you like.
The downside to this is that there is no native index. If you never have to query based on location/spatial relation, you are fine. If you do have query based on location/spatial relation, you would have to write your own index. Can be a hard thing do...
There is CouchDB which has a GeoSpatial addition. Don't know how it works/what it supports though.
A hybrid approach is also often taken by some large-data-based companies. For example, use MongoDB to store/query normal data, and PostGIS to store/query geospatial data.
Django MongoDB Engine developer here.
We haven't got any sort of real support for MongoDB's GIS features. It's possible to do geospatial queries by "working around Django" though (see http://django-mongodb.org/topics/lowerlevel.html - the first example is actually about Geo indexes).
It should be possible, however, to implement native Django GIS support into the MongoDB backend. We're really happy to mentor anyone who wants to approach that task!
I've been working with MongoDb storing points of interest in the DB, then doing point in poly queries, along with radius queries and Mongo has been FAR superior to PostGres. I've had much faster response times with hundreds of thousands of items.
I would say however depending on the complexity of your queries (ie if you're doing something beyond point in poly, radius around a point), you might want a more heavy GIS db like postgres.. you're just going to get the extra weight of postgres as well.
Sorry I can't speak to anything on django as well.
I'm trying to solve the relational model in order to make a Django app.
I't will be something like a McDonald's crew scheduler. I mean the grid with colored pins marking who will be working at a given hour a given weekday.
I did try to Google out some example, but I didn't find anything. I need some theory/bibliography in order to build up my model and code it into my app.
Thanks in advance
From the short description, you probably wouldn't have just one model in your app.
From your question I'm assuming you don't have a lot of experience with databases... Here are a few suggestions:
Start here because if you don't understand the basic principles of database design, foreign keys, one-to-one, one-to-many, many-to-many, etc etc etc; you will have a hard time designing your Django models.
It would be nice to learn SQL too. Django models are supposed to insulate you from it, but in reality it is using SQL underneath and knowing SQL will enable you to check and fix performance issues in the future. There are some resources online too. And if you are using SQLite, learn its syntax too.
The above is stuff that you will be able to reuse regardless of the web framework you end up with. Django, Rails, the next big thing... whatever.
Study other people's data models. Here are several different ones - maybe you can find the one you are looking for (employee shifts? shift scheduling?).
Then read the basic django model documentation and really understand it. What django models are doing is mapping python objects to relational database tables (ORM is the acronym; Object Relational Mapping) and this article may very well help you in coming up with good designs.
Don't get discouraged. Everybody had to start somewhere.
Hope you find all you need. Have fun with Django.