Hi,
I had problem with the query:
JobOffer.objects.filter(
location__distance_lte=(
current_location,
D(km=radius))
)
because it returned everything.
when I looked into SQL:
SELECT "joboffers_joboffer"."id", "joboffers_joboffer"."owner_name",
"joboffers_joboffer"."title", "joboffers_joboffer"."description",
"joboffers_joboffer"."date", "joboffers_joboffer"."starts",
"joboffers_joboffer"."salary_m", "joboffers_joboffer"."salary_h",
"joboffers_joboffer"."category", "joboffers_joboffer"."phone_number",
"joboffers_joboffer"."email", "joboffers_joboffer"."location" FROM
"joboffers_joboffer" WHERE ST_Distance("joboffers_joboffer"."location",
ST_GeomFromEWKB('\001\001\000\000
\346\020\000\000\000\000\000\000\000\000I@\000\000\000\000\000\000I@'::bytea
)) <= 1000.0
I looked into database and found that location is Geometry.
I looked into documentation for PostGIS and found that ST_Distance:
For geometry type returns the minimum 2D Cartesian distance between two
> geometries in projected units (spatial ref units). For geography type
> defaults to return the minimum geodesic distance between two geographies in
> meters. If use_spheroid is false, a faster sphere calculation is used
> instead of a spheroid.
So I removed geographic=True and get query:
SELECT "joboffers_joboffer"."id", "joboffers_joboffer"."owner_name",
"joboffers_joboffer"."title", "joboffers_joboffer"."description",
"joboffers_joboffer"."date", "joboffers_joboffer"."starts",
"joboffers_joboffer"."salary_m", "joboffers_joboffer"."salary_h",
"joboffers_joboffer"."category", "joboffers_joboffer"."phone_number",
"joboffers_joboffer"."email", "joboffers_joboffer"."location" FROM
"joboffers_joboffer" WHERE ST_Distance_Sphere("joboffers_joboffer".
"location", ST_GeomFromEWKB('\001\001\000\000
\346\020\000\000\000\000\000\000\000\000I@\000\000\000\000\000\000I@'::bytea
)) <= 1000.0
and everything started working fine.
>From django documenation:
> The geography type provides native support for spatial features
> represented with geographic coordinates (e.g., WGS84 longitude/latitude).
> [6]
> <https://docs.djangoproject.com/es/1.9/ref/contrib/gis/model-api/#fngeography>
> Unlike
> the plane used by a geometry type, the geography type uses a spherical
> representation of its data. Distance and measurement operations performed
> on a geography column automatically employ great circle arc calculations
> and return linear units. In other words, when ST_Distance is called on
> two geographies, a value in meters is returned (as opposed to degrees if
> called on a geometry column in WGS84).
*BUT POINT FIELD IS STILL GEOMETRY INSTEAD OF GEOGRAPHY*
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/6457b5ad-b32f-4ddb-b004-d7da5782fea4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.