Re: GeoDjango: distance between PointFields problem

2008-04-24 Thread Nathaniel Whiteinge

On Apr 23, 9:23 am, Justin Bronn <[EMAIL PROTECTED]> wrote:
> > A PointField from that same model containing lat/long pairs obtained
> > from the Google geocoder.

Quick follow-up in case anyone else has a similar problem. The Google
geocoder annoyingly returns latitude and longitude as y/x instead of x/
y.
Not so obvious if you don't know lat/long very well.

Thanks, Justin, for pointing this out on IRC, and for all the other
helpful links.

- whiteinge
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: GeoDjango: distance between PointFields problem

2008-04-23 Thread Justin Bronn

 > > (1) What geographic fields are in your model, what type are they
> > (e.g., PointField, etc.), and their SRID.
>
> A plain PointField, e.g.: ``location = PointField()``. I 
> believeGeoDjangodefaults to WGS84 for the SRID.
>
> > (2) The geometry type of the parameter you're passing to `distance`,
> > and its SRID.
>
> A PointField from that same model containing lat/long pairs obtained
> from the Google geocoder.
>

OK, so my first guess at what's going on is incorrect.

You're calculating distances from one geodetic point to another --
this means that the units for both points are in degrees.  Typically,
the `distance` GeoQuerySet method returns values that are in the
coordinate system of the field (e.g., if my field is SRID=32140, then
the values returned are in meters because that is the unit used by the
coordinate system).  However, this is undesirable for geodetic
coordinate systems because distances in units of degrees depend on
your location -- for example, take a look at the spacing of longitude
lines on a globe they get closer together at the poles and are
farthest apart at the equator.  Having distances returned in degrees
is not optimal for humans who think in units of meters or miles which
stay the same no matter where you're at.

Thus, when using a geodetic coordinate system, such as WGS84 (the
default, aka SRID=4326), a spherical distance calculation method is
used instead which returns _meters_ (i.e., the PostGIS
`distance_spheroid` function is used instead of `distance`).  The
large values may be due to the fact that they are large values to
begin with -- it is ~2,029,313 meters from Chicago to Salt Lake City.
At some point I wish the distance values would be `Distance` objects
rather than number values, but at this point it would require a lot of
internal hacking on internal Django ORM components I'll put off to
another day.

Just to be clear, there is only one PointField in the model, right?  I
ask because GeoQuerySet methods operate, by default, on the first
geographic field encountered in the model -- if you have more than one
geographic field then you may have to explicitly specify it in the
first parameter (`qs = MyModel.objects.distance('point_field2',
pnt)`).

If you still think you're getting bogus values set up an example model
and data set that exhibit the problem so that I can examine more
closely.

> So now that you know more about my setup, how would I find the
> distance between two users in a model?

from django.contrib.gis.measure import D # `Distance` object.
qs = User.objects.distance(user1.point)
for u in qs:
print u, D(m=u.distance).mi # Printing out distance in miles.

> Do you know of any simple-language introductions to working with GIS?
> The best I've seen so far is the link below.

That's a good link.  Sticking with the projected vs. geographic topic,
here are some other good resources:

[1] "Map Projections", 
http://www.progonos.com/furuti/MapProj/CartIndex/cartIndex.html

[2] "Coordinate Systems: PROJ.4, EPSG and OGC WKT",
http://www.foss4g2006.org/contributionDisplay.py?contribId=139&sessionId=42&confId=1
Frank Warmerdam's FOSS4G 2006 presentation -- I can't recommend this
one highly enough.

[3] "The State Plane Coordinate System",
http://welcome.warnercnr.colostate.edu/class_info/nr502/lg3/datums_coordinates/spcs.html
Helps demystify state plane coordinate systems -- if working with US
data you'll encounter it one of these projections sooner or later.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: GeoDjango: distance between PointFields problem

2008-04-22 Thread Nathaniel Whiteinge

On Apr 22, 11:54 am, Justin Bronn <[EMAIL PROTECTED]> wrote:
> (1) What geographic fields are in your model, what type are they
> (e.g., PointField, etc.), and their SRID.

A plain PointField, e.g.: ``location = PointField()``. I believe
GeoDjango defaults to WGS84 for the SRID.

> (2) The geometry type of the parameter you're passing to `distance`,
> and its SRID.

A PointField from that same model containing lat/long pairs obtained
from the Google geocoder.

> My guess is that you're trying to calculate distances from a projected
> coordinate system to a geodetic point that is outside the valid range
> of your projection.

That sounds likely. I've done a bit of Googling for explanations for
the concepts and terms in use with GeoDjango, but I have a shaky
understanding, at best. Do you know of any simple-language
introductions to working with GIS? The best I've seen so far is the
link below.

So now that you know more about my setup, how would I find the
distance between two users in a model?

Thanks for your help so far, Justin.
- whiteinge


.. __:
http://www.sharpgis.net/post/2007/05/Spatial-references2c-coordinate-systems2c-projections2c-datums2c-ellipsoids-e28093-confusing.aspx
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: GeoDjango: distance between PointFields problem

2008-04-22 Thread Justin Bronn

> I'm calculating the distance between two plain PointFields in the GIS
> branch using the distance GeoQuerySet method [1] and I'm coming up
> with some confusing results.
>

I require more information before I can answer your inquiry:

(1) What geographic fields are in your model, what type are they
(e.g., PointField, etc.), and their SRID.
(2) The geometry type of the parameter you're passing to `distance`,
and its SRID.

> The distance between nearby things is often about right, maybe off by
> a mile or two. But the distance between farther locations is off by
> quite a bit. The distance between Salt Lake City and Chicago is
> reported as just over 10,000 miles, for example.

My guess is that you're trying to calculate distances from a projected
coordinate system to a geodetic point that is outside the valid range
of your projection.  For example, if I had a model in the projected
coordinate system of SRID=32140 (only valid for South Texas[1]), and I
attempted to calculate distances from my model to a WGS84 point
referencing Denver, CO (SRID=4326) then I would get garbage distances
returned because Denver is well outside the valid range for 32140.  If
I were to use a WGS84 point referencing San Antonio instead of Denver
valid results would be returned.

[1] http://spatialreference.org/ref/epsg/32140/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



GeoDjango: distance between PointFields problem

2008-04-22 Thread Nathaniel Whiteinge

I'm calculating the distance between two plain PointFields in the GIS
branch using the distance GeoQuerySet method [1] and I'm coming up
with some confusing results.

The distance between nearby things is often about right, maybe off by
a mile or two. But the distance between farther locations is off by
quite a bit. The distance between Salt Lake City and Chicago is
reported as just over 10,000 miles, for example.

I'm not sure how to go about troubleshooting this. Any advice would be
very much appreciated.
- whiteinge


.. [1] http://code.djangoproject.com/wiki/GeoDjangoDatabaseAPI#distance
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---