Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6196767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:42:04+00:00 2026-05-24T03:42:04+00:00

I just got GeoDjango up and running on my development machine. Problem is that

  • 0

I just got GeoDjango up and running on my development machine. Problem is that I can’t get a distance query to work correctly. No matter what SRID I use, the distance results are totally off. Here’s an example.

>>> from django.contrib.gis.measure import D
>>> from app.models import Place
>>> from django.contrib.gis.geos import Point
>>> qs = Place.objects.all()
>>> point = Point(-118, 34)
>>> qs.filter(coordinates__distance_lte=(point, D(m=1)))
[<Place: 7-Eleven>, <Place: Arthur Murray Dance Studio>, <Place: Costco>, <Place: AMC Century City 15>, <Place: 24 Hour Fitness>, <Place: Ralphs>, <Place: Houston's Restaurant>, <Place: CVS/pharmacy>, <Place: Shaky Alibi>, <Place: Sephora>, <Place: Trader Joe's>]

The problem is that these places are much further than 1m away from point.

I tried playing around with it, but haven’t had much luck. Here’s an example with another SRID.

>>> qs = Place.objects.all().transform(3786)
>>> point = Point(-118, 34, srid=3786)
>>> qs.filter(coordinates__distance_lte=(point, D(m=1)))
[<Place: 7-Eleven>, <Place: Arthur Murray Dance Studio>, <Place: Costco>, <Place: AMC Century City 15>, <Place: 24 Hour Fitness>, <Place: Ralphs>, <Place: Houston's Restaurant>, <Place: CVS/pharmacy>, <Place: Shaky Alibi>, <Place: Sephora>, <Place: Trader Joe's>]

I have a feeling I’m just choosing the wrong SRIDs, but not a single one that I’ve run into online has worked, or given any response that is even moderately useful.

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:42:04+00:00Added an answer on May 24, 2026 at 3:42 am

    I hate to be answering my own question, but no one else stepped up to the plate and I figured out the solution.

    I delved into PostGIS to isolate the issue to either the location database itself or to Django. So I converted the Django ORM query I had been using above into the ideal query that I would have expected the PostGIS backend to receive. To my surprise, the query that was being produced was equivalent to:

    SELECT id
    FROM app_place
    WHERE ST_DWithin(coordinates, ST_SetSRID(ST_Point(-118, 34), 3768), 1);
    

    That was the problem right there. The query I needed was:

    SELECT id
    FROM app_place
    WHERE ST_Distance_Sphere(ST_SetSRID(ST_Point(-118, 34), 3768), coordinates) < 1;
    

    I read through the Django source to figure out what was happening here, and I realized that I had set geography=True on my coordinates field. Apparently, this changes the PostGIS functions Django generates when creating the SQL query. It’s undocumented, but here is the relevant section.

    In short, if you’re having this issue, remove geography=True from your model and you should be good to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just got Delphi 2009 and have previously read some articles about modifications that
I've got geodjango running using openlayers and OpenStreetMaps with the admin app. Now I
I just got a script to work by changing $('#thisElement').show(); to $('#thisElement').css({'display':'block'}); where #thisElement
i Just got the book Linux Kernel Development by Robert Love . It has
I just got some space on a VPS server(running on ubuntu 8.04), and I'm
Just got a request from my boss for an application I'm working on. Basically
Just got a question about generics, why doesn't this compile when using a generic
I just got a dedicated server from a hosting company, and for some reason,
I just got through manually removing the bin\ and obj\ folders from around 30
I just got a shiny, brand-new Debian server handed to me by our Systems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.