[GRASSLIST:608] How do I create a thematic map from a shapefile?

List:

Say I have imported into GRASS 6.1cvs a shapefile consisting of basin boundaries. There are NO attributes in the dbf file. What is the process by which I thematically map attributes from an ascii file that consists of identifiers (that match the IDs of the individual basins) and a value (e.g., mean rainfall)? I know this is elementary, but I just can not see how to do this in GRASS 6. I have looked through all the examples and documentation I can find with no luck.

Regards,
Tom

--
Thomas E Adams
National Weather Service
Ohio River Forecast Center
1901 South State Route 134
Wilmington, OH 45177

EMAIL: thomas.adams@noaa.gov

VOICE: 937-383-0528
FAX: 937-383-0033

What I would do is to add a column or columns to the dbf file with
v.db.addcol to contain the additional fields (e.g. 'v.db.addcol basin
columns="meanprecip real"'). I then write a little script (awk works well
here) to generate a batch file to be executed by db.execute. This file
might look like:

UPDATE basin SET meanprecip=49.7 WHERE id=1;
UPDATE basin SET meanprecip=24.8 WHERE id=2;

and so on. Once I run db.execute with this batch file, I now have an
attribute column in the dbf file with the values of interest.

Best wishes,

Allan Hollander

On Thu, 6 Apr 2006, Thomas Adams wrote:

List:

Say I have imported into GRASS 6.1cvs a shapefile consisting of basin
boundaries. There are NO attributes in the dbf file. What is the process
by which I thematically map attributes from an ascii file that consists
of identifiers (that match the IDs of the individual basins) and a value
(e.g., mean rainfall)? I know this is elementary, but I just can not see
how to do this in GRASS 6. I have looked through all the examples and
documentation I can find with no luck.

Regards,
Tom

--

On Apr 6, 2006, at 3:16 PM, Thomas Adams wrote:

List:

Say I have imported into GRASS 6.1cvs a shapefile consisting of basin boundaries. There are NO attributes in the dbf file. What is the process by which I thematically map attributes from an ascii file that consists of identifiers (that match the IDs of the individual basins) and a value (e.g., mean rainfall)? I know this is elementary, but I just can not see how to do this in GRASS 6. I have looked through all the examples and documentation I can find with no luck.

If the basin dbf has no attributes, you'll have to add your basin ID to the vector coverage first, and then you can merge the rainfall values with db.execute (or do it outside of GRASS using, say, MySQL).

First add a column in the database for your unique ID. I'd use db.execute here too, or else do it outside of GRASS in a terminal window.

To add basin IDs, use the d.what.vect -ef command, clicking through each basin and assigning the appropriate value to the "BASIN_ID" column.

Last, as noted above, you can then (in MySQL, at least) Left- or Right-JOIN the tables WHERE index.table1 = index.table2. This type of JOIN has the added bonus of filling in missing values with NULL, so you can spot values you might have skipped.

Alternately, you could create a "RAINFALL" field in your coverage dbf file (here, I'll call it 'tablename') and use

UPDATE tablename SET 'tablename.RAINFALL'= 'othertable.rainfall' WHERE 'tablename.BASIN_ID' = 'othertable.basin_id';

to merge in the one value; I think that's the right syntax--somebody tell me if I screwed up.

Jesse

On Apr 6, 2006, at 4:15 PM, Jesse Hamner wrote:

If the basin dbf has no attributes, you'll have to add your basin ID to the vector coverage first, and then you can merge the rainfall values with db.execute (or do it outside of GRASS using, say, MySQL).

First add a column in the database for your unique ID. I'd use db.execute here too, or else do it outside of GRASS in a terminal window.

To add basin IDs, use the d.what.vect -ef command, clicking through each basin and assigning the appropriate value to the "BASIN_ID" column.

Last, as noted above, you can then (in MySQL, at least) Left- or Right-JOIN the tables WHERE index.table1 = index.table2. This type of JOIN has the added bonus of filling in missing values with NULL, so you can spot values you might have skipped.

Alternately, you could create a "RAINFALL" field in your coverage dbf file (here, I'll call it 'tablename') and use

UPDATE tablename SET 'tablename.RAINFALL'= 'othertable.rainfall' WHERE 'tablename.BASIN_ID' = 'othertable.basin_id';

to merge in the one value; I think that's the right syntax--somebody tell me if I screwed up.

I should note that these SQL commands won't work with the dbf driver--you'll have to db.connect to a mysql database and db.copy your polygon attribute table into the database. Allen Hollander's solution will work with the dbf driver, so that's a consideration.

Jesse