geodjango

How do I get the k nearest neighbors for geodjango?

老子叫甜甜 提交于 2021-01-24 09:21:31
问题 Assume that I have the following model: class Person: id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=150) location = models.PointField() How would I go by obtaining the k nearest neighbors (KNN) by location using geodjango? Would I have to write custom SQL for that? I am using PostgreSQL with PostGIS. 回答1: You can use a raw() sql query to utilize postgis order_by operators: <-> which gets the nearest neighbor using the centers of the bounding boxes to calculate

How do I get the k nearest neighbors for geodjango?

别等时光非礼了梦想. 提交于 2021-01-24 09:20:40
问题 Assume that I have the following model: class Person: id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=150) location = models.PointField() How would I go by obtaining the k nearest neighbors (KNN) by location using geodjango? Would I have to write custom SQL for that? I am using PostgreSQL with PostGIS. 回答1: You can use a raw() sql query to utilize postgis order_by operators: <-> which gets the nearest neighbor using the centers of the bounding boxes to calculate

How do I get the k nearest neighbors for geodjango?

自古美人都是妖i 提交于 2021-01-24 09:18:51
问题 Assume that I have the following model: class Person: id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=150) location = models.PointField() How would I go by obtaining the k nearest neighbors (KNN) by location using geodjango? Would I have to write custom SQL for that? I am using PostgreSQL with PostGIS. 回答1: You can use a raw() sql query to utilize postgis order_by operators: <-> which gets the nearest neighbor using the centers of the bounding boxes to calculate

How can I flatten a foreignkey object with django-rest-framework-(gis)

血红的双手。 提交于 2021-01-02 06:34:41
问题 I have searched long and far for a solution that is up to date and specific to my problem but have yet not found a solution or a clear documentation on what I really need to do in order to flatten a relationship to become geojson compliant. This question is almost identical to mine, however the solutions or answers does not solve the problem and still produces invalid GeoJSON. django-rest-framework-gis related field Related Set serializer geo_field as PointField from another model - Django

GeoDjango: Distance Object is not serializable

安稳与你 提交于 2020-08-08 06:09:11
问题 I am just learning the geo-django. I can find out the distance of all places from a point. But when I use .values method to the annotated distance field, I am getting TypeError: Object of type 'Distance' is not JSON serializable Here is my code snippets #models.py import uuid from django.contrib.gis.db import models from django.contrib.gis.db.models.functions import Distance from django.contrib.gis.geos import Point class PlaceManager(models.GeoManager): def get_queryset(self): qs = super

Which Model Field to use in Django to store longitude and latitude values?

扶醉桌前 提交于 2020-07-31 09:40:12
问题 I want to store my users location using longitude and latitude, at the moment this comes from Google Maps, but I will be using GeoDango and some point to work out distances between to points also. However, my first confusion is which field in Django I should be using to store the longitude and latitude values? The information I'm getting is conflicting. The official documentation uses a FloatField https://docs.djangoproject.com/en/dev/ref/contrib/gis/tutorial/#geographic-models lon = models

Django : how to use multiple databases?

一个人想着一个人 提交于 2020-07-09 14:35:24
问题 I'm building a website with Django and I need to have a GPS coordinate attribute in my User model. I will be using GeoDjango, which needs PostgreSQL and, since my website is already working with the sqlite3 default database, I need to install a PostgreSQL database to the project in order to create a Coordinates model in it and link it to the User model of the SQLite database. I found lots of tutorials on the internet about "how to use multiple databases" but they are all very basics. Since I

Django : how to use multiple databases?

不打扰是莪最后的温柔 提交于 2020-07-09 14:34:09
问题 I'm building a website with Django and I need to have a GPS coordinate attribute in my User model. I will be using GeoDjango, which needs PostgreSQL and, since my website is already working with the sqlite3 default database, I need to install a PostgreSQL database to the project in order to create a Coordinates model in it and link it to the User model of the SQLite database. I found lots of tutorials on the internet about "how to use multiple databases" but they are all very basics. Since I

Django filter location distance with dynamic radius

久未见 提交于 2020-06-30 23:57:27
问题 I have 2 model in django a zone and a shop, models are like this: from django.contrib.gis.db import models from django.contrib.gis.geos import Point from django.contrib.gis.measure import D from location_field.models.spatial import LocationField class Zone(models.Model): name = models.CharField(max_length=200) location_point = LocationField(based_fields=['city'], zoom=7, default=Point(51.67, 32.65)) radius = models.IntegerField(default=1000) # radius in meters class Shop(models.Model): name =