30
30
#include <stdlib.h>
31
#include <sys/types.h>
32
33
#include <grass/gis.h>
33
#include <grass/G3d.h>
34
#include <grass/raster.h>
35
#include <grass/raster3d.h>
34
36
#include <grass/dbmi.h>
35
#include <grass/Vect.h>
37
#include <grass/vector.h>
36
38
#include <grass/bitmap.h>
37
39
#include <grass/glocale.h>
107
109
G_fatal_error(_("Column type of wcolumn is not supported (must be integer or double)"));
110
G_fatal_error("Unable to select data from table");
112
G_fatal_error(_("Unable to select data from table"));
111
113
G_message("%d records selected from table", nrec);
113
115
if (scol != NULL) {
118
120
sctype = cvarr.ctype;
120
122
if (sctype == -1)
121
G_fatal_error("Cannot read column type of smooth column");
123
G_fatal_error(_("Cannot read column type of smooth column"));
122
124
if (sctype == DB_C_TYPE_DATETIME)
124
("Column type of smooth column (datetime) is not supported");
126
(_("Column type of smooth column (datetime) is not supported"));
125
127
if (sctype != DB_C_TYPE_INT && sctype != DB_C_TYPE_DOUBLE)
126
128
G_fatal_error(_("Column type of smooth column is not supported (must be integer or double)"));
203
205
((c1 >= 0) && (c2 >= 0) && (c3 >= 0) && (c4 >= 0) && (c5 >= 0) &&
206
G_warning("some points outside of region -- will ignore...");
208
G_warning(_("Some points outside of region -- will ignore..."));
211
213
if (!(point = point_new(x, y, z, w, sm))) {
212
clean_fatal_error("Cannot allocate memory for point");
215
G_fatal_error(_("Cannot allocate memory for point"));
215
218
a = OT_insert_oct(point, root);
220
G_warning("Can't insert %lf,%lf,%lf,%lf,%lf a=%d\n", x, y, z,
223
G_warning(_("Can't insert %lf,%lf,%lf,%lf,%lf a=%d"), x, y, z,
272
275
totsegm = translate_oct(root, ((struct octdata *)(root->data))->x_orig,
273
276
((struct octdata *)(root->data))->y_orig,
274
277
((struct octdata *)(root->data))->z_orig, nz);
276
clean_fatal_error("Zero segments!");
280
G_fatal_error(_("Zero segments!"));
278
283
((struct octdata *)(root->data))->x_orig = 0;
279
284
((struct octdata *)(root->data))->y_orig = 0;
303
308
fprintf(stderr, "\n");
304
309
if (OUTRANGE > 0)
306
("There are points outside specified 2D/3D region--ignored %d points (total points: %d)",
311
(_("There are points outside specified 2D/3D region--ignored %d points (total points: %d)"),
310
("Points are more dense than specified 'DMIN'--ignored %d points (remain %d)",
315
(_("Points are more dense than specified 'DMIN'--ignored %d points (remain %d)"),
311
316
NPOINT, k - NPOINT);
312
317
NPOINT = k - NPOINT - NPT - OUTRANGE;
313
318
if (NPOINT < KMIN) {
314
319
if (NPOINT != 0) {
316
("%d points given for interpolation (after thinning) is less than given NPMIN=%d",
321
(_("%d points given for interpolation (after thinning) is less than given NPMIN=%d"),
334
339
if (NPOINT < KMAXPOINTS && KMAX != KMAXPOINTS)
336
("There is less than %d points for interpolation, no segmentation is necessary, to run the program faster, set segmax=%d (see manual)",
341
(_("There is less than %d points for interpolation, no segmentation is necessary, to run the program faster, set segmax=%d (see manual)"),
337
342
KMAXPOINTS, KMAXPOINTS);
339
344
deltx = xmax - xmin;
358
363
/** create a bitmap mask from given raster map **/
359
364
if (maskmap != NULL) {
360
mapsetm = G_find_cell2(maskmap, "");
365
mapsetm = G_find_raster2(maskmap, "");
362
sprintf(buf, "mask raster map [%s] not found\n", maskmap);
363
clean_fatal_error(buf);
368
G_fatal_error(_("Mask raster map [%s] not found"), maskmap);
365
370
bitmask = BM_create(nsizc, nsizr);
366
cellmask = G_allocate_cell_buf();
367
cfmask = G_open_cell_old(maskmap, mapsetm);
371
cellmask = Rast_allocate_c_buf();
372
cfmask = Rast_open_old(maskmap, mapsetm);
368
373
for (i = 0; i < nsizr; i++) {
369
374
irev = nsizr - i - 1;
370
G_get_map_row(cfmask, cellmask, i);
375
Rast_get_c_row(cfmask, cellmask, i);
371
376
for (j = 0; j < nsizc; j++) {
372
if ((cellmask[j] == 0) || G_is_c_null_value(&cellmask[j]))
377
if ((cellmask[j] == 0) || Rast_is_c_null_value(&cellmask[j]))
373
378
BM_set(bitmask, j, irev, 0);
375
380
BM_set(bitmask, j, irev, 1);
378
G_message("bitmap mask created");
383
G_message(_("Bitmap mask created"));
394
399
int i, iarc, cnt;
400
404
if ((cellinp != NULL) && (cellout != NULL)) {
401
cell = G_allocate_f_raster_buf();
405
cell = Rast_allocate_f_buf();
403
407
for (i = 0; i < nsizr; i++) {
404
408
/* seek to the right row */
406
(Tmp_fd_cell, (long)((nsizr - 1 - i) * nsizc * sizeof(FCELL)),
408
G_fatal_error("cannot fseek to the right spot");
410
(Tmp_fd_cell, ((off_t)(nsizr - 1 - i) * nsizc * sizeof(FCELL)),
409
412
fread(cell, sizeof(FCELL), nsizc, Tmp_fd_cell);
410
G_put_f_raster_row(fdcout, cell);
413
Rast_put_f_row(fdcout, cell);
416
419
current_region.top = nsizl * tb_res_in + z_orig_in;
418
421
if (!(data = (float *)G_malloc(sizeof(float) * nsizr * nsizc * nsizl))) {
419
clean_fatal_error("Error: out of memory");
423
G_fatal_error(_("Out of memory"));
422
426
/*** Write elevation results ***/
423
427
if (outz != NULL) {
425
cf1 = G3d_openCellNew(outz, FCELL_TYPE,
426
G3D_USE_CACHE_DEFAULT, ¤t_region);
429
cf1 = Rast3d_open_new_opt_tile_size(outz, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
427
430
if (cf1 == NULL) {
428
sprintf(buff, "Can't open %s for writing ", outz);
429
clean_fatal_error(buff);
432
G_fatal_error(_("Unable to open %s for writing"), outz);
432
435
/* seek to the beginning */
433
fseek(Tmp_fd_z, 0L, 0);
436
G_fseek(Tmp_fd_z, 0L, 0);
435
438
/* Read data in from temp file */
437
440
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_z);
439
clean_fatal_error("Cannot read data from temp file");
443
G_fatal_error(_("Unable to read data from temp file"));
442
447
for (iarc = 0; iarc < nsizl; iarc++) {
450
455
value = data[cnt];
452
G3d_setNullValue(&value, 1, FCELL_TYPE);
453
if (G3d_putFloat(cf1, x, y, iarc, value) == 0) {
455
"Error writing cell (%d,%d,%d) with value %f",
457
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
458
if (Rast3d_put_float(cf1, x, y, iarc, value) == 0) {
461
_("Error writing cell (%d,%d,%d) with value %f"),
456
462
x, y, iarc, value);
457
clean_fatal_error(buff);
466
471
/* Close the file */
467
if (G3d_closeCell(cf1) == 0) {
468
sprintf(buff, "Error closing output file %s ", outz);
469
clean_fatal_error(buff);
472
if (Rast3d_close(cf1) == 0) {
474
G_fatal_error(_("Error closing output file %s"), outz);
471
476
G_message(_("3D raster map <%s> created"), outz);
474
479
/*** Write out the gradient results ***/
475
480
if (gradient != NULL) {
477
cf2 = G3d_openCellNew(gradient, FCELL_TYPE,
478
G3D_USE_CACHE_DEFAULT, ¤t_region);
482
cf2 = Rast3d_open_new_opt_tile_size(gradient, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
479
483
if (cf2 == NULL) {
480
sprintf(buff, "Can't open %s for writing ", gradient);
481
clean_fatal_error(buff);
485
G_fatal_error(_("Unable to open %s for writing"), gradient);
484
488
/* seek to the beginning */
485
fseek(Tmp_fd_dx, 0L, 0);
489
G_fseek(Tmp_fd_dx, 0L, 0);
487
491
/* Read data in from temp file */
489
493
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dx);
491
clean_fatal_error("Cannot read data from temp file");
496
G_fatal_error(_("Unable to read data from temp file"));
494
500
for (iarc = 0; iarc < nsizl; iarc++) {
502
508
value = data[cnt];
504
G3d_setNullValue(&value, 1, FCELL_TYPE);
505
if (G3d_putFloat(cf2, x, y, iarc, value) == 0) {
507
"Error writing cell (%d,%d,%d) with value %f",
510
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
511
if (Rast3d_put_float(cf2, x, y, iarc, value) == 0) {
514
_("Error writing cell (%d,%d,%d) with value %f"),
508
515
x, y, iarc, value);
509
clean_fatal_error(buff);
518
524
/* Close the file */
519
if (G3d_closeCell(cf2) == 0) {
520
sprintf(buff, "Error closing output file %s ", gradient);
521
clean_fatal_error(buff);
525
if (Rast3d_close(cf2) == 0) {
527
G_fatal_error(_("Error closing output file %s"), gradient);
523
529
G_message(_("3D raster map <%s> created"), gradient);
526
532
/*** Write out aspect1 results ***/
527
533
if (aspect1 != NULL) {
529
cf3 = G3d_openCellNew(aspect1, FCELL_TYPE,
530
G3D_USE_CACHE_DEFAULT, ¤t_region);
535
cf3 = Rast3d_open_new_opt_tile_size(aspect1, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
531
536
if (cf3 == NULL) {
532
sprintf(buff, "Can't open %s for writing ", aspect1);
533
clean_fatal_error(buff);
538
G_fatal_error(_("Unable to open %s for writing"), aspect1);
536
541
/* seek to the beginning */
537
fseek(Tmp_fd_dy, 0L, 0);
542
G_fseek(Tmp_fd_dy, 0L, 0);
539
544
/* Read data in from temp file */
541
546
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dy);
543
clean_fatal_error("Cannot read data from temp file");
549
G_fatal_error(_("Unable to read data from temp file"));
546
553
for (iarc = 0; iarc < nsizl; iarc++) {
551
558
bmask = BM_get(bitmask, x, nsizr - y - 1);
561
value = data[cnt] * 180 / M_PI;
556
G3d_setNullValue(&value, 1, FCELL_TYPE);
557
if (G3d_putFloat(cf3, x, y, iarc, value) == 0) {
559
"Error writing cell (%d,%d,%d) with value %f",
563
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
564
if (Rast3d_put_float(cf3, x, y, iarc, value) == 0) {
567
_("Error writing cell (%d,%d,%d) with value %f"),
560
568
x, y, iarc, value);
561
clean_fatal_error(buff);
570
577
/* Close the file */
571
if (G3d_closeCell(cf3) == 0) {
572
sprintf(buff, "Error closing output file %s ", aspect1);
573
clean_fatal_error(buff);
578
if (Rast3d_close(cf3) == 0) {
580
G_fatal_error(_("Error closing output file %s"), aspect1);
575
582
G_message(_("3D raster map <%s> created"), aspect1);
578
585
/*** Write out aspect2 results ***/
579
586
if (aspect2 != NULL) {
581
cf4 = G3d_openCellNew(aspect2, FCELL_TYPE,
582
G3D_USE_CACHE_DEFAULT, ¤t_region);
588
cf4 = Rast3d_open_new_opt_tile_size(aspect2, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
583
589
if (cf4 == NULL) {
584
sprintf(buff, "Can't open %s for writing ", aspect2);
585
clean_fatal_error(buff);
591
G_fatal_error(_("Unable to open %s for writing"), aspect2);
588
594
/* seek to the beginning */
589
fseek(Tmp_fd_dz, 0L, 0);
595
G_fseek(Tmp_fd_dz, 0L, 0);
591
597
/* Read data in from temp file */
593
599
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_dz);
595
clean_fatal_error("Cannot read data from temp file");
602
G_fatal_error(_("Unable to read data from temp file"));
598
606
for (iarc = 0; iarc < nsizl; iarc++) {
603
611
bmask = BM_get(bitmask, x, nsizr - y - 1);
614
value = data[cnt] * 180 / M_PI;
608
G3d_setNullValue(&value, 1, FCELL_TYPE);
609
if (G3d_putFloat(cf4, x, y, iarc, value) == 0) {
611
"Error writing cell (%d,%d,%d) with value %f",
616
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
617
if (Rast3d_put_float(cf4, x, y, iarc, value) == 0) {
620
_("Error writing cell (%d,%d,%d) with value %f"),
612
621
x, y, iarc, value);
613
clean_fatal_error(buff);
622
630
/* Close the file */
623
if (G3d_closeCell(cf4) == 0) {
624
sprintf(buff, "Error closing output file %s ", aspect2);
625
clean_fatal_error(buff);
631
if (Rast3d_close(cf4) == 0) {
633
G_fatal_error(_("Error closing output file %s"), aspect2);
627
635
G_message(_("3D raster map <%s> created"), aspect2);
630
638
/*** Write out ncurv results ***/
631
639
if (ncurv != NULL) {
633
cf5 = G3d_openCellNew(ncurv, FCELL_TYPE,
634
G3D_USE_CACHE_DEFAULT, ¤t_region);
641
cf5 = Rast3d_open_new_opt_tile_size(ncurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
635
642
if (cf5 == NULL) {
636
sprintf(buff, "Can't open %s for writing ", ncurv);
637
clean_fatal_error(buff);
644
G_fatal_error(_("Unable to open %s for writing"), ncurv);
640
647
/* seek to the beginning */
641
fseek(Tmp_fd_xx, 0L, 0);
648
G_fseek(Tmp_fd_xx, 0L, 0);
643
650
/* Read data in from temp file */
645
652
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_xx);
647
clean_fatal_error("Cannot read data from temp file");
655
G_fatal_error(_("Unable to read data from temp file"));
650
659
for (iarc = 0; iarc < nsizl; iarc++) {
658
667
value = data[cnt];
660
G3d_setNullValue(&value, 1, FCELL_TYPE);
661
if (G3d_putFloat(cf5, x, y, iarc, value) == 0) {
663
"Error writing cell (%d,%d,%d) with value %f",
669
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
670
if (Rast3d_put_float(cf5, x, y, iarc, value) == 0) {
673
_("Error writing cell (%d,%d,%d) with value %f"),
664
674
x, y, iarc, value);
665
clean_fatal_error(buff);
674
683
/* Close the file */
675
if (G3d_closeCell(cf5) == 0) {
676
sprintf(buff, "Error closing output file %s ", ncurv);
677
clean_fatal_error(buff);
684
if (Rast3d_close(cf5) == 0) {
686
G_fatal_error(_("Error closing output file %s"), ncurv);
679
688
G_message(_("3D raster map <%s> created"), ncurv);
682
691
/*** Write out gcurv results ***/
683
692
if (gcurv != NULL) {
685
cf6 = G3d_openCellNew(gcurv, FCELL_TYPE,
686
G3D_USE_CACHE_DEFAULT, ¤t_region);
694
cf6 = Rast3d_open_new_opt_tile_size(gcurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
687
695
if (cf6 == NULL) {
688
sprintf(buff, "Can't open %s for writing ", gcurv);
689
clean_fatal_error(buff);
697
G_fatal_error(_("Unable to open %s for writing"), gcurv);
692
700
/* seek to the beginning */
693
fseek(Tmp_fd_yy, 0L, 0);
701
G_fseek(Tmp_fd_yy, 0L, 0);
695
703
/* Read data in from temp file */
697
705
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_yy);
699
clean_fatal_error("Cannot read data from temp file");
708
G_fatal_error(_("Unable to read data from temp file"));
702
712
for (iarc = 0; iarc < nsizl; iarc++) {
710
720
value = data[cnt];
712
G3d_setNullValue(&value, 1, FCELL_TYPE);
713
if (G3d_putFloat(cf6, x, y, iarc, value) == 0) {
715
"Error writing cell (%d,%d,%d) with value %f",
722
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
723
if (Rast3d_put_float(cf6, x, y, iarc, value) == 0) {
726
_("Error writing cell (%d,%d,%d) with value %f"),
716
727
x, y, iarc, value);
717
clean_fatal_error(buff);
726
736
/* Close the file */
727
if (G3d_closeCell(cf6) == 0) {
728
sprintf(buff, "Error closing output file %s ", gcurv);
729
clean_fatal_error(buff);
737
if (Rast3d_close(cf6) == 0) {
739
G_fatal_error(_("Error closing output file %s"), gcurv);
731
741
G_message(_("3D raster map <%s> created"), gcurv);
734
744
/*** Write mcurv results ***/
735
745
if (mcurv != NULL) {
737
cf7 = G3d_openCellNew(mcurv, FCELL_TYPE,
738
G3D_USE_CACHE_DEFAULT, ¤t_region);
747
cf7 = Rast3d_open_new_opt_tile_size(mcurv, RASTER3D_USE_CACHE_DEFAULT, ¤t_region, FCELL_TYPE, 32);
739
748
if (cf7 == NULL) {
740
sprintf(buff, "Can't open %s for writing ", mcurv);
741
clean_fatal_error(buff);
750
G_fatal_error(_("Unable to open %s for writing"), mcurv);
744
753
/* seek to the beginning */
745
fseek(Tmp_fd_xy, 0L, 0);
754
G_fseek(Tmp_fd_xy, 0L, 0);
747
756
/* Read data in from temp file */
749
758
fread(data, sizeof(float), nsizr * nsizc * nsizl, Tmp_fd_xy);
751
clean_fatal_error("Cannot read data from temp file");
761
G_fatal_error(_("Unable to read data from temp file"));
754
765
for (iarc = 0; iarc < nsizl; iarc++) {
762
773
value = data[cnt];
764
G3d_setNullValue(&value, 1, FCELL_TYPE);
765
if (G3d_putFloat(cf7, x, y, iarc, value) == 0) {
767
"Error writing cell (%d,%d,%d) with value %f",
775
Rast3d_set_null_value(&value, 1, FCELL_TYPE);
776
if (Rast3d_put_float(cf7, x, y, iarc, value) == 0) {
779
_("Error writing cell (%d,%d,%d) with value %f"),
768
780
x, y, iarc, value);
769
clean_fatal_error(buff);
778
789
/* Close the file */
779
if (G3d_closeCell(cf7) == 0) {
780
sprintf(buff, "Error closing output file %s ", mcurv);
781
clean_fatal_error(buff);
790
if (Rast3d_close(cf7) == 0) {
792
G_fatal_error(_("Error closing output file %s"), mcurv);
783
794
G_message(_("3D raster map <%s> created"), mcurv);