Changeset 66594
- Timestamp:
- Oct 24, 2015, 8:10:35 PM (9 years ago)
- Location:
- grass/trunk/raster/r.in.lidar
- Files:
-
- 2 added
- 2 edited
-
info.c (added)
-
local_proto.h (modified) (3 diffs)
-
main.c (modified) (5 diffs)
-
projection.c (added)
Legend:
- Unmodified
- Added
- Removed
-
grass/trunk/raster/r.in.lidar/local_proto.h
r66593 r66594 22 22 23 23 #include <grass/gis.h> 24 #include <grass/raster.h> 24 25 #include <liblas/capi/liblas.h> 25 26 … … 41 42 #define METHOD_TRIMMEAN 13 42 43 43 /* main.c */44 /* info.c */ 44 45 void print_lasinfo(LASHeaderH, LASSRSH); 45 46 int scan_bounds(LASReaderH, int, int, double, struct Cell_head *); … … 53 54 int update_sumsq(void *, int, int, int, RASTER_MAP_TYPE, double); 54 55 56 /* projection.c */ 57 void projection_mismatch_report(struct Cell_head cellhd, 58 struct Cell_head loc_wind, 59 struct Key_Value *loc_proj_info, 60 struct Key_Value *loc_proj_units, 61 struct Key_Value *proj_info, 62 struct Key_Value *proj_units, 63 int err); 64 void projection_check_wkt(struct Cell_head cellhd, 65 struct Cell_head loc_wind, 66 const char *projstr, 67 int override, 68 int shellstyle); 55 69 /* raster reading */ 56 70 int row_array_get_value_row_col(void *array, int arr_row, int arr_col, -
grass/trunk/raster/r.in.lidar/main.c
r66593 r66594 4 4 * 5 5 * AUTHOR(S): Markus Metz 6 * Vaclav Petras (base raster addition and refactoring) 6 7 * Based on r.in.xyz by Hamish Bowman, Volker Wichmann 7 8 * … … 9 10 * aggregate statistics. 10 11 * 11 * COPYRIGHT: (C) 2011 Markus Metz and the The GRASS Development Team12 * COPYRIGHT: (C) 2011-2015 Markus Metz and the The GRASS Development Team 12 13 * 13 14 * This program is free software under the GNU General Public … … 164 165 int return_filter; 165 166 166 struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;167 struct Key_Value *proj_info, *proj_units;168 167 const char *projstr; 169 168 struct Cell_head cellhd, loc_wind; … … 374 373 375 374 /* Fetch input map projection in GRASS form. */ 376 proj_info = NULL;377 proj_units = NULL;378 375 projstr = LASSRS_GetWKT_CompoundOK(LAS_srs); 379 376 380 377 if (TRUE) { 381 int err = 0; 382 char error_msg[8192]; 383 384 /* Projection only required for checking so convert non-interactively */ 385 if (GPJ_wkt_to_grass(&cellhd, &proj_info, 386 &proj_units, projstr, 0) < 0) 387 G_warning(_("Unable to convert input map projection information to " 388 "GRASS format for checking")); 389 390 /* Does the projection of the current location match the dataset? */ 391 /* G_get_window seems to be unreliable if the location has been changed */ 392 G_get_set_window(&loc_wind); /* TODO: v.in.lidar uses G_get_default_window() */ 393 /* fetch LOCATION PROJ info */ 394 if (loc_wind.proj != PROJECTION_XY) { 395 loc_proj_info = G_get_projinfo(); 396 loc_proj_units = G_get_projunits(); 397 } 398 399 if (over_flag->answer) { 400 cellhd.proj = loc_wind.proj; 401 cellhd.zone = loc_wind.zone; 402 G_message(_("Over-riding projection check")); 403 } 404 else if (loc_wind.proj != cellhd.proj 405 || (err = 406 G_compare_projections(loc_proj_info, loc_proj_units, 407 proj_info, proj_units)) != TRUE) { 408 int i_value; 409 410 strcpy(error_msg, 411 _("Projection of dataset does not" 412 " appear to match current location.\n\n")); 413 414 /* TODO: output this info sorted by key: */ 415 if (loc_wind.proj != cellhd.proj || err != -2) { 416 if (loc_proj_info != NULL) { 417 strcat(error_msg, _("GRASS LOCATION PROJ_INFO is:\n")); 418 for (i_value = 0; i_value < loc_proj_info->nitems; 419 i_value++) 420 sprintf(error_msg + strlen(error_msg), "%s: %s\n", 421 loc_proj_info->key[i_value], 422 loc_proj_info->value[i_value]); 423 strcat(error_msg, "\n"); 424 } 425 426 if (proj_info != NULL) { 427 strcat(error_msg, _("Import dataset PROJ_INFO is:\n")); 428 for (i_value = 0; i_value < proj_info->nitems; i_value++) 429 sprintf(error_msg + strlen(error_msg), "%s: %s\n", 430 proj_info->key[i_value], 431 proj_info->value[i_value]); 432 } 433 else { 434 strcat(error_msg, _("Import dataset PROJ_INFO is:\n")); 435 if (cellhd.proj == PROJECTION_XY) 436 sprintf(error_msg + strlen(error_msg), 437 "Dataset proj = %d (unreferenced/unknown)\n", 438 cellhd.proj); 439 else if (cellhd.proj == PROJECTION_LL) 440 sprintf(error_msg + strlen(error_msg), 441 "Dataset proj = %d (lat/long)\n", 442 cellhd.proj); 443 else if (cellhd.proj == PROJECTION_UTM) 444 sprintf(error_msg + strlen(error_msg), 445 "Dataset proj = %d (UTM), zone = %d\n", 446 cellhd.proj, cellhd.zone); 447 else 448 sprintf(error_msg + strlen(error_msg), 449 "Dataset proj = %d (unknown), zone = %d\n", 450 cellhd.proj, cellhd.zone); 451 } 452 } 453 else { 454 if (loc_proj_units != NULL) { 455 strcat(error_msg, "GRASS LOCATION PROJ_UNITS is:\n"); 456 for (i_value = 0; i_value < loc_proj_units->nitems; 457 i_value++) 458 sprintf(error_msg + strlen(error_msg), "%s: %s\n", 459 loc_proj_units->key[i_value], 460 loc_proj_units->value[i_value]); 461 strcat(error_msg, "\n"); 462 } 463 464 if (proj_units != NULL) { 465 strcat(error_msg, "Import dataset PROJ_UNITS is:\n"); 466 for (i_value = 0; i_value < proj_units->nitems; i_value++) 467 sprintf(error_msg + strlen(error_msg), "%s: %s\n", 468 proj_units->key[i_value], 469 proj_units->value[i_value]); 470 } 471 } 472 sprintf(error_msg + strlen(error_msg), 473 _("\nIn case of no significant differences in the projection definitions," 474 " use the -o flag to ignore them and use" 475 " current location definition.\n")); 476 strcat(error_msg, 477 _("Consider generating a new location with 'location' parameter" 478 " from input data set.\n")); 479 G_fatal_error("%s", error_msg); 480 } 481 else if (!shell_style->answer) { 482 G_message(_("Projection of input dataset and current location " 483 "appear to match")); 484 } 378 projection_check_wkt(cellhd, loc_wind, projstr, over_flag->answer, shell_style->answer); 485 379 } 486 380 … … 1316 1210 1317 1211 } 1318 1319 void print_lasinfo(LASHeaderH LAS_header, LASSRSH LAS_srs)1320 {1321 char *las_srs_proj4 = LASSRS_GetProj4(LAS_srs);1322 int las_point_format = LASHeader_GetDataFormatId(LAS_header);1323 1324 fprintf(stdout, "\nUsing LAS Library Version '%s'\n\n",1325 LAS_GetFullVersion());1326 fprintf(stdout, "LAS File Version: %d.%d\n",1327 LASHeader_GetVersionMajor(LAS_header),1328 LASHeader_GetVersionMinor(LAS_header));1329 fprintf(stdout, "System ID: '%s'\n",1330 LASHeader_GetSystemId(LAS_header));1331 fprintf(stdout, "Generating Software: '%s'\n",1332 LASHeader_GetSoftwareId(LAS_header));1333 fprintf(stdout, "File Creation Day/Year: %d/%d\n",1334 LASHeader_GetCreationDOY(LAS_header),1335 LASHeader_GetCreationYear(LAS_header));1336 fprintf(stdout, "Point Data Format: %d\n",1337 las_point_format);1338 fprintf(stdout, "Number of Point Records: %d\n",1339 LASHeader_GetPointRecordsCount(LAS_header));1340 fprintf(stdout, "Number of Points by Return: %d %d %d %d %d\n",1341 LASHeader_GetPointRecordsByReturnCount(LAS_header, 0),1342 LASHeader_GetPointRecordsByReturnCount(LAS_header, 1),1343 LASHeader_GetPointRecordsByReturnCount(LAS_header, 2),1344 LASHeader_GetPointRecordsByReturnCount(LAS_header, 3),1345 LASHeader_GetPointRecordsByReturnCount(LAS_header, 4));1346 fprintf(stdout, "Scale Factor X Y Z: %g %g %g\n",1347 LASHeader_GetScaleX(LAS_header),1348 LASHeader_GetScaleY(LAS_header),1349 LASHeader_GetScaleZ(LAS_header));1350 fprintf(stdout, "Offset X Y Z: %g %g %g\n",1351 LASHeader_GetOffsetX(LAS_header),1352 LASHeader_GetOffsetY(LAS_header),1353 LASHeader_GetOffsetZ(LAS_header));1354 fprintf(stdout, "Min X Y Z: %g %g %g\n",1355 LASHeader_GetMinX(LAS_header),1356 LASHeader_GetMinY(LAS_header),1357 LASHeader_GetMinZ(LAS_header));1358 fprintf(stdout, "Max X Y Z: %g %g %g\n",1359 LASHeader_GetMaxX(LAS_header),1360 LASHeader_GetMaxY(LAS_header),1361 LASHeader_GetMaxZ(LAS_header));1362 if (las_srs_proj4 && strlen(las_srs_proj4) > 0) {1363 fprintf(stdout, "Spatial Reference:\n");1364 fprintf(stdout, "%s\n", las_srs_proj4);1365 }1366 else {1367 fprintf(stdout, "Spatial Reference: None\n");1368 }1369 1370 fprintf(stdout, "\nData Fields:\n");1371 fprintf(stdout, " 'X'\n 'Y'\n 'Z'\n 'Intensity'\n 'Return Number'\n");1372 fprintf(stdout, " 'Number of Returns'\n 'Scan Direction'\n");1373 fprintf(stdout, " 'Flighline Edge'\n 'Classification'\n 'Scan Angle Rank'\n");1374 fprintf(stdout, " 'User Data'\n 'Point Source ID'\n");1375 if (las_point_format == 1 || las_point_format == 3 || las_point_format == 4 || las_point_format == 5) {1376 fprintf(stdout, " 'GPS Time'\n");1377 }1378 if (las_point_format == 2 || las_point_format == 3 || las_point_format == 5) {1379 fprintf(stdout, " 'Red'\n 'Green'\n 'Blue'\n");1380 }1381 fprintf(stdout, "\n");1382 fflush(stdout);1383 1384 return;1385 }1386 1387 1388 int scan_bounds(LASReaderH LAS_reader, int shell_style, int extents,1389 double zscale, struct Cell_head *region)1390 {1391 unsigned long line;1392 int first;1393 double min_x, max_x, min_y, max_y, min_z, max_z;1394 double x, y, z;1395 LASPointH LAS_point;1396 1397 line = 0;1398 first = TRUE;1399 1400 /* init to nan in case no points are found */1401 min_x = max_x = min_y = max_y = min_z = max_z = 0.0 / 0.0;1402 1403 G_verbose_message(_("Scanning data ..."));1404 1405 LASReader_Seek(LAS_reader, 0);1406 1407 while ((LAS_point = LASReader_GetNextPoint(LAS_reader)) != NULL) {1408 line++;1409 1410 if (!LASPoint_IsValid(LAS_point)) {1411 continue;1412 }1413 1414 x = LASPoint_GetX(LAS_point);1415 y = LASPoint_GetY(LAS_point);1416 z = LASPoint_GetZ(LAS_point);1417 1418 if (first) {1419 min_x = x;1420 max_x = x;1421 min_y = y;1422 max_y = y;1423 min_z = z;1424 max_z = z;1425 first = FALSE;1426 }1427 else {1428 if (x < min_x)1429 min_x = x;1430 if (x > max_x)1431 max_x = x;1432 if (y < min_y)1433 min_y = y;1434 if (y > max_y)1435 max_y = y;1436 if (z < min_z)1437 min_z = z;1438 if (z > max_z)1439 max_z = z;1440 }1441 }1442 1443 if (!extents) {1444 if (!shell_style) {1445 fprintf(stderr, _("Range: min max\n"));1446 fprintf(stdout, "x: %11f %11f\n", min_x, max_x);1447 fprintf(stdout, "y: %11f %11f\n", min_y, max_y);1448 fprintf(stdout, "z: %11f %11f\n", min_z * zscale, max_z * zscale);1449 }1450 else1451 fprintf(stdout, "n=%f s=%f e=%f w=%f b=%f t=%f\n",1452 max_y, min_y, max_x, min_x, min_z * zscale, max_z * zscale);1453 1454 G_debug(1, "Processed %lu points.", line);1455 G_debug(1, "region template: g.region n=%f s=%f e=%f w=%f",1456 max_y, min_y, max_x, min_x);1457 }1458 else {1459 region->east = max_x;1460 region->west = min_x;1461 region->north = max_y;1462 region->south = min_y;1463 }1464 1465 return 0;1466 }
Note:
See TracChangeset
for help on using the changeset viewer.
