Dear Markus
Thanks for your answer. I thought about v.db.dropcolumn earlier. However, I am
trying to include this within a function, following a workflow in which the
input vector might have columns with different names, in which case it would be
good to be able to select the ones to keep instead of the ones to remove.For
instance, let's say I want to be able to provide either of the following input
vectors:- "vector1", with columns "a, b, c, d, e"- "vector2", with columns "j,
a, k, f, e"Let's say I want to keep only "a" and "e".
If I use v.db.dropcolumn, I'll have to first list the names of all columns
(maybe with v.db.select), then match all the column names that I do not want to
keep ("b, c, d" in the first case, "j, k, f" in the second), then drop them
with v.db.dropcolumn. I thought just selecting which ones I want to keep would
be simpler and more straightforward, if there is a tool for that.
So far I am doing a long step (I am creating a temporary vector to avoid
changing the input):1) v.extract -t input=vector1 output=temp_vector (here I
select only the features, not attribute table)2) v.db.addtable map=temp_vector
columns=a,e (here I do not bother with the names of the undesirable columns)3)
v.db.update map=temp_vector column=e value=1 (here I set a value but I could
take it from the original vector1)
Following what you suggest, I could do:1) g.copy vector=vector1,temp_vector2)
(find out a way to list the undesirable column names)3) v.db.dropcolumn
columns=list_undesidable_columns
Neither of the solutions is so straightforward, that's why I thought there
should be (or could be) another way.In R, for instance, I can easily subset
columns of an sf object using dplyr::select(vector1, a, e). I guess in PostGIS
it is also possible to do that with "SELECT statements", even though I am less
skilled there. It would be great to have a module in GRASS to do it as well...
BestBernardo Em quarta-feira, 9 de fevereiro de 2022 09:28:06 GMT+1, Markus
Neteler <[email protected]> escreveu:
Hi Bernardo,
On Wed, Feb 9, 2022 at 1:39 AM Bernardo Santos via grass-user
<[email protected]> wrote:
>
> Dear list,
>
> Is there a GRASS GIS command (maybe a v.db.* one) to subset, in a single
> command, the columns of a vector?
>
> What I have: vector "vect" with 5 columns "a, b, c, d, e" in the attribute
> table
> What I want: vector "vect_sub" with only, for instance, "a, c, e"
>
> I can use v.extract to subsample rows, but not columns. What is the easiest
> way of doing that, what needing many commands (like creating or copying the
> vector to a new one, creating a new attribute table, then copying only the
> columns I want).
Isn't this simply
https://grass.osgeo.org/grass80/manuals/vector.html
--> v.db.dropcolumn - Drops a column from the attribute table
connected to a given vector map.
--> It offers single and multiple column dropping: columns=name[,name,...]
> I looked for that in the documentation but did not found it so easily.
Please suggest where to improve the documentation.
Markus
_______________________________________________
grass-user mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/grass-user