[GRASS-user] db.? to change column names

   I imported a .dat file using v.in.ascii to a lon_lat location, then
re-projected it to the desired location. The column names for the CRS in the
database were still 'lon' and 'lat'. I did not see a db.* module to change
the names; neither db.columns nor db.describe have this capability.

   Using the gui I was able to 'manage tables' and change the column names
there, but did not look to see if there was the related command on the
bottom of the dialog box.

   What module lets me rename columns when working at the command line or
from a script?

Regards,

Rich

On Fri, Aug 31, 2018 at 12:09 AM Rich Shepard <rshepard@appl-ecosys.com> wrote:

   I imported a .dat file using v.in.ascii to a lon_lat location, then
re-projected it to the desired location. The column names for the CRS in the
database were still 'lon' and 'lat'. I did not see a db.* module to change
the names; neither db.columns nor db.describe have this capability.

Maybe this helps: it allows to rename a column in the attribute table
connected to a given vector map:
https://grass.osgeo.org/grass74/manuals/v.db.renamecolumn.html

Markus

On 31/08/18 00:09, Rich Shepard wrote:

    I imported a .dat file using v.in.ascii to a lon_lat location, then
re-projected it to the desired location. The column names for the CRS in the
database were still 'lon' and 'lat'. I did not see a db.* module to change
the names; neither db.columns nor db.describe have this capability.

    Using the gui I was able to 'manage tables' and change the column names
there, but did not look to see if there was the related command on the
bottom of the dialog box.

    What module lets me rename columns when working at the command line or
from a script?

Markus gave you the name of a module, but just to make sure: the column content in your attribute table does not change because you reproject, so your columns lat and lon should still contain lat and lon values.

If you would like to fill two columns with the x and y values of your points in the projected system, instead of having the lat/lon columns, you might just as well drop the latter with v.db.dropcolumn, add two new columns x/y with v.db.addcolumn and fill those with v.to.db.

Moritz

On Fri, 31 Aug 2018, Moritz Lennert wrote:

Markus gave you the name of a module, but just to make sure: the column
content in your attribute table does not change because you reproject, so
your columns lat and lon should still contain lat and lon values.

Moritz,

   Yes, this is correct: they do.

   However, v.out.ascii produced the projected coordinates, not the
geographic lon/lat; e.g.,

10332|2324618.93021014|214826.06781179
10335|2330789.44861867|202224.65265656

   While in the GUI attribute table manager this is seen:
10332|-122.7475|45.977544
10335|-122.644139|45.466111

and there are no easting/northing columns.

  Here's the script (line breaks set by MUA; entered on one command line):

   Using lon_lat location:
v.in.ascii in=wrb-stations.dat out=stations text=doublequote skip=1
columns='site_nbr varchar(5), site_name varchar(64), lon double precision,
lat double precision' x=3 y=4 z=0

   Exit grass, restart and create new location/mapset, then:
v.proj loc=lon_lat map=PERMANENT in=stations
v.out.ascii -c in=stations out=stations.dat type=point columns='*' format=point --o
v.to.db map=stations opt=coor columns='easting,northing'

   Closed that map in the GUI and re-loaded it; still no easting/northing
columns only lon/lat.

   Your thoughts on this are always welcome.

Regards,

Rich

On Fri, 31 Aug 2018, Markus Neteler wrote:

Maybe this helps: it allows to rename a column in the attribute table
connected to a given vector map:
https://grass.osgeo.org/grass74/manuals/v.db.renamecolumn.html

Markus,

   Yes, it would help.

   Because I wanted to modify the database I looked at the db.* modules and
didn't think to look for any v.db.* modules. I know about v.to.db, but did
not consider that a strictly database manipulation would be a vector
command.

   Would it be helpful (and practical) to put (in this case) a "See also:
vector commands" section at the bottom of each module category page that
would point to applicable alternatives? Perhaps even suggesint looking for
extension modules.

Best regards,

Rich

On 31/08/18 16:43, Rich Shepard wrote:

On Fri, 31 Aug 2018, Moritz Lennert wrote:

Markus gave you the name of a module, but just to make sure: the column
content in your attribute table does not change because you reproject, so
your columns lat and lon should still contain lat and lon values.

Moritz,

    Yes, this is correct: they do.

    However, v.out.ascii produced the projected coordinates, not the
geographic lon/lat; e.g.,

10332|2324618.93021014|214826.06781179
10335|2330789.44861867|202224.65265656

    While in the GUI attribute table manager this is seen:
10332|-122.7475|45.977544
10335|-122.644139|45.466111

and there are no easting/northing columns.

Normal:

The first (v.out.ascii) is an output of the information on the geometries (the points). The second is the attribute table linked to those geometries.

   Here's the script (line breaks set by MUA; entered on one command line):

    Using lon_lat location:
v.in.ascii in=wrb-stations.dat out=stations text=doublequote skip=1
columns='site_nbr varchar(5), site_name varchar(64), lon double precision,
lat double precision' x=3 y=4 z=0

    Exit grass, restart and create new location/mapset, then:
v.proj loc=lon_lat map=PERMANENT in=stations
v.out.ascii -c in=stations out=stations.dat type=point columns='*' format=point --o
v.to.db map=stations opt=coor columns='easting,northing'

    Closed that map in the GUI and re-loaded it; still no easting/northing
columns only lon/lat.

To get the data into columns, try this:

v.db.addcolumn stations col="easting double precision, northing double precision"
v.to.db map=stations opt=coor columns='easting,northing'

Then you should see the easting and northing columns in the attribute table. Not need to export and reload.

Moritz

On 31/08/18 16:46, Rich Shepard wrote:

On Fri, 31 Aug 2018, Markus Neteler wrote:

Maybe this helps: it allows to rename a column in the attribute table
connected to a given vector map:
https://grass.osgeo.org/grass74/manuals/v.db.renamecolumn.html

Markus,

    Yes, it would help.

    Because I wanted to modify the database I looked at the db.* modules and
didn't think to look for any v.db.* modules. I know about v.to.db, but did
not consider that a strictly database manipulation would be a vector
command.

    Would it be helpful (and practical) to put (in this case) a "See also:
vector commands" section at the bottom of each module category page that
would point to applicable alternatives? Perhaps even suggesint looking for
extension modules.

db.* = modules for generic database manipulation, including on tables that are not linked to vector maps

v.db.* = modules that manipulate an attribute table of a vector map

Moritz

On Fri, 31 Aug 2018, Moritz Lennert wrote:

To get the data into columns, try this:

v.db.addcolumn stations col="easting double precision, northing double precision"
v.to.db map=stations opt=coor columns='easting,northing'

Then you should see the easting and northing columns in the attribute table. Not need to export and reload.

Moritz,

   Thanks very much.

   The data were exported in preparation for reading into R.

Best regards,

Rich

On Fri, 31 Aug 2018, Moritz Lennert wrote:

db.* = modules for generic database manipulation, including on tables that are not linked to vector maps

v.db.* = modules that manipulate an attribute table of a vector map

Moritz,

   Very true. Yet, for those of us who use grass sporatically a note on the
command pages that other data types hold related commands would be helpful.

Best regards,

Rich