<span style="font-family:arial, sans-serif;font-size:13px">Brent and Birgit,</span><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif">Thanks to both of you for help on this. You helped lead me down a discovery path, and I understand this stuff a lot better now.</font></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif">It took a while to get the data usable because trial and error with ~12,000,000 records is a bit time-consuming. :-)</font></div><div><font face="arial, sans-serif"><br></font></div>
<div><font face="arial, sans-serif">This is the query I ended up using, based on your models:</font></div><div><b><font class="Apple-style-span" face="'courier new', monospace"><div>INSERT INTO "raw"."rm accuracy check" </div>
<div>select rm.rte_nm, rm.rm, "HA_Route", "HA_Milepost", "HA_County", total_tickets_per_rm, </div><div> avg(ST_Distance(ST_Transform(rm.the_geom, 3081),arrests.avg_location)), arrests.avg_location, arrests.arrest_locations</div>
<div>from </div><div> (select "HA_Milepost", "HA_Route", "HA_County", gid, count("HA_Milepost") as total_tickets_per_rm, st_collect(ST_Transform(the_geom, 3081)) as arrest_locations, st_centroid(st_collect(ST_Transform(the_geom, 3081))) as avg_location</div>
<div> from raw."joint arrests" LEFT JOIN raw."geocoding"</div><div><span class="Apple-tab-span" style="white-space:pre"> </span> ON "joint arrests"."HA_Arrest_Key" = "geocoding"."HA_Arrest_Key"</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> WHERE the_geom IS NOT NULL</div><div> group by "HA_Milepost", "HA_Route", "HA_County", gid) arrests LEFT JOIN</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span> gis.hip_reference_markers rm</div><div>on rm.gid=arrests.gid</div><div>group by rm.rte_nm, rm.rm, "HA_Route", "HA_Milepost", "HA_County", arrests.avg_location, arrests.arrest_locations, total_tickets_per_rm;</div>
</font></b></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif">Aren<br></font><br><div class="gmail_quote">On Wed, Apr 27, 2011 at 7:46 AM, Birgit Laggner <span dir="ltr"><<a href="mailto:birgit.laggner@vti.bund.de" target="_blank">birgit.laggner@vti.bund.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#ffffff" text="#000000">
Hi Aren, hi Brent,<br>
<br>
I would only add to Brent's suggestion, that you could use
st_centroid of the collected multipoint instead of calculating
average x and y points for each reference mark - perhaps like this:<br>
<br>
select l.ref_mark_id,<div><br>
avg(ST_Distance(l.location,a.avg_location))<br>
from loc_table l<br></div>
inner join<br>
(select ref_mark_id,<br>
st_centroid(st_collect(location)) as avg_location<br>
from loc_table<br>
group by ref_mark_id) a<br>
on l.ref_mark_id=a.ref_mark_id<br>
group by l.ref_mark_id;<br>
<br>
Regards,<br>
<br>
Birgit.<br>
<br>
<br>
<br>
Am <a href="tel:25.04.2011%2003" value="+12504201103" target="_blank">25.04.2011 03</a>:22, schrieb <a href="mailto:pcreso@pcreso.com:" target="_blank">pcreso@pcreso.com:</a><div><div></div><div>
<blockquote type="cite">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td style="font:inherit" valign="top">Hi Aren,<br>
<br>
If I understand the question, then off the top of my head,
untested & without getting into calculating spheroidal
distances instead of cartesian ones :-) ...<br>
<br>
given a table loc_table with columns:<br>
ref_mark_id<br>
location (point geometry)<br>
<br>
something like:<br>
<br>
select ref_mark_id,<br>
avg(ST_Distance(l.location,a.avg_location))<br>
from loc_table l,<br>
(select ref_mark_id,<br>
setsrid(makepoint(avg(x(location)),
avg(y(location))),4326) as avg_location<br>
group by ref_mark_id as foo) a<br>
where l.ref_mark_id - a.ref_mark_id<br>
group by ref_mark_id;<br>
<br>
Should work. ie: generate a virtual table as a query which
provides the average X/Y point for each marker, then join
this to the original table by marker to average the
distances between each point & the average point,
grouped by marker.<br>
<br>
HTH<br>
<br>
Brent Wood<br>
<br>
<br>
--- On <b>Mon, 4/25/11, Aren Cambre <i><a href="mailto:aren@arencambre.com" target="_blank"><aren@arencambre.com></a></i></b>
wrote:<br>
<blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px"><br>
From: Aren Cambre <a href="mailto:aren@arencambre.com" target="_blank"><aren@arencambre.com></a><br>
Subject: [postgis-users] Calculating variance of a set
of points<br>
To: "PostGIS Users Discussion"
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank"><postgis-users@postgis.refractions.net></a><br>
Date: Monday, April 25, 2011, 12:42 PM<br>
<br>
<div>I have a table with events. Each
event happened at a listed reference marker on a
highway, and it also has latitude and longitude as
recorded by an observer of the event.
<div><br>
</div>
<div>There are many events at each reference marker.
<div>
<br>
</div>
<div>I want to check the precision of the latitude
and longitude for events recorded at each
reference marker. Roughly, I would collect
all latitude/longitude points at each reference
marker, then I would want to see the average
distance between each point and a centroid of all
the points.</div>
<div><br>
</div>
<div>How would I do that with PostGIS?</div>
<div><br>
</div>
<div>I understand how to convert latitude/longitude
to a geometry type, but I am not clear how to do
the rest without iterating through each point
individually.</div>
<div><br>
</div>
<div>Aren</div>
</div>
</div>
<br>
-----Inline Attachment Follows-----<br>
<br>
<div>_______________________________________________<br>
postgis-users mailing list<br>
<a href="http://mc/compose?to=postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div>
</blockquote>
</td>
</tr>
</tbody>
</table>
<pre><fieldset></fieldset>
_______________________________________________
postgis-users mailing list
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a>
</pre>
</blockquote>
</div></div></div>
<br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
<br></blockquote></div><br></div>