[GRASS-user] SQL: generating numeric class numbers from class text labels?

Hernán De Angelis dhdeangelis at comhem.se
Wed Dec 4 09:39:06 PST 2019


The variable to increment should be of course as corrected below:
>
> # get the unique classes
>
> SELECT distinct(label) FROM table;
>
> -> fetch results in an array "txt_label"
>
> # iterate over array and insert new integer labels in table
>
> *int_label = 0 *
>
> foreach txt_label {
>
>     INSERT INTO table.label_int VALUES int_label WHERE label = 
> 'txt_label'
>
> *int_label++*
>
> }
>
>
> /H.
>
>
>
>
>
> On 2019-12-04 18:11, Markus Neteler wrote:
>> Hi,
>>
>> I have a landuse map with text labels (forest, street, ...). For
>> r.learn.ml I need to have them as numeric classes.
>> It is not important for me which number is assigned but I search for
>> an automated solution, i.e. SQL statement unless there is a different
>> way.
>>
>> So:
>>
>> cat|label|label_int
>> 1|forest|1
>> 2|forest|1
>> 3|street|2
>> 4|forest|1
>> 5|street|2
>> 6|urban|3
>> ...
>>
>> I guess I have done that already some years ago but I can't remember
>> the trick :-)
>>
>> thanks for a hint,
>> Markus
>> _______________________________________________
>> grass-user mailing list
>> grass-user at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/grass-user
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20191204/2d797f3b/attachment.html>


More information about the grass-user mailing list