[GRASS-user] Change column data format from double precision to integer

A vector map's database table has a column named z_int and data type of
double precision as presented in the map's attribute table. It was defined
as an int in the v.in.ascii command. How do I change the data type to int?

The only option offered in that window is to delete a column by
right-clicking on it. I assume there's a way within GRASS of changing the
data type.

TIA,

Rich

Hi Rich

On 10/5/21 7:59 PM, Rich Shepard wrote:

A vector map's database table has a column named z_int and data type of
double precision as presented in the map's attribute table. It was defined
as an int in the v.in.ascii command. How do I change the data type to int?

AFAIK coordinates in GRASS (including the z coord) are always DOUBLE. The v.in.ascii function reads the x,y,z columns as DOUBLE.

If you declare the columns parameter in v.in.ascii, these attribute columns are created as DOUBLE.

I checked the OGC specs for vector data and did not find any mention that coordinates should be DOUBLE, but that's usually the case in most GIS, to the best of my knowledge.

Having said that, you can create a new attribute column, and populate it with integer values from the z coordinate, with the CAST sqlite3 function. Consider:

echo "1,1,1" | v.in.ascii -z input=- output=p1 separator=comma x=1 y=2 z=3

v.report p1 option=coor
cat|x|y|z
1|1|1|1

# However, no database connection defined:

v.info -c p1
ERROR: Database connection for map <p1> is not defined in DB file

# v.to.db creates new columns as DOUBLE

v.to.db p1 option=coor column="east,north,elev"

v.info -c p1
Displaying column types/names for database connection of layer <1>:
INTEGER|cat
DOUBLE PRECISION|east
DOUBLE PRECISION|north
DOUBLE PRECISION|elev

# Now add a new INTEGER column

v.db.addcolumn p1 column="z_int INTEGER"

v.db.update p1 column=z_int query_col="CAST(elev as INTEGER)"

v.info -c p1
Displaying column types/names for database connection of layer <1>:
INTEGER|cat
DOUBLE PRECISION|east
DOUBLE PRECISION|north
DOUBLE PRECISION|elev
INTEGER|z_int

I think that is what you wanted.

The only option offered in that window is to delete a column by
right-clicking on it. I assume there's a way within GRASS of changing the
data type.

TIA,

Rich

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918

On Tue, 5 Oct 2021, Micha Silver wrote:

AFAIK coordinates in GRASS (including the z coord) are always DOUBLE. The
v.in.ascii function reads the x,y,z columns as DOUBLE.

Micha,

How interesting! In this project the depths are in integers but display as
double

# However, no database connection defined:

Yes, I noticed this, too. The shape files for the same points, imported with
v.in.ogr, do come with a database table. I was going to provide a couple of
samples and ask about this but you've answered my question.

# Now add a new INTEGER column
v.db.addcolumn p1 column="z_int INTEGER"
v.db.update p1 column=z_int query_col="CAST(elev as INTEGER)"

I think that is what you wanted.

Yep. That it is. Saves my time creating examples to get this same knowledge.

Thanks,

Rich