> > (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 -~----------~----~----~----~------~----~------~--~---