[postgis-users] noob question
Brent Wood
pcreso at pcreso.com
Wed Jul 4 11:39:48 PDT 2007
--- Steve Lefevre <lawpoop at gmail.com> wrote:
> On 7/4/07, Brent Wood <pcreso at pcreso.com> wrote:
> >
> >
> > Hi Steve,
> >
> > Hope this helps...
> >
> > If I understand you correctly, this may be easier outside of PostGIS
> > geometries, try:
> >
> > select geometryfromtext(('POINT( avg(longitude) avge(latitude) ',4326)
> > group by ....
> >
> > Always assuming the avg() is a appropriate value to use for your purposes.
>
>
>
> I guess I was under the idea that avg() functions don't quite work in
> geography for latitude and longitude. Is this not the case?
The point at avg(X), avg(Y) of a set of points will always be a midpoint of the
set, assuming your points don't have 180 degree issues (the average of -179 &
+179 is about as far away from where you want to be as possible).
There are other ways to determine/define a midpoint, just like mean, median,
modes are used as representative values (sort of mid points) for numeric
datasets.
If you are working in lat/long, the avg(X), avg(Y) will lie in a place which
could certainly be called a midpoint, but it isn't the only way, esp if you
want to weight points for any reason.
While there is a distortion using cartesian lats/longs instead of projected
points, all your data is subject to this distortion, so the avg() is still
consistent with, & representative of, your data.
If it is critical, youcan transform() your coords to an equal area or other
more suitable projection, then back to achieve a reprojected average instead. I
don't see any value in this for most purposes though.... something like:
select transform(
geometryfromtext('POINT( avg(X(transform(coords,SRID)))
avg(Y(transform(coords,SRID)))
),4326)
group by ....
where SRID is whatever projection you prefer. This may be better done using
centroid() & building a geometry collection, or multipoint for it to work on
(although I'm not sure if centroid() works on collections). I think avg() is
simpler.
Cheers,
Brent
More information about the postgis-users
mailing list