For instance, assume that well is a table containing X,Y coordinate values and that wellowners is a table containing ownership information associated with well logs. To base a query on site location which would return attribute data on ownership and locational information in the table well the following join would be needed on the command line:
The column wellid is common to both the well and the wellowners table. Because of this attribute data from both tables will be returned if the coordinates registered by the mouse return a record from the table well within a radius specified by the distance parameter on the command line. Specifying these conditions would insure that all rows from table roads which satisfy the query criteria would be matched with the corresponding rows in table main, 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 SELECT statement for use with the -s flag.
EXAMPLE (single table)
d.what.s.pg -s pql=well.pql distance=10
well.pql:
retrieve unique (well.all)
where (((well.utmeast-?) * (well.utmeast-?) + (well.utmnorth-?) * (well.utmnorth-?)) < ?) and well.utmeast > 0 and well.utmnorth >0
EXAMPLE (two table join)
d.what.s.pg -s pql=nri.pql distance
nri.pql:
retrieve unique (well.all,wellowners.all)
where (((well.utmeast-?) * (well.utmeast-?) + (well.utmnorth-?) * (well.utmnorth-?)) < ?) and well.utmeast > 0 and well.utmnorth >0 and wellowners.lastname ~ "SM" and wellowners.wellid=well.wellid
Postgres modifications: Janne Soimasuo, Faculty of Forestry, University of Joensuu, Finland.
Updated to GRASS 5 by Alex Shevlakov (sixote@yahoo.com)