<html style="direction: ltr;">
  <head>
    <meta content="text/html; charset=windows-1255"
      http-equiv="Content-Type">
    <style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
  </head>
  <body style="direction: ltr;"
    bidimailui-detected-decoding-type="preferred-charset"
    bgcolor="#FFFFFF" text="#660000">
    <div class="moz-cite-prefix">On 19/08/2012 03:43, PB wrote:<br>
    </div>
    <blockquote cite="mid:1345337005706-4996130.post@n6.nabble.com"
      type="cite">
      <pre wrap="">Hi - I have a large set of points (x,y,z) on a map. Overlayed on the map is a
grid that is currently a separate polygon shapefile layer (defined by
lat/lons).  What i'd like to do is aggregate the z values within each grid
square (sum, mean, count, etc).  I'm new-ish to GIS, and brand new to QGIS,
have searched the archive, and tried a number of vector tools and queries
but no joy.  I have also tried converting layers to rasters, but things
start getting weird quickly.  

Any help would be great.  Many thanks!  Paul.
</pre>
    </blockquote>
    Sounds like a job for Spatialite. If you import both shapefiles into
    spatialite, then you can run a query to aggregate the z values, such
    as:<br>
    <br>
    # Assuming two tables: 'points' with z values in column 'z' <br>
    # and the 'grid' table with primary key pk_uid.<br>
    # First add columns to the grid for sum, mean, count:<br>
    ALTER TABLE grid ADD COLUMN sum_pts INTEGER;<br>
    ALTER TABLE grid ADD COLUMN mean_pts INTEGER;<br>
    ALTER TABLE grid ADD COLUMN count_pts INTEGER;<br>
    <br>
    # The aggregate query will be<br>
    SELECT SUM(p.z), AVG(p.z), COUNT(p.z)<br>
    FROM points AS p, grid AS g<br>
    WHERE ST_Within(p.Geometry, g.Geometry)<br>
    GROUP BY g.pk_uid;<br>
    <br>
    # Now put that query into update statements to get the values into
    the grid table<br>
    UPDATE grid SET sum_pts=(<br>
        SELECT SUM(p.z)<br>
        FROM points AS p, grid AS g<br>
        WHERE ST_Within(p.Geometry, g.Geometry) AND<br>
        g.pk_uid=grid.pk_uid<br>
    );<br>
    <br>
    UPDATE grid SET count_pts=(<br>
        SELECT COUNT(p.z)<br>
        FROM points AS p, grid AS g<br>
        WHERE ST_Within(p.Geometry, g.Geometry) AND<br>
        g.pk_uid=grid.pk_uid<br>
    );<br>
    <br>
    UPDATE grid SET mean_pts=(<br>
        SELECT AVG(p.z)<br>
        FROM points AS p, grid AS g<br>
        WHERE ST_Within(p.Geometry, g.Geometry) AND<br>
        g.pk_uid=grid.pk_uid<br>
    );<br>
    <br>
    <blockquote cite="mid:1345337005706-4996130.post@n6.nabble.com"
      type="cite">
      <pre wrap="">


--
View this message in context: <a class="moz-txt-link-freetext" href="http://osgeo-org.1560.n6.nabble.com/aggregate-points-within-pre-defined-grid-squares-tp4996130.html">http://osgeo-org.1560.n6.nabble.com/aggregate-points-within-pre-defined-grid-squares-tp4996130.html</a>
Sent from the Quantum GIS - User mailing list archive at Nabble.com.
_______________________________________________
Qgis-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Qgis-user@lists.osgeo.org">Qgis-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/qgis-user">http://lists.osgeo.org/mailman/listinfo/qgis-user</a>

This mail was received via Mail-SeCure System.


</pre>
    </blockquote>
    <font size="+1"></font><br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Micha Silver
052-3665918
</pre>
  </body>
</html>