[GRASS-user] Square root in SQL Builder

Hi everyone!

I need to populate a column in attribute table based on the square root of entries from another column. I tried the field calculator with no success. It seams that SQRT function is not supported by SQLite driver. Any help would be highly appreciated.

Regards.

Atenciosamente,

···

Dr. Thiago Statella, Professor Titular

Instituto Federal de Educação, Ciência e Tecnologia de São Paulo - IFSP

Campus Presidente Epitácio

http://lattes.cnpq.br/8559753273123798

https://sites.google.com/view/statella

https://orcid.org/0000-0002-8656-9147

Hi Thiago,

On Tue, Jan 30, 2024 at 1:05 AM Thiago Statella via grass-user
<grass-user@lists.osgeo.org> wrote:

Hi everyone!

I need to populate a column in attribute table based on the square root of entries from another column.
I tried the field calculator with no success. It seams that SQRT function is not supported by SQLite driver.
Any help would be highly appreciated.

Functionalities like sqrt() or log() are not available in base SQLite
(an issue unrelated to GRASS GIS). You will have to install an SQLite extension.

See the v.db.update manual page and these wiki pages:
- https://grasswiki.osgeo.org/wiki/Build_SQLite_extension_on_Linux
- https://grasswiki.osgeo.org/wiki/Build_SQLite_extension_on_windows

Regards,
Markus

--
Markus Neteler, PhD
https://www.mundialis.de - company
https://grass.osgeo.org - FOSS
https://neteler.org - blog & freelancing

Math functions in SQLite are available when SQLite’s amalgamation is compiled with

-DSQLITE_ENABLE_MATH_FUNCTIONS

However, since sqlite3 3.35, in March 2021, that option is on by default. I did a quick check with the latest released Ubuntu docker image for grass (so you could compare), and sqrt seems to work. Python has this enabled too for versions since April 2021, including back ported versions of Python 3.8 https://github.com/python/cpython/issues/86852, so there’s no reason it shouldn’t work.

echoix /workspace/grass (main) $ docker run -it osgeo/grass-gis:releasebranch_8_3-ubuntu bash

root@83c468d748e4:/grassdb# grass

Starting GRASS GIS…

WARNING: It appears that the X Windows system is not active.

A graphical based user interface is not supported.

(DISPLAY variable is not set.)

Switching to text based interface mode.


/ ____/ __ / | / ___/ ___/ / ____/ _/ ___/

/ / / // / /| | _ \ \ / / __ / / _ \

/ // / , / ___ |/ /__/ / / /_/ // / ___/ /

_// |// |/// _///___/

Welcome to GRASS GIS 8.3.2dev (aeb4081)

GRASS GIS homepage: https://grass.osgeo.org

This version running through: Bash Shell (/bin/bash)

Help is available with the command: g.manual -i

See the licence terms with: g.version -c

See citation options with: g.version -x

Start the GUI with: g.gui wxpython

When ready to quit enter: exit

GRASS world_latlong_wgs84/PERMANENT:grassdb > sqlite3

SQLite version 3.37.2 2022-01-06 13:25:41

Enter “.help” for usage hints.

Connected to a transient in-memory database.

Use “.open FILENAME” to reopen on a persistent database.

sqlite> .version

SQLite 3.37.2 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5dalt1

zlib version 1.2.11

gcc-11.4.0

sqlite> .exit

GRASS world_latlong_wgs84/PERMANENT:grassdb > db.select sql=“select sqrt(2)”

sqrt(2)

1.4142135623731

GRASS world_latlong_wgs84/PERMANENT:grassdb >

You could check your versions, and come back if they are recent enough and should have them enabled, but aren’t. A little bit more info on your environment might be needed to fully understand in that case

Have a great day!

Edouard Choinière

Le 30 janv. 2024 à 04:41, Markus Neteler neteler@osgeo.org a écrit :

Hi Thiago,

On Tue, Jan 30, 2024 at 1:05 AM Thiago Statella via grass-user
grass-user@lists.osgeo.org wrote:

Hi everyone!

