[GRASS-user] Reclassify a vector adding a column

Margherita Di Leo diregola at gmail.com
Thu Jun 18 03:05:43 PDT 2020


Super! Thank you both!

On Wed, Jun 17, 2020 at 9:12 PM Micha Silver <tsvibar at gmail.com> wrote:

>
> On 17/06/2020 19:38, Margherita Di Leo wrote:
>
> Dear Micha,
>
> On Wed, Jun 17, 2020 at 4:05 PM Micha Silver <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?
>
>
> Yes, sqlite supports LIKE, for example:
>
>
> micha at tp480:scripts$ db.select sql='SELECT TYPE,LENGTH FROM roads WHERE
> TYPE LIKE "%Ma%";'
> TYPE|LENGTH
> Main|1.542641
> Main|4.346567
> Main|1.382557
> Main|1.120805
> Main|1.117633
> Main|0.13777
> ....
>
>
> Thanks!
>
>
> --
> Margherita Di Leo
>
> --
> Micha Silver
> Ben Gurion Univ.
> Sde Boker, Remote Sensing Lab
> cell: +972-523-665918https://orcid.org/0000-0002-1128-1325
>
>

-- 
Margherita Di Leo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20200618/21703935/attachment.html>


More information about the grass-user mailing list