user2552806
user2552806

Reputation:

Django point distance in given circle

I have Django 1.7 with PostgreSQL 9.3 behind.

I want to store a model with geometrical field circle and be able to get true or false if a given point is within the stored geometrical circle. I found that question and that library and also this option, so I got lost...

What is the right and simpler way to do it, is it better to save a point and a radius and then calculate it (so I need to install the django-postgres-geometry?), or should I update Django and PostgreSQL?

Upvotes: 3

Views: 410

Answers (1)

djq
djq

Reputation: 15286

You will need the PostGIS extension installed into PostgreSQL to achieve this. This is what Django and Postgres use for spatial calculations.

To check if a point is in a circle you can do the following in the Django shell:

   from django.contrib.gis.geos import Point
   point = Point(45.3, 34.2, srid=4326) # lon, lat

   # check if point in polygon
   mypoly.contains(point) # this returns True/False

Upvotes: 1

Related Questions