Skip to content

Commit

Permalink
v.db.join: Add exclude_columns= option (#3174)
Browse files Browse the repository at this point in the history
  • Loading branch information
HuidaeCho committed Nov 19, 2023
1 parent 6164ea1 commit 97da922
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion scripts/v.db.join/v.db.join.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# AUTHOR(S): Markus Neteler
# Converted to Python by Glynn Clements
# PURPOSE: Join a table to a map table
# COPYRIGHT: (C) 2007-2021 by Markus Neteler and the GRASS Development Team
# COPYRIGHT: (C) 2007-2023 by Markus Neteler and the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
Expand Down Expand Up @@ -56,6 +56,13 @@
# % description: Subset of columns from the other table
# %end

# %option G_OPT_DB_COLUMN
# % key: exclude_columns
# % multiple: yes
# % required: no
# % description: Columns to exclude from the other table
# %end

import sys
import string
import grass.script as grass
Expand All @@ -72,6 +79,10 @@ def main():
scolumns = options["subset_columns"].split(",")
else:
scolumns = None
if options["exclude_columns"]:
ecolumns = options["exclude_columns"].split(",")
else:
ecolumns = None

try:
f = grass.vector_layer_db(map, layer)
Expand Down Expand Up @@ -124,6 +135,10 @@ def main():
if not found:
grass.warning(_("Column <%s> not found in table <%s>") % (scol, otable))

# exclude columns from other table
if ecolumns:
cols_to_add = list(filter(lambda col: col[0] not in ecolumns, cols_to_add))

all_cols_tt = grass.vector_columns(map, int(layer)).keys()
# This is used for testing presence (and potential name conflict) with
# the newly added columns, but the test needs to case-insensitive since it
Expand Down

0 comments on commit 97da922

Please sign in to comment.