Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v.edit: Implement the batch option for batch editing #3450

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
623d591
v.edit: Implement the batch option for batching editing
HuidaeCho Feb 24, 2024
5eec2ac
Add a sentence about the red color
HuidaeCho Feb 24, 2024
0767a7c
Add empty lines
HuidaeCho Feb 24, 2024
b58c427
Implement a faster benchmark sript
HuidaeCho Feb 24, 2024
336095c
Add info about necessary columns and order
HuidaeCho Feb 24, 2024
656acbc
Update vector/v.edit/args.c
HuidaeCho Feb 25, 2024
4360af4
Update vector/v.edit/v.edit.html
HuidaeCho Feb 25, 2024
a672d25
Update vector/v.edit/v.edit.html
HuidaeCho Feb 25, 2024
9b28ac3
batching editing => batch editing
HuidaeCho Feb 25, 2024
7016607
Add a comment about the produced table
HuidaeCho Feb 25, 2024
1df8e59
Add a description about stdin for batch=
HuidaeCho Feb 25, 2024
15d50e1
Mention relative performance advantage in the manual
HuidaeCho Feb 25, 2024
9298288
Make batch= exclusive to all options and flags that are supported in …
HuidaeCho Feb 25, 2024
480807a
Make batch= exclusive to all options and flags that are supported in …
HuidaeCho Feb 25, 2024
7186828
Add an affiliation for Huidae Cho
HuidaeCho Feb 25, 2024
76d3f5e
Inline get_flag(); Move p = strchr() closer to its relevant code
HuidaeCho Feb 25, 2024
ddd2011
Add an empty line after variable declarations
HuidaeCho Feb 25, 2024
76e9fbf
Rerun grass_clang_format on long strings in batch.c
HuidaeCho Feb 25, 2024
43ec64e
Micro-optimize short-circuit evaluation for *editing* (non-select) tools
HuidaeCho Feb 25, 2024
23c0620
Support single-character separators and double-quoted columns for mor…
HuidaeCho Feb 26, 2024
7398b13
Add a sentence about a single-character separator
HuidaeCho Feb 26, 2024
3d27af7
Disallow newline as seprator
HuidaeCho Feb 26, 2024
4336502
Empty lines
HuidaeCho Feb 26, 2024
47f75db
Fatal error on multiline columns
HuidaeCho Feb 26, 2024
3ad14c5
Support add tool in batch mode
HuidaeCho Feb 26, 2024
59baa26
Use MODE_BATCH
HuidaeCho Feb 26, 2024
334f9c8
Support multiple tables separated by an empty line; Remove comments (…
HuidaeCho Feb 26, 2024
f21e465
Add an example for a merged table
HuidaeCho Feb 26, 2024
f954793
Fix <p> to <b>
HuidaeCho Feb 26, 2024
907171f
Rewrite about multiple tables
HuidaeCho Feb 26, 2024
17fefc7
Minor change
HuidaeCho Feb 26, 2024
62676c7
Minor change
HuidaeCho Feb 26, 2024
01fdf37
Properly close map for batch editing on fatal error
HuidaeCho Feb 26, 2024
617eb97
Always build topology after each batch command
HuidaeCho Feb 26, 2024
ba22c2a
Empty line
HuidaeCho Feb 26, 2024
280ec93
flags column supports all flags except -b because topology is always …
HuidaeCho Feb 26, 2024
4e6a145
Build topology only when needed
HuidaeCho Feb 26, 2024
6906317
Move thresh to SelectParams
HuidaeCho Feb 27, 2024
cd272ce
Move duplicate editing code to edit.c
HuidaeCho Feb 27, 2024
4339dfe
Fix a bug in the example
HuidaeCho Feb 27, 2024
d60975f
Add a comment about unsupported multi-line columns
HuidaeCho Feb 27, 2024
bf7c826
Add a comment about unsupported multi-line columns
HuidaeCho Feb 27, 2024
f187082
Move List to non-batch block
HuidaeCho Feb 27, 2024
c08a8a3
Add back the custom error handler to build topology on error
HuidaeCho Feb 27, 2024
15a1d41
Move separator line after topology building
HuidaeCho Feb 27, 2024
3bedfba
Merge branch 'main' into v_edit_batch
landam Mar 22, 2024
bf0ac31
Merge branch 'main' into v_edit_batch
landam May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
234 changes: 130 additions & 104 deletions vector/v.edit/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ int parser(int argc, char *argv[], struct GParams *params,
params->tool = G_define_option();
params->tool->key = "tool";
params->tool->type = TYPE_STRING;
params->tool->required = YES;
params->tool->multiple = NO;
params->tool->description = _("Tool");
desc_tool = NULL;
Expand Down Expand Up @@ -225,6 +224,24 @@ int parser(int argc, char *argv[], struct GParams *params,
params->extend_parallel->description =
_("Connect parallel lines (using extend tools and threshold distance)");

params->batch = G_define_standard_option(G_OPT_F_INPUT);
params->batch->key = "batch";
params->batch->required = NO;
params->batch->label = _("Name of input file for batch editing");
params->batch->description = _("'-' for standard input");

params->sep = G_define_standard_option(G_OPT_F_SEP);
params->sep->label = _("Field separator for batch input file");
params->sep->description = _("Special characters: pipe, comma, space, tab");

G_option_required(params->tool, params->batch, NULL);
G_option_excludes(params->batch, params->tool, params->in, params->move,
params->id, params->cat, params->coord, params->bbox,
params->poly, params->where, params->query, params->snap,
params->zbulk, params->reverse, params->close,
params->header, params->topo, params->move_first,
params->extend_parallel, NULL);

if (G_parser(argc, argv))
exit(EXIT_FAILURE);

Expand All @@ -242,119 +259,128 @@ int parser(int argc, char *argv[], struct GParams *params,
/*
check that the given arguments makes sense together
*/
if (strcmp(params->tool->answer, "create") == 0) {
*action_mode = MODE_CREATE;
}
else if (strcmp(params->tool->answer, "add") == 0) {
*action_mode = MODE_ADD;
}
else if (strcmp(params->tool->answer, "delete") == 0) {
*action_mode = MODE_DEL;
}
else if (strcmp(params->tool->answer, "move") == 0) {
*action_mode = MODE_MOVE;
}
else if (strcmp(params->tool->answer, "merge") == 0) {
*action_mode = MODE_MERGE;
}
else if (strcmp(params->tool->answer, "break") == 0) {
*action_mode = MODE_BREAK;
}
else if (strcmp(params->tool->answer, "connect") == 0) {
*action_mode = MODE_CONNECT;
}
else if (strcmp(params->tool->answer, "extend") == 0) {
*action_mode = MODE_EXTEND;
}
else if (strcmp(params->tool->answer, "extendstart") == 0) {
*action_mode = MODE_EXTEND_START;
}
else if (strcmp(params->tool->answer, "extendend") == 0) {
*action_mode = MODE_EXTEND_END;
}
else if (strcmp(params->tool->answer, "vertexadd") == 0) {
*action_mode = MODE_VERTEX_ADD;
}
else if (strcmp(params->tool->answer, "vertexdel") == 0) {
*action_mode = MODE_VERTEX_DELETE;
}
else if (strcmp(params->tool->answer, "vertexmove") == 0) {
*action_mode = MODE_VERTEX_MOVE;
}
else if (strcmp(params->tool->answer, "select") == 0) {
*action_mode = MODE_SELECT;
}
else if (strcmp(params->tool->answer, "catadd") == 0) {
*action_mode = MODE_CATADD;
}
else if (strcmp(params->tool->answer, "catdel") == 0) {
*action_mode = MODE_CATDEL;
}
else if (strcmp(params->tool->answer, "copy") == 0) {
*action_mode = MODE_COPY;
}
else if (strcmp(params->tool->answer, "snap") == 0) {
*action_mode = MODE_SNAP;
}
else if (strcmp(params->tool->answer, "flip") == 0) {
*action_mode = MODE_FLIP;
}
else if (strcmp(params->tool->answer, "zbulk") == 0) {
*action_mode = MODE_ZBULK;
}
else if (strcmp(params->tool->answer, "chtype") == 0) {
*action_mode = MODE_CHTYPE;
}
else if (strcmp(params->tool->answer, "areadel") == 0) {
*action_mode = MODE_AREA_DEL;
}
else {
G_fatal_error(_("Operation '%s' not implemented"),
params->tool->answer);
}

if ((*action_mode != MODE_CREATE && *action_mode != MODE_ADD &&
*action_mode != MODE_ZBULK) &&
(params->cat->answers == NULL) && (params->coord->answers == NULL) &&
(params->poly->answers == NULL) && (params->id->answers == NULL) &&
(params->bbox->answers == NULL) && (params->where->answer == NULL) &&
(params->query->answer == NULL)) {
G_fatal_error(_("At least one option from %s must be specified"),
"cats, ids, coords, bbox, polygon, where, query");
}
if (params->tool->answer) {
if (strcmp(params->tool->answer, "create") == 0) {
*action_mode = MODE_CREATE;
}
else if (strcmp(params->tool->answer, "add") == 0) {
*action_mode = MODE_ADD;
}
else if (strcmp(params->tool->answer, "delete") == 0) {
*action_mode = MODE_DEL;
}
else if (strcmp(params->tool->answer, "move") == 0) {
*action_mode = MODE_MOVE;
}
else if (strcmp(params->tool->answer, "merge") == 0) {
*action_mode = MODE_MERGE;
}
else if (strcmp(params->tool->answer, "break") == 0) {
*action_mode = MODE_BREAK;
}
else if (strcmp(params->tool->answer, "connect") == 0) {
*action_mode = MODE_CONNECT;
}
else if (strcmp(params->tool->answer, "extend") == 0) {
*action_mode = MODE_EXTEND;
}
else if (strcmp(params->tool->answer, "extendstart") == 0) {
*action_mode = MODE_EXTEND_START;
}
else if (strcmp(params->tool->answer, "extendend") == 0) {
*action_mode = MODE_EXTEND_END;
}
else if (strcmp(params->tool->answer, "vertexadd") == 0) {
*action_mode = MODE_VERTEX_ADD;
}
else if (strcmp(params->tool->answer, "vertexdel") == 0) {
*action_mode = MODE_VERTEX_DELETE;
}
else if (strcmp(params->tool->answer, "vertexmove") == 0) {
*action_mode = MODE_VERTEX_MOVE;
}
else if (strcmp(params->tool->answer, "select") == 0) {
*action_mode = MODE_SELECT;
}
else if (strcmp(params->tool->answer, "catadd") == 0) {
*action_mode = MODE_CATADD;
}
else if (strcmp(params->tool->answer, "catdel") == 0) {
*action_mode = MODE_CATDEL;
}
else if (strcmp(params->tool->answer, "copy") == 0) {
*action_mode = MODE_COPY;
}
else if (strcmp(params->tool->answer, "snap") == 0) {
*action_mode = MODE_SNAP;
}
else if (strcmp(params->tool->answer, "flip") == 0) {
*action_mode = MODE_FLIP;
}
else if (strcmp(params->tool->answer, "zbulk") == 0) {
*action_mode = MODE_ZBULK;
}
else if (strcmp(params->tool->answer, "chtype") == 0) {
*action_mode = MODE_CHTYPE;
}
else if (strcmp(params->tool->answer, "areadel") == 0) {
*action_mode = MODE_AREA_DEL;
}
else {
G_fatal_error(_("Operation '%s' not implemented"),
params->tool->answer);
}

if (*action_mode == MODE_MOVE || *action_mode == MODE_VERTEX_MOVE) {
if (params->move->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"), params->tool->answer,
params->move->key);
if ((*action_mode != MODE_CREATE && *action_mode != MODE_ADD &&
*action_mode != MODE_ZBULK) &&
(params->cat->answers == NULL) &&
(params->coord->answers == NULL) &&
(params->poly->answers == NULL) && (params->id->answers == NULL) &&
(params->bbox->answers == NULL) &&
(params->where->answer == NULL) &&
(params->query->answer == NULL) &&
(params->batch->answer == NULL)) {
G_fatal_error(
_("At least one option from %s must be specified"),
"cats, ids, coords, bbox, polygon, where, query, batch");
}
}

if (*action_mode == MODE_VERTEX_ADD || *action_mode == MODE_VERTEX_DELETE ||
*action_mode == MODE_VERTEX_MOVE) {
if (params->coord->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"), params->tool->answer,
params->coord->key);
if (*action_mode == MODE_MOVE || *action_mode == MODE_VERTEX_MOVE) {
if (params->move->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"),
params->tool->answer, params->move->key);
}
}
}

if (*action_mode == MODE_CATADD || *action_mode == MODE_CATDEL) {
if (params->cat->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"), params->tool->answer,
params->cat->key);
if (*action_mode == MODE_VERTEX_ADD ||
*action_mode == MODE_VERTEX_DELETE ||
*action_mode == MODE_VERTEX_MOVE) {
if (params->coord->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"),
params->tool->answer, params->coord->key);
}
}
}

if (*action_mode == MODE_ZBULK) {
if (params->bbox->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"), params->tool->answer,
params->bbox->key);
if (*action_mode == MODE_CATADD || *action_mode == MODE_CATDEL) {
if (params->cat->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"),
params->tool->answer, params->cat->key);
}
}
if (params->zbulk->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"), params->tool->answer,
params->zbulk->key);

if (*action_mode == MODE_ZBULK) {
if (params->bbox->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"),
params->tool->answer, params->bbox->key);
}
if (params->zbulk->answers == NULL) {
G_fatal_error(_("Tool %s requires option %s"),
params->tool->answer, params->zbulk->key);
}
}
}
else
*action_mode = MODE_BATCH;

return 1;
}