[GRASS-user] Reclassify a vector adding a column
Stefan.Blumentrath at nina.no
Wed Jun 17 12:24:12 PDT 2020
Here is the documentation for the LIKE operator in SQLite:
It should be possible to use it in a “searched case statement”:
So the syntax would be:
db.execute sql="UPDATE myroads SET width=CASE WHEN TYPE LIKE 'M%' THEN 'Wide' WHEN TYPE LIKE 'Loc%' THEN 'Narrow' ELSE 'Unknown' END;"
From: grass-user <grass-user-bounces at lists.osgeo.org> On Behalf Of Margherita Di Leo
Sent: onsdag 17. juni 2020 18:39
To: Micha Silver <tsvibar at gmail.com>
Cc: GRASS user list <grass-user at lists.osgeo.org>
Subject: Re: [GRASS-user] Reclassify a vector adding a column
On Wed, Jun 17, 2020 at 4:05 PM Micha Silver <tsvibar at gmail.com<mailto:tsvibar at gmail.com>> wrote:
On 17/06/2020 16:14, Margherita Di Leo wrote:
thank you, I tried and it didn't give me any error but didn't update the column either...
The sqlite CASE statement should be:
CASE <old_column> WHEN '<old_val1>' THEN '<new_val1>' WHEN '<old_val2>' THEN '<new_val2>'....END;
Here's an example that worked for me. I have a "myroads" vector with column 'TYPE'
# Add new column for road width as text
v.db.addcolumn myroads column="width TEXT"
# Run update with CASE
db.execute sql="UPDATE myroads SET width=CASE TYPE WHEN 'Main' THEN 'Wide' WHEN 'Local' THEN 'Narrow' ELSE 'Unknown' END;"
This worked! Thank you so much! I have one last question. Does it also support an IS LIKE condition, and if yes, how can I express it?
Margherita Di Leo
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the grass-user