I need to populate a column in attribute table based on the square root of entries from another column.

I tried the field calculator with no success. It seams that SQRT function is not supported by SQLite driver.

Any help would be highly appreciated.

Functionalities like sqrt() or log() are not available in base SQLite
(an issue unrelated to GRASS GIS). You will have to install an SQLite extension.

See the v.db.update manual page and these wiki pages:

Regards,
Markus


Markus Neteler, PhD
https://www.mundialis.de - company
https://grass.osgeo.org - FOSS
https://neteler.org - blog & freelancing

Thank you guys, I’ll try that!

Atenciosamente,


Dr. Thiago Statella, Professor Titular
Instituto Federal de Educação, Ciência e Tecnologia de São Paulo - IFSP
Campus Presidente Epitácio
http://lattes.cnpq.br/8559753273123798
https://sites.google.com/view/statella

Em 30 de jan. de 2024, à(s) 20:09, Edouard Choinière e.chs@outlook.com escreveu:

Math functions in SQLite are available when SQLite’s amalgamation is compiled with

-DSQLITE_ENABLE_MATH_FUNCTIONS

However, since sqlite3 3.35, in March 2021, that option is on by default. I did a quick check with the latest released Ubuntu docker image for grass (so you could compare), and sqrt seems to work. Python has this enabled too for versions since April 2021, including back ported versions of Python 3.8 https://github.com/python/cpython/issues/86852, so there’s no reason it shouldn’t work.

echoix /workspace/grass (main) $ docker run -it osgeo/grass-gis:releasebranch_8_3-ubuntu bash

root@83c468d748e4:/grassdb# grass

Starting GRASS GIS…

WARNING: It appears that the X Windows system is not active.

A graphical based user interface is not supported.

(DISPLAY variable is not set.)

Switching to text based interface mode.


/ ____/ __ / | / ___/ ___/ / ____/ _/ ___/

/ / / // / /| | _ \ \ / / __ / / _ \

/ // / , / ___ |/ /__/ / / /_/ // / ___/ /

_// |// |/// _///___/

Welcome to GRASS GIS 8.3.2dev (aeb4081)

GRASS GIS homepage: https://grass.osgeo.org

This version running through: Bash Shell (/bin/bash)

Help is available with the command: g.manual -i

See the licence terms with: g.version -c

See citation options with: g.version -x

Start the GUI with: g.gui wxpython

When ready to quit enter: exit

GRASS world_latlong_wgs84/PERMANENT:grassdb > sqlite3

SQLite version 3.37.2 2022-01-06 13:25:41

Enter “.help” for usage hints.

Connected to a transient in-memory database.

Use “.open FILENAME” to reopen on a persistent database.

sqlite> .version

SQLite 3.37.2 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5dalt1

zlib version 1.2.11

gcc-11.4.0

sqlite> .exit

GRASS world_latlong_wgs84/PERMANENT:grassdb > db.select sql=“select sqrt(2)”

sqrt(2)

1.4142135623731

GRASS world_latlong_wgs84/PERMANENT:grassdb >

You could check your versions, and come back if they are recent enough and should have them enabled, but aren’t. A little bit more info on your environment might be needed to fully understand in that case

Have a great day!

Edouard Choinière

Le 30 janv. 2024 à 04:41, Markus Neteler neteler@osgeo.org a écrit :

Hi Thiago,

On Tue, Jan 30, 2024 at 1:05 AM Thiago Statella via grass-user
grass-user@lists.osgeo.org wrote:

Hi everyone!

I need to populate a column in attribute table based on the square root of entries from another column.

I tried the field calculator with no success. It seams that SQRT function is not supported by SQLite driver.

Any help would be highly appreciated.

Functionalities like sqrt() or log() are not available in base SQLite
(an issue unrelated to GRASS GIS). You will have to install an SQLite extension.

See the v.db.update manual page and these wiki pages:

Regards,
Markus


Markus Neteler, PhD
https://www.mundialis.de - company
https://grass.osgeo.org - FOSS
https://neteler.org - blog & freelancing