Django - determine if geographic coordinates are inside a circle

Does django have anything that will look at the geographic coordinate (decimal lat / long) and determine if it is inside a circle with a certain radius (say 100 km)?

I have a specific data type, each has lat / long, and I would like to search the database to see if that data is inside a circle with a specified radius size.

I could probably write something myself that would handle it, but I wander if there is already something written that will handle it.

+3
source share
1 answer

This problem can be solved in pure SQL, if you do not mind very good accuracy.

GPS SQL:

# find point around :
latitude = 46.2037010192871
longitude = 5.20353984832764
query= "SELECT ID, NOM, LAT, LON, 3956 * 2 * ASIN(SQRT(POWER(SIN((%s - LAT) * 0.0174532925 / 2), 2) + COS(%s * 0.0174532925) * COS(LAT * 0.0174532925) * POWER(SIN((%s - LON) * 0.0174532925 / 2), 2) )) as distance from POI  having distance < 50 ORDER BY distance ASC " % ( latitude, latitude, longitude)

gps 50 .

django :

from django.db import connection
cursor = connection.cursor()
cursor.execute( query )
rows = cursor.fetchall()

django

+12

Source: https://habr.com/ru/post/1783766/


All Articles