|
On 02/10/2012 17:43, Lars Dalby wrote:
Micha Silver wroteHere's the same query using db.select: echo 'SELECT a_row AS GridRow, a_col AS GridCol, SUM(clip_area) As "Water Area in Grid" FROM glwd_grid GROUP BY a_cat ORDER BY a_row, a_col LIMIT 20;' | db.select GridRow|GridCol|Water Area in Grid 9|43|11734990.811648 10|42|7600679.947002 10|43|20154750.823557 10|44|10095944.174832 10|46|18364623.744757 10|49|3054521.141835 11|41|250083.456892 11|42|9839134.964962 11|43|23519926.337785 11|44|11323614.28017 11|45|8426141.099425 11|46|12079532.459832 11|47|11135300.910967 11|49|571804.968053 11|50|1319664.199523 12|41|18036461.225015 12|42|15664405.025981 12|43|2471761.404269 12|45|2339714.549891 12|47|2890312.572311So I got this now, but now I struggle with getting these summed values set in at the right locations in the vector grid (or ideally a raster, which is the ultimate goal).I guess the idea is to create a new vector from the sql selection and then rasterize this new map, but I am affraid I will have to ask for a hint once again... Well this would be easy to do right within SQLite. After creating the grid in GRASS you'll have an SQLite table called glwd_grid of all areas of water surface (clipped to the grid) and another table of the grid itself (I called it grid92 in the example). So, in SQLite: ALTER TABLE grid92 ADD COLUMN water_surf_area DOUBLE PRECISION; Then use the above query as a subquery in an UPDATE Statement: UPDATE grid92 SET water_surf_area=( SELECT SUM(clip_area) FROM glwd_grid AS gg WHERE gg.a_cat=grid92.cat ) ; That should leave you with a vector polygon layer "grid92" including a column "water_surf_area" which holds the area covered by water in each grid cell. To convert that to a raster, using the water surface area would require: extracting centroids, exporting the centroid attribute table to ascii, and using that with r.in.xyz to recreate the raster. v.extract grid92 type=centroids out=grid92_centroids # GRASS keeps the attrib table linked to the centroids, # so when you extract centroids you also get the attribs v.out.ascii grid92_centroids out=grid92_centroids.txt columns="cat,water_surf_area,...<other data>..." # Check the ascii file to see column positions Now set the resolution to exactly what you want for the final raster: g.region -p res=92000,92000 n=... s=... e=... w=... Use the r.in.xyz -s option to examine the extent of the xyz point data from the vector grid. Then r.in.xyz -s grid92_centroids.txt r.in.xyz in=grid92_centroids.txt out=grid92 z=<the column number containing the water_surf_area data> The above seems a bit convoluted. Maybe someone else can see a more straight forward solution... Regards, Micha Thanks again -Lars -- View this message in context: http://osgeo-org.1560.n6.nabble.com/Rasterize-polygons-multiple-polygons-per-grid-cell-tp5005264p5005898.html Sent from the Grass - Users mailing list archive at Nabble.com. _______________________________________________ grass-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/grass-user This mail was received via Mail-SeCure System. -- Micha Silver 052-3665918 |
_______________________________________________ grass-user mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/grass-user
