|
@@ -47,15 +47,14 @@ int main(int argc, char *argv[])
|
|
|
float xmin = 0., ymin = 0., xmax = 0., ymax = 0.;
|
|
|
struct GModule *module;
|
|
|
struct Option *in_opt, *out_opt, *spat_opt, *filter_opt, *class_opt;
|
|
|
- struct Option *id_layer_opt, *return_layer_opt, *n_returns_layer_opt;
|
|
|
+ struct Option *id_layer_opt;
|
|
|
+ struct Option *return_layer_opt;
|
|
|
struct Option *class_layer_opt;
|
|
|
- struct Option *red_layer_opt, *green_layer_opt, *blue_layer_opt;
|
|
|
struct Option *rgb_layer_opt;
|
|
|
struct Option *vector_mask_opt, *vector_mask_field_opt;
|
|
|
struct Option *skip_opt, *preserve_opt, *offset_opt, *limit_opt;
|
|
|
struct Option *outloc_opt, *zrange_opt;
|
|
|
struct Flag *print_flag, *notab_flag, *region_flag, *notopo_flag;
|
|
|
- struct Flag *nocats_flag;
|
|
|
struct Flag *over_flag, *extend_flag, *no_import_flag;
|
|
|
struct Flag *invert_mask_flag;
|
|
|
char buf[2000];
|
|
@@ -119,58 +118,35 @@ int main(int argc, char *argv[])
|
|
|
id_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
id_layer_opt->key = "id_layer";
|
|
|
id_layer_opt->label = _("Layer number to store generated point ID as category");
|
|
|
- id_layer_opt->answer = NULL;
|
|
|
+ id_layer_opt->description =
|
|
|
+ _("Set empty to not store it. Required for attribute table.");
|
|
|
+ id_layer_opt->answer = "1";
|
|
|
id_layer_opt->guisection = _("Categories");
|
|
|
|
|
|
return_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
return_layer_opt->key = "return_layer";
|
|
|
return_layer_opt->label =
|
|
|
- _("Layer number to store return number as category");
|
|
|
+ _("Layer number to store return information as category");
|
|
|
+ return_layer_opt->description = _("Leave empty to not store it");
|
|
|
return_layer_opt->answer = NULL;
|
|
|
return_layer_opt->guisection = _("Categories");
|
|
|
|
|
|
- n_returns_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
- n_returns_layer_opt->key = "n_returns_layer";
|
|
|
- n_returns_layer_opt->label =
|
|
|
- _("Layer number to store number of returns as category");
|
|
|
- n_returns_layer_opt->answer = NULL;
|
|
|
- n_returns_layer_opt->guisection = _("Categories");
|
|
|
-
|
|
|
class_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
class_layer_opt->key = "class_layer";
|
|
|
class_layer_opt->label =
|
|
|
_("Layer number to store class number as category");
|
|
|
+ class_layer_opt->description = _("Leave empty to not store it");
|
|
|
class_layer_opt->answer = NULL;
|
|
|
class_layer_opt->guisection = _("Categories");
|
|
|
|
|
|
rgb_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
rgb_layer_opt->key = "rgb_layer";
|
|
|
rgb_layer_opt->label =
|
|
|
- _("Layer number where RBG colors is stored as category");
|
|
|
+ _("Layer number where RBG colors are stored as category");
|
|
|
+ rgb_layer_opt->description = _("Leave empty to not store it");
|
|
|
rgb_layer_opt->answer = NULL;
|
|
|
rgb_layer_opt->guisection = _("Categories");
|
|
|
|
|
|
- red_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
- red_layer_opt->key = "red_layer";
|
|
|
- red_layer_opt->label =
|
|
|
- _("Layer number where red color is stored as category");
|
|
|
- red_layer_opt->answer = NULL;
|
|
|
- red_layer_opt->guisection = _("Categories");
|
|
|
-
|
|
|
- green_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
- green_layer_opt->key = "green_layer";
|
|
|
- green_layer_opt->label =
|
|
|
- _("Layer number where red color is stored as category");
|
|
|
- green_layer_opt->answer = NULL;
|
|
|
- green_layer_opt->guisection = _("Categories");
|
|
|
-
|
|
|
- blue_layer_opt = G_define_standard_option(G_OPT_V_FIELD);
|
|
|
- blue_layer_opt->key = "blue_layer";
|
|
|
- blue_layer_opt->label =
|
|
|
- _("Layer number where blue color is stored as category");
|
|
|
- blue_layer_opt->answer = NULL;
|
|
|
- blue_layer_opt->guisection = _("Categories");
|
|
|
-
|
|
|
spat_opt = G_define_option();
|
|
|
spat_opt->key = "spatial";
|
|
|
spat_opt->type = TYPE_DOUBLE;
|
|
@@ -290,14 +266,6 @@ int main(int argc, char *argv[])
|
|
|
notab_flag = G_define_standard_flag(G_FLG_V_TABLE);
|
|
|
notab_flag->guisection = _("Speed");
|
|
|
|
|
|
- nocats_flag = G_define_flag();
|
|
|
- nocats_flag->key = 'c';
|
|
|
- nocats_flag->label =
|
|
|
- _("Store only the coordinates");
|
|
|
- nocats_flag->description =
|
|
|
- _("Do not add categories to points and do not create attribute table");
|
|
|
- nocats_flag->guisection = _("Speed");
|
|
|
-
|
|
|
notopo_flag = G_define_standard_flag(G_FLG_V_TOPO);
|
|
|
notopo_flag->guisection = _("Speed");
|
|
|
|
|
@@ -316,9 +284,6 @@ int main(int argc, char *argv[])
|
|
|
no_import_flag->suppress_required = YES;
|
|
|
|
|
|
G_option_exclusive(skip_opt, preserve_opt, NULL);
|
|
|
- G_option_excludes(nocats_flag, id_layer_opt, return_layer_opt,
|
|
|
- n_returns_layer_opt, class_layer_opt, rgb_layer_opt,
|
|
|
- red_layer_opt, green_layer_opt, blue_layer_opt, NULL);
|
|
|
|
|
|
/* The parser checks if the map already exists in current mapset, this is
|
|
|
* wrong if location options is used, so we switch out the check and do it
|
|
@@ -328,10 +293,6 @@ int main(int argc, char *argv[])
|
|
|
if (G_parser(argc, argv))
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
- /* no cats implies no table */
|
|
|
- if (nocats_flag->answer)
|
|
|
- notab_flag->answer = 1;
|
|
|
-
|
|
|
/* Don't crash on cmd line if file not found */
|
|
|
if (access(in_opt->answer, F_OK) != 0) {
|
|
|
G_fatal_error(_("Input file <%s> does not exist"), in_opt->answer);
|
|
@@ -379,62 +340,20 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
int id_layer = 0;
|
|
|
int return_layer = 0;
|
|
|
- int n_returns_layer = 0;
|
|
|
int class_layer = 0;
|
|
|
int rgb_layer = 0;
|
|
|
- int red_layer = 0;
|
|
|
- int green_layer = 0;
|
|
|
- int blue_layer = 0;
|
|
|
if (id_layer_opt->answer)
|
|
|
id_layer = atoi(id_layer_opt->answer);
|
|
|
if (return_layer_opt->answer)
|
|
|
return_layer = atoi(return_layer_opt->answer);
|
|
|
- if (n_returns_layer_opt->answer)
|
|
|
- n_returns_layer = atoi(n_returns_layer_opt->answer);
|
|
|
if (class_layer_opt->answer)
|
|
|
class_layer = atoi(class_layer_opt->answer);
|
|
|
if (rgb_layer_opt->answer)
|
|
|
rgb_layer = atoi(rgb_layer_opt->answer);
|
|
|
- if (red_layer_opt->answer)
|
|
|
- red_layer = atoi(red_layer_opt->answer);
|
|
|
- if (green_layer_opt->answer)
|
|
|
- green_layer = atoi(green_layer_opt->answer);
|
|
|
- if (blue_layer_opt->answer)
|
|
|
- blue_layer = atoi(blue_layer_opt->answer);
|
|
|
- /* If no layer specified by user, force 1 to be used for ids.
|
|
|
- * If id_layer not specified by the attributes table was, find a layer.
|
|
|
- * nocats implies notab and we don't add any layers.
|
|
|
- * Also when layers are set to zero by user, we consider it as if
|
|
|
- * the nocats flag would be specified. We use !id_layer_opt->answer
|
|
|
- * to see that user was the one not setting the id_layer which are
|
|
|
- * are about to turn on.
|
|
|
- * Later on, layer set to 0 is considered as no layer set.
|
|
|
- */
|
|
|
- if (!nocats_flag->answer && !id_layer_opt->answer && !return_layer
|
|
|
- && !n_returns_layer && !class_layer && !rgb_layer && !red_layer
|
|
|
- && !green_layer && !blue_layer) {
|
|
|
- id_layer = 1;
|
|
|
- G_message(_("Storing generated point IDs as categories in the layer %d"), id_layer);
|
|
|
- }
|
|
|
/* no cats forces no table earlier */
|
|
|
if (!notab_flag->answer && !id_layer) {
|
|
|
- /* get the maximum layer number used */
|
|
|
- int max_used_layer;
|
|
|
- max_used_layer = MAX(return_layer, n_returns_layer);
|
|
|
- max_used_layer = MAX(max_used_layer, class_layer);
|
|
|
- max_used_layer = MAX(max_used_layer, rgb_layer);
|
|
|
- max_used_layer = MAX(max_used_layer, red_layer);
|
|
|
- max_used_layer = MAX(max_used_layer, green_layer);
|
|
|
- max_used_layer = MAX(max_used_layer, blue_layer);
|
|
|
- /* get the first free layer number */
|
|
|
- for (i = 1; i <= max_used_layer + 1; i++) {
|
|
|
- if (i != return_layer && i != n_returns_layer
|
|
|
- && i != class_layer && i != rgb_layer
|
|
|
- && i != red_layer && i != green_layer && i != blue_layer)
|
|
|
- break;
|
|
|
- }
|
|
|
- id_layer = i;
|
|
|
- G_message(_("Storing generated point IDs as categories in the layer %d"), id_layer);
|
|
|
+ G_message(_("-%c flag is not set but ID layer is not specified"), notab_flag->key);
|
|
|
+ G_fatal_error(_("ID layer is required to store attribute table"));
|
|
|
}
|
|
|
|
|
|
double zrange_min, zrange_max;
|
|
@@ -672,15 +591,14 @@ int main(int argc, char *argv[])
|
|
|
Vect_append_point(Points, x, y, z);
|
|
|
if (id_layer)
|
|
|
Vect_cat_set(Cats, id_layer, cat);
|
|
|
- if (return_layer)
|
|
|
- Vect_cat_set(Cats, return_layer, LASPoint_GetReturnNumber(LAS_point));
|
|
|
- if (n_returns_layer)
|
|
|
- Vect_cat_set(Cats, n_returns_layer, LASPoint_GetNumberOfReturns(LAS_point));
|
|
|
+ if (return_layer) {
|
|
|
+ int return_c = return_to_cat(return_n, n_returns);
|
|
|
+ Vect_cat_set(Cats, return_layer, return_c);
|
|
|
+ }
|
|
|
if (class_layer)
|
|
|
- Vect_cat_set(Cats, class_layer, LASPoint_GetClassification(LAS_point));
|
|
|
- if (have_color && (rgb_layer || red_layer || green_layer || blue_layer)) {
|
|
|
+ Vect_cat_set(Cats, class_layer, point_class);
|
|
|
+ if (have_color && rgb_layer) {
|
|
|
/* TODO: if attr table, acquired again, performance difference? */
|
|
|
- /* TODO: the getters are called too when separate layers are used */
|
|
|
LASColorH LAS_color = LASPoint_GetColor(LAS_point);
|
|
|
if (rgb_layer) {
|
|
|
int red = LASColor_GetRed(LAS_color);
|
|
@@ -691,12 +609,6 @@ int main(int argc, char *argv[])
|
|
|
rgb = (rgb << 8) + blue;
|
|
|
Vect_cat_set(Cats, rgb_layer, rgb);
|
|
|
}
|
|
|
- if (red_layer)
|
|
|
- Vect_cat_set(Cats, red_layer, LASColor_GetRed(LAS_color));
|
|
|
- if (green_layer)
|
|
|
- Vect_cat_set(Cats, green_layer, LASColor_GetGreen(LAS_color));
|
|
|
- if (blue_layer)
|
|
|
- Vect_cat_set(Cats, blue_layer, LASColor_GetBlue(LAS_color));
|
|
|
}
|
|
|
Vect_write_line(&Map, GV_POINT, Points, Cats);
|
|
|
|