For instance, assume that secosoilcats is a table containing column values associated with category values in a the GRASS raster file soils. In addition, assume that compyld is a table containing attribute data on the crop production capacity in the same area (cropname). In this example secosoilcats is the table associated with the GRASS raster map and grasscats is the column linking secosoilcats to the GRASS category file, the table compyld contains the attribute information to base the query/reclass on and it is linked to secosoilcats via the common column muid. To specify a query based on attribute values in the table compyld:
Specifying these conditions would insure that all rows from table compyld which satisfy the query criteria would be matched with the corresponding rows in table secosoilcats, which are then related to the spatial features in the GRASS data layer via the GRASS category values.
This syntax is adequate to accomplish 2 table joins. However, if the query demands joins between more than 2 tables it is advisable to use the -s option [see Alternate Command Line Usage] to read a user prepared query, complete with join requirements, from a file.
The user must also specify the name of the GRASS data layer containing these category values on the command line. The following example illustrates the syntax which must be used in constructing a retrieve statement for use with the -s flag.
d.rast.pg -s pql=statsgo.pql input=secosoils
statsgo.pql:
retrieve unique secosoilcats.grasscat,compyld.cropname)
where compyld.muid = secosoilcats.muid and cropname NOTNULL sort by cropname
RESULT:
This example will display a raster surface with a category for each unique value of the column "cropname" from the table compyld. The raster surface will be a reclassed data layer based on the input raster map secosoils.
Postgres modifications: Janne Soimasuo, Faculty of Forestry, University of Joensuu, Finland.
Updated to GRASS 5 by Alex Shevlakov (sixote@yahoo.com)