Changeset 56190
- Timestamp:
- May 10, 2013, 1:46:38 PM (11 years ago)
- Location:
- grass-addons/grass7/raster
- Files:
-
- 1 deleted
- 3 edited
- 2 copied
-
Makefile (modified) (1 diff)
-
r.traveltime (copied) (copied from grass-addons/grass6/raster/r.traveltime )
-
r.traveltime/Makefile (modified) (1 diff)
-
r.traveltime/description.html (deleted)
-
r.traveltime/main.c (modified) (11 diffs)
-
r.traveltime/r.traveltime.html (copied) (copied from grass-addons/grass6/raster/r.traveltime/description.html ) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grass-addons/grass7/raster/Makefile
r56056 r56190 28 28 r.stream.snap \ 29 29 r.stream.stats \ 30 r.threshold 30 r.threshold \ 31 r.traveltime 31 32 32 33 include $(MODULE_TOPDIR)/include/Make/Dir.make -
grass-addons/grass7/raster/r.traveltime/Makefile
r55236 r56190 1 # Uncoment and fix MODULE_TOPDIR line OR provide MODULE_TOPDIR variable for make 2 # fix this relative to include/ 3 # or use absolute path to the GRASS source code 4 #MODULE_TOPDIR = ../.. 1 MODULE_TOPDIR = ../.. 5 2 6 3 PGM = r.traveltime 7 4 8 LIBES = $(G ISLIB)9 DEPENDENCIES = $(G ISDEP)5 LIBES = $(GMATHLIB) $(RASTERLIB) $(GISLIB) 6 DEPENDENCIES = $(GMATHDEP) $(RASTERDEP) $(GISDEP) 10 7 11 8 include $(MODULE_TOPDIR)/include/Make/Module.make -
grass-addons/grass7/raster/r.traveltime/main.c
r53876 r56190 28 28 #include <float.h> 29 29 #include <grass/gis.h> 30 #include <grass/raster.h> 30 31 #include <grass/glocale.h> 31 32 #include <grass/config.h> … … 58 59 int value; 59 60 60 if (G_get_raster_row(in_dir, inrast_dir, loc_y, data_type_dir) < 0) 61 G_fatal_error(_("Could not read from map")); 61 Rast_get_row(in_dir, inrast_dir, loc_y, data_type_dir); 62 62 value = ((CELL *) inrast_dir)[loc_x]; 63 63 … … 151 151 double manningsn; 152 152 153 if (G_get_raster_row(in_dir, inrast_dir, y, data_type_dir) < 0) 154 G_fatal_error(_("Could not read from map")); 153 Rast_get_row(in_dir, inrast_dir, y, data_type_dir); 155 154 dir = ((CELL *) inrast_dir)[x]; 156 155 157 if (G_get_raster_row(in_accu, inrast_accu, y, data_type_accu) < 0) 158 G_fatal_error(_("Could not read from map")); 156 Rast_get_row(in_accu, inrast_accu, y, data_type_accu); 159 157 accu = ((CELL *) inrast_accu)[x]; 160 158 161 if (G_get_raster_row(in_n, inrast_n, y, data_type_n) < 0) 162 G_fatal_error(_("Could not read from map")); 159 Rast_get_row(in_n, inrast_n, y, data_type_n); 163 160 switch (data_type_n) { 164 161 case DCELL_TYPE: … … 170 167 } 171 168 172 if (G_get_raster_row(in_dtm, inrast_dtm, y, data_type_dtm) < 0) 173 G_fatal_error(_("Could not read from map")); 169 Rast_get_row(in_dtm, inrast_dtm, y, data_type_dtm); 174 170 switch (data_type_dtm) { 175 171 case CELL_TYPE: … … 184 180 } 185 181 186 if (G_get_raster_row(in_dtm, inrast_dtm, y - dy, data_type_dtm) < 0) 187 G_fatal_error(_("Could not read from map")); 182 Rast_get_row(in_dtm, inrast_dtm, y - dy, data_type_dtm); 188 183 switch (data_type_dtm) { 189 184 case CELL_TYPE: … … 197 192 break; 198 193 } 199 200 201 194 202 195 for (i = -1; i < 2; i++) { … … 252 245 *input_ep, *input_fdis; 253 246 254 255 256 257 247 /* initialize GIS environment */ 258 248 G_gisinit(argv[0]); /* reads grass env, stores program name to G_program_name() */ 259 249 260 261 262 250 /* initialize module */ 263 251 module = G_define_module(); 264 module->description = _("Estimation of travel times/isochrones"); 252 G_add_keyword(_("raster")); 253 G_add_keyword(_("hydrology")); 254 module->label = _("Estimation of travel times/isochrones."); 255 module->description = 256 _("Computes the travel time of surface runoff to an outlet"); 265 257 266 258 /* Define the different options as defined in gis.h */ … … 362 354 fdis = factor; 363 355 else { 364 printf("\nWARNING! Reduction factor is not valid!\n"); 365 exit(EXIT_FAILURE); 366 } 367 368 /* returns NULL if the map was not found in any mapset, 369 * mapset name otherwise */ 370 mapset = G_find_cell2(map_dir, ""); 371 if (mapset == NULL) 372 G_fatal_error(_("cell file [%s] not found"), map_dir); 373 374 mapset = G_find_cell2(map_accu, ""); 375 if (mapset == NULL) 376 G_fatal_error(_("cell file [%s] not found"), map_accu); 377 378 mapset = G_find_cell2(map_dtm, ""); 379 if (mapset == NULL) 380 G_fatal_error(_("cell file [%s] not found"), map_dtm); 381 382 mapset = G_find_cell2(map_n, ""); 383 if (mapset == NULL) 384 G_fatal_error(_("cell file [%s] not found"), map_n); 385 386 387 if (G_legal_filename(result) < 0) 388 G_fatal_error(_("[%s] is an illegal name"), result); 389 390 356 G_fatal_error("Reduction factor is not valid!"); 357 } 358 359 mapset = G_find_raster2(map_dir, ""); 360 mapset = G_find_raster2(map_accu, ""); 361 mapset = G_find_raster2(map_dtm, ""); 362 mapset = G_find_raster2(map_n, ""); 391 363 392 364 /* determine the inputmap type (CELL/FCELL/DCELL) */ 393 data_type_dir = G_raster_map_type(map_dir, mapset); 394 data_type_accu = G_raster_map_type(map_accu, mapset); 395 data_type_n = G_raster_map_type(map_n, mapset); 396 data_type_dtm = G_raster_map_type(map_dtm, mapset); 397 398 /* G_open_cell_old - returns file destriptor (>0) */ 399 if ((in_dir = G_open_cell_old(map_dir, mapset)) < 0) 400 G_fatal_error(_("Cannot open cell file [%s]"), map_dir); 401 402 if ((in_accu = G_open_cell_old(map_accu, mapset)) < 0) 403 G_fatal_error(_("Cannot open cell file [%s]"), map_accu); 404 405 if ((in_n = G_open_cell_old(map_n, mapset)) < 0) 406 G_fatal_error(_("Cannot open cell file [%s]"), map_n); 407 408 if ((in_dtm = G_open_cell_old(map_dtm, mapset)) < 0) 409 G_fatal_error(_("Cannot open cell file [%s]"), map_dtm); 410 411 /* controlling, if we can open input raster */ 412 if (G_get_cellhd(map_accu, mapset, &cellhd_accu) < 0) 413 G_fatal_error(_("Cannot read file header of [%s]"), map_accu); 414 415 if (G_get_cellhd(map_dir, mapset, &cellhd_dir) < 0) 416 G_fatal_error(_("Cannot read file header of [%s]"), map_dir); 417 418 if (G_get_cellhd(map_dtm, mapset, &cellhd_dtm) < 0) 419 G_fatal_error(_("Cannot read file header of [%s]"), map_dtm); 420 421 if (G_get_cellhd(map_n, mapset, &cellhd_n) < 0) 422 G_fatal_error(_("Cannot read file header of [%s]"), map_n); 365 data_type_dir = Rast_map_type(map_dir, mapset); 366 data_type_accu = Rast_map_type(map_accu, mapset); 367 data_type_n = Rast_map_type(map_n, mapset); 368 data_type_dtm = Rast_map_type(map_dtm, mapset); 369 370 in_dir = Rast_open_old(map_dir, mapset); 371 in_accu = Rast_open_old(map_accu, mapset); 372 in_n = Rast_open_old(map_n, mapset); 373 in_dtm = Rast_open_old(map_dtm, mapset); 423 374 424 375 G_debug(3, "number of rows %d", cellhd_accu.rows); … … 428 379 429 380 /* Allocate input buffer */ 430 inrast_accu = G_allocate_raster_buf(data_type_accu);431 inrast_dir = G_allocate_raster_buf(data_type_dir);432 inrast_n = G_allocate_raster_buf(data_type_n);433 inrast_dtm = G_allocate_raster_buf(data_type_dtm);381 inrast_accu = Rast_allocate_buf(data_type_accu); 382 inrast_dir = Rast_allocate_buf(data_type_dir); 383 inrast_n = Rast_allocate_buf(data_type_n); 384 inrast_dtm = Rast_allocate_buf(data_type_dtm); 434 385 435 386 436 387 /* Allocate output buffer, use input map data_type */ 437 nrows = G_window_rows();438 ncols = G_window_cols();439 outrast = G_allocate_raster_buf(FCELL_TYPE);388 nrows = Rast_window_rows(); 389 ncols = Rast_window_cols(); 390 outrast = Rast_allocate_buf(FCELL_TYPE); 440 391 441 392 /* controlling, if we can write the raster */ 442 if ((outfd = G_open_raster_new(result, FCELL_TYPE)) < 0) 443 G_fatal_error(_("Could not open <%s>"), result); 393 outfd = Rast_open_new(result, FCELL_TYPE); 444 394 445 395 /* output array */ 446 396 447 397 array_out = (double **)malloc(nrows * sizeof(double *)); 448 if ((NULL == array_out)) { 449 printf("out of memory ... !"); 450 exit(EXIT_FAILURE); 451 } 398 if ((NULL == array_out)) 399 G_fatal_error("Out of memory ... !"); 452 400 int i, j; 453 401 454 402 for (i = 0; i < nrows; i++) { 455 403 array_out[i] = (double *)malloc(ncols * sizeof(double)); 456 if ((NULL == array_out[i])) { 457 printf("out of memory ... !"); 458 exit(EXIT_FAILURE); 459 } 404 if ((NULL == array_out[i])) 405 G_fatal_error("Out of memory ... !"); 460 406 } 461 407 … … 470 416 */ 471 417 472 if (G_get_window(&window) < 0) { 473 sprintf(map_dir, "can't read current window parameters"); 474 G_fatal_error(map_dir); 475 exit(EXIT_FAILURE); 476 } 418 G_get_window(&window); 477 419 478 420 // map units to matrix locations … … 533 475 } 534 476 /* write raster row to output raster file */ 535 if (G_put_raster_row(outfd, outrast, CELL_TYPE) < 0) 536 G_fatal_error(_("Cannot write to <%s>"), result); 537 } 538 539 540 541 542 /* memory cleanup */ 543 G_free(inrast_accu); 544 G_free(inrast_dir); 545 G_free(inrast_dtm); 546 G_free(inrast_n); 547 G_free(outrast); 477 Rast_put_row(outfd, outrast, CELL_TYPE); 478 } 548 479 549 480 /* closing raster files */ 550 G_close_cell(inrast_accu); 551 G_close_cell(inrast_dir); 552 G_close_cell(inrast_dtm); 553 G_close_cell(inrast_n); 554 G_close_cell(outfd); 555 481 // Rast_close(inrast_accu); 482 // Rast_close(inrast_dir); 483 // Rast_close(inrast_dtm); 484 // Rast_close(inrast_n); 485 486 Rast_close(in_dir); 487 Rast_close(in_accu); 488 Rast_close(in_n); 489 Rast_close(in_dtm); 490 Rast_close(outfd); 556 491 557 492 return 0; -
grass-addons/grass7/raster/r.traveltime/r.traveltime.html
r56189 r56190 3 3 outlet. The program starts at the basin outlet and calculates the travel 4 4 time at each raster cell recursively. A drainage area related threhold 5 considers even surface and also channel runoff. Travel times are5 considers even surface and also channel runoff. Travel times are 6 6 derived by assuming kinematic wave approximation.<br> 7 7 To derive channel flow velocities an equilibrium discharge for each 8 8 cell is calculated (Q=Area*Excess_Prcipitation, Assumption: storm 9 duration >= time of concentration). This assumption may result9 duration >= time of concentration). This assumption may result 10 10 in overestimated velocities. Therefor a factor is implemented to reduce 11 11 velocities biased towards too large values.<br> … … 24 24 The program does not work correctly if Manning's roughness grid is 25 25 defined as double (float expected). To define a simple uniform 26 roughness distribution try: r.mapcalc 'roughness =0.1f'26 roughness distribution try: r.mapcalc 'roughness = 0.1f' 27 27 <br> 28 28 The region has to be set one row and column larger than the elevation … … 33 33 <p> 34 34 <div class="code"><pre> 35 g.region rast=elev_lid792_1m n=n+1 s=s-1 w=w-1 e=e+1 -p 36 r.watershed elev_lid792_1m thresh=5000 accum=accum_5K drain=draindir_5K 37 r.fill.dir elev_lid792_1m elev=elev_filled dir=elev_dir 38 r.mapcalc rough=0.1f 39 r.traveltime --overwrite dir=draindir_5K@user1 accu=accum_5K@user1 \ 40 dtm=elev_filled@user1 manningsn=rough out_x=638741.43125 \ 41 out_y=220269.7 threshold=1 b=1 nchannel=0.1 ep=40 fdis=1 \ 42 out=travel_time 35 g.region rast=elev_lid792_1m n=n+1 s=s-1 w=w-1 e=e+1 -p 36 r.watershed elev_lid792_1m thresh=5000 accum=accum_5K drain=draindir_5K 37 r.fill.dir elev_lid792_1m output=elev_filled outdir=elev_dir 38 39 r.mapcalc "rough = 0.1f" 40 r.traveltime dir=draindir_5K@user1 accu=accum_5K@user1 \ 41 dtm=elev_filled@user1 manningsn=rough out_x=638741.43125 \ 42 out_y=220269.7 threshold=1 b=1 nchannel=0.1 ep=40 fdis=1 \ 43 out=travel_time 44 r.colors travel_time col=gyr 43 45 </pre></div> 44 </p>45 46 46 47 <h2>SEE ALSO</h2> 47 <em><a href="r.watershed.html">r.watershed</a>, 48 <a href="r.fill.dir.html">r.fill.dir</a> 49 <br> 50 <br> 51 <a href="http://jesbergwetter.twoday.net/stories/4845555/">http://jesbergwetter.twoday.net/stories/4845555/</a> 48 <em> 49 <a href="r.watershed.html">r.watershed</a>, 50 <a href="r.fill.dir.html">r.fill.dir</a> 51 </em> 52 <br> 53 <a href="http://jesbergwetter.twoday.net/stories/4845555/">http://jesbergwetter.twoday.net/stories/4845555/</a> 52 54 53 <h2>REFERENCES</h2> 54 <li>Kilgore, J. L. (1997): <em>Development and evaluation of a GIS-based 55 <h2>REFERENCES</h2> 56 57 <ul> 58 <li>Kilgore, J. L. (1997): <em>Development and evaluation of a GIS-based 55 59 spatially distributed unit hydrograph model</em>, master thesis, 56 60 Virginia … … 63 67 <li>Muzik, I. (1996): <em>Flood modelling with GIS-derived distributed 64 68 unit hydrographs</em>, Hydrological Processes, 10, 1401-1409.</li> 69 </ul> 65 70 66 71 <h2>AUTHOR</h2> 67 72 Kristian Foerster<br> 68 73 <p><i>Last changed: $Date$</i> 69 </p>
Note:
See TracChangeset
for help on using the changeset viewer.
