[GRASS-user] Reclassify a vector adding a column
Stefan Blumentrath
Stefan.Blumentrath at nina.no
Wed Jun 17 12:24:12 PDT 2020
Here is the documentation for the LIKE operator in SQLite:
https://www.sqlitetutorial.net/sqlite-like/
It should be possible to use it in a “searched case statement”:
https://www.sqlitetutorial.net/sqlite-case/
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;"
Cheers
Stefan
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
Dear Micha,
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:
Ciao Stefan,
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;"
Best, Micha
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?
Thanks!
--
Margherita Di Leo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20200617/2abefbff/attachment.html>
More information about the grass-user
mailing list