Skip to content Skip to sidebar Skip to footer

Fastest Way To Get Nearest Geometry To A Point In Geodjango

I've got a large number of points (~1.5 million) in the WGS84 coordinate system. The points span a large area, so I can't use a projected coordinate system. I want to find the clos

Solution 1:

Not sure, this may be faster. You can use the google projection (900913) to get your data in meters.

from django.contrib.gis.measure import D

DISTANCE_LIMIT_METERS = 5000

input_point = Point(lon, lat, srid=4326)
input_point.transform(900913)
ModelContainingPoint.objects.filter(geom__dwithin=(input_point , D(m=DISTANCE_LIMIT_METERS)))

Reference:

https://docs.djangoproject.com/en/dev/ref/contrib/gis/db-api/#distance-queries

Post a Comment for "Fastest Way To Get Nearest Geometry To A Point In Geodjango"