|
@@ -29,81 +29,14 @@
|
|
|
|
|
|
#include "count_decimation.h"
|
|
|
#include "projection.h"
|
|
|
+#include "lidar.h"
|
|
|
+#include "attributes.h"
|
|
|
|
|
|
#ifndef MAX
|
|
|
# define MIN(a,b) ((a<b) ? a : b)
|
|
|
# define MAX(a,b) ((a>b) ? a : b)
|
|
|
#endif
|
|
|
|
|
|
-#define LAS_ALL 0
|
|
|
-#define LAS_FIRST 1
|
|
|
-#define LAS_LAST 2
|
|
|
-#define LAS_MID 3
|
|
|
-
|
|
|
-/*
|
|
|
- * ASPRS Standard LIDAR Point Classes
|
|
|
- * Classification Value (bits 0:4) : Meaning
|
|
|
- * 0 : Created, never classified
|
|
|
- * 1 : Unclassified
|
|
|
- * 2 : Ground
|
|
|
- * 3 : Low Vegetation
|
|
|
- * 4 : Medium Vegetation
|
|
|
- * 5 : High Vegetation
|
|
|
- * 6 : Building
|
|
|
- * 7 : Low Point (noise)
|
|
|
- * 8 : Model Key-point (mass point)
|
|
|
- * 9 : Water
|
|
|
- * 10 : Reserved for ASPRS Definition
|
|
|
- * 11 : Reserved for ASPRS Definition
|
|
|
- * 12 : Overlap Points
|
|
|
- * 13-31 : Reserved for ASPRS Definition
|
|
|
- */
|
|
|
-
|
|
|
-/* Classification Bit Field Encoding
|
|
|
- * Bits | Field Name | Description
|
|
|
- * 0-4 | Classification | Standard ASPRS classification as defined in the
|
|
|
- * above classification table.
|
|
|
- * 5 | Synthetic | If set then this point was created by a technique
|
|
|
- * other than LIDAR collection such as digitized from
|
|
|
- * a photogrammetric stereo model or by traversing
|
|
|
- * a waveform.
|
|
|
- * 6 | Key-point | If set, this point is considered to be a model
|
|
|
- * key-point and thus generally should not be withheld
|
|
|
- * in a thinning algorithm.
|
|
|
- * 7 | Withheld | If set, this point should not be included in
|
|
|
- * processing (synonymous with Deleted).
|
|
|
-*/
|
|
|
-
|
|
|
-struct class_table
|
|
|
-{
|
|
|
- int code;
|
|
|
- char *name;
|
|
|
-};
|
|
|
-
|
|
|
-static struct class_table class_val[] = {
|
|
|
- {0, "Created, never classified"},
|
|
|
- {1, "Unclassified"},
|
|
|
- {2, "Ground"},
|
|
|
- {3, "Low Vegetation"},
|
|
|
- {4, "Medium Vegetation"},
|
|
|
- {5, "High Vegetation"},
|
|
|
- {6, "Building"},
|
|
|
- {7, "Low Point (noise)"},
|
|
|
- {8, "Model Key-point (mass point)"},
|
|
|
- {9, "Water"},
|
|
|
- {10, "Reserved for ASPRS Definition"},
|
|
|
- {11, "Reserved for ASPRS Definition"},
|
|
|
- {12, "Overlap Points"},
|
|
|
- {13 /* 13 - 31 */, "Reserved for ASPRS Definition"},
|
|
|
- {0, 0}
|
|
|
-};
|
|
|
-
|
|
|
-static struct class_table class_type[] = {
|
|
|
- {5, "Synthetic"},
|
|
|
- {6, "Key-point"},
|
|
|
- {7, "Withheld"},
|
|
|
- {0, 0}
|
|
|
-};
|
|
|
|
|
|
void print_lasinfo(LASHeaderH LAS_header, LASSRSH LAS_srs);
|
|
|
|
|
@@ -138,7 +71,6 @@ int main(int argc, char *argv[])
|
|
|
/* Attributes */
|
|
|
struct field_info *Fi;
|
|
|
dbDriver *driver;
|
|
|
- dbString sql, strval;
|
|
|
|
|
|
/* LAS */
|
|
|
LASReaderH LAS_reader;
|
|
@@ -622,9 +554,6 @@ int main(int argc, char *argv[])
|
|
|
TRUE);
|
|
|
}
|
|
|
|
|
|
- db_init_string(&sql);
|
|
|
- db_init_string(&strval);
|
|
|
-
|
|
|
if (!outloc_opt->answer) { /* Check if the map exists */
|
|
|
if (G_find_vector2(out_opt->answer, G_mapset())) {
|
|
|
if (overwrite)
|
|
@@ -661,116 +590,8 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
/* Add DB link */
|
|
|
if (!notab_flag->answer) {
|
|
|
- char *cat_col_name = GV_KEY_COLUMN;
|
|
|
-
|
|
|
- Fi = Vect_default_field_info(&Map, id_layer, NULL, GV_1TABLE);
|
|
|
-
|
|
|
- Vect_map_add_dblink(&Map, id_layer, out_opt->answer, Fi->table,
|
|
|
- cat_col_name, Fi->database, Fi->driver);
|
|
|
-
|
|
|
- /* check available LAS info, depends on POINT DATA RECORD FORMAT [0-5] */
|
|
|
- /* X (double),
|
|
|
- * Y (double),
|
|
|
- * Z (double),
|
|
|
- * intensity (double),
|
|
|
- * return number (int),
|
|
|
- * number of returns (int),
|
|
|
- * scan direction (int),
|
|
|
- * flight line edge (int),
|
|
|
- * classification type (char),
|
|
|
- * class (char),
|
|
|
- * time (double) (FORMAT 1, 3, 4, 5),
|
|
|
- * scan angle rank (int),
|
|
|
- * source ID (int),
|
|
|
- * user data (char), ???
|
|
|
- * red (int) (FORMAT 2, 3, 5),
|
|
|
- * green (int) (FORMAT 2, 3, 5),
|
|
|
- * blue (int) (FORMAT 2, 3, 5)*/
|
|
|
-
|
|
|
- /* Create table */
|
|
|
- sprintf(buf, "create table %s (%s integer", Fi->table,
|
|
|
- cat_col_name);
|
|
|
- db_set_string(&sql, buf);
|
|
|
-
|
|
|
- /* x, y, z */
|
|
|
- sprintf(buf, ", x_coord double precision");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- sprintf(buf, ", y_coord double precision");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- sprintf(buf, ", z_coord double precision");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* intensity */
|
|
|
- sprintf(buf, ", intensity integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* return number */
|
|
|
- sprintf(buf, ", return integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* number of returns */
|
|
|
- sprintf(buf, ", n_returns integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* scan direction */
|
|
|
- sprintf(buf, ", scan_dir integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* flight line edge */
|
|
|
- sprintf(buf, ", edge integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* classification type */
|
|
|
- sprintf(buf, ", cl_type varchar(20)");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* classification class */
|
|
|
- sprintf(buf, ", class varchar(40)");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* GPS time */
|
|
|
- if (have_time) {
|
|
|
- sprintf(buf, ", gps_time double precision");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- }
|
|
|
- /* scan angle */
|
|
|
- sprintf(buf, ", angle integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* source id */
|
|
|
- sprintf(buf, ", src_id integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* user data */
|
|
|
- sprintf(buf, ", usr_data integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* colors */
|
|
|
- if (have_color) {
|
|
|
- sprintf(buf, ", red integer, green integer, blue integer");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- sprintf(buf, ", GRASSRGB varchar(11)");
|
|
|
- db_append_string(&sql, buf);
|
|
|
- }
|
|
|
-
|
|
|
- db_append_string(&sql, ")");
|
|
|
- G_debug(3, "%s", db_get_string(&sql));
|
|
|
-
|
|
|
- driver =
|
|
|
- db_start_driver_open_database(Fi->driver,
|
|
|
- Vect_subst_var(Fi->database,
|
|
|
- &Map));
|
|
|
- if (driver == NULL) {
|
|
|
- G_fatal_error(_("Unable open database <%s> by driver <%s>"),
|
|
|
- Vect_subst_var(Fi->database, &Map), Fi->driver);
|
|
|
- }
|
|
|
- db_set_error_handler_driver(driver);
|
|
|
-
|
|
|
- if (db_execute_immediate(driver, &sql) != DB_OK) {
|
|
|
- G_fatal_error(_("Unable to create table: '%s'"),
|
|
|
- db_get_string(&sql));
|
|
|
- }
|
|
|
-
|
|
|
- if (db_create_index2(driver, Fi->table, cat_col_name) != DB_OK)
|
|
|
- G_warning(_("Unable to create index for table <%s>, key <%s>"),
|
|
|
- Fi->table, cat_col_name);
|
|
|
-
|
|
|
- if (db_grant_on_table
|
|
|
- (driver, Fi->table, DB_PRIV_SELECT,
|
|
|
- DB_GROUP | DB_PUBLIC) != DB_OK)
|
|
|
- G_fatal_error(_("Unable to grant privileges on table <%s>"),
|
|
|
- Fi->table);
|
|
|
-
|
|
|
- db_begin_transaction(driver);
|
|
|
+ create_table_for_lidar(&Map, out_opt->answer, id_layer, &driver,
|
|
|
+ &Fi, have_time, have_color);
|
|
|
}
|
|
|
|
|
|
struct Map_info vector_mask;
|
|
@@ -937,81 +758,8 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
/* Attributes */
|
|
|
if (!notab_flag->answer) {
|
|
|
- char class_flag;
|
|
|
- int las_class_type, las_class;
|
|
|
-
|
|
|
- /* use LASPoint_Validate (LASPointH hPoint) to check for
|
|
|
- * return number, number of returns, scan direction, flight line edge,
|
|
|
- * classification, scan angle rank */
|
|
|
- sprintf(buf, "insert into %s values ( %d", Fi->table, cat);
|
|
|
- db_set_string(&sql, buf);
|
|
|
-
|
|
|
- /* x, y, z */
|
|
|
- sprintf(buf, ", %f", x);
|
|
|
- db_append_string(&sql, buf);
|
|
|
- sprintf(buf, ", %f", y);
|
|
|
- db_append_string(&sql, buf);
|
|
|
- sprintf(buf, ", %f", z);
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* intensity */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetIntensity(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* return number */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetReturnNumber(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* number of returns */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetNumberOfReturns(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* scan direction */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetScanDirection(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* flight line edge */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetFlightLineEdge(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- class_flag = LASPoint_GetClassification(LAS_point);
|
|
|
- /* classification type int or char ? */
|
|
|
- las_class_type = class_flag / 32;
|
|
|
- sprintf(buf, ", \'%s\'", class_type[las_class_type].name);
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* classification class int or char ? */
|
|
|
- las_class = class_flag % 32;
|
|
|
- if (las_class > 13)
|
|
|
- las_class = 13;
|
|
|
- sprintf(buf, ", \'%s\'", class_val[las_class].name);
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* GPS time */
|
|
|
- if (have_time) {
|
|
|
- sprintf(buf, ", %f", LASPoint_GetTime(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- }
|
|
|
- /* scan angle */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetScanAngleRank(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* source id */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetPointSourceId(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* user data */
|
|
|
- sprintf(buf, ", %d", LASPoint_GetUserData(LAS_point));
|
|
|
- db_append_string(&sql, buf);
|
|
|
- /* colors */
|
|
|
- if (have_color) {
|
|
|
- LASColorH LAS_color = LASPoint_GetColor(LAS_point);
|
|
|
- int red = LASColor_GetRed(LAS_color);
|
|
|
- int green = LASColor_GetGreen(LAS_color);
|
|
|
- int blue = LASColor_GetBlue(LAS_color);
|
|
|
-
|
|
|
- sprintf(buf, ", %d, %d, %d", red, green, blue);
|
|
|
- db_append_string(&sql, buf);
|
|
|
- sprintf(buf, ", \"%03d:%03d:%03d\"", red, green, blue);
|
|
|
- db_append_string(&sql, buf);
|
|
|
- }
|
|
|
- db_append_string(&sql, " )");
|
|
|
- G_debug(3, "%s", db_get_string(&sql));
|
|
|
-
|
|
|
- if (db_execute_immediate(driver, &sql) != DB_OK) {
|
|
|
- G_fatal_error(_("Cannot insert new row: %s"),
|
|
|
- db_get_string(&sql));
|
|
|
- }
|
|
|
+ las_point_to_attributes(Fi, driver, cat, LAS_point, x, y, z,
|
|
|
+ have_time, have_color);
|
|
|
}
|
|
|
|
|
|
if (count_decimation_is_end(&count_decimation_control))
|