~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.out.vtk/writeascii.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <stdlib.h>
21
21
#include <string.h>
22
22
#include <grass/gis.h>
 
23
#include <grass/raster.h>
23
24
#include <grass/glocale.h>
24
25
#include <grass/config.h>
25
26
#include "globaldefs.h"
37
38
    double val = nullval;
38
39
 
39
40
    if (MapType == CELL_TYPE) {
40
 
        if (G_is_null_value(ptr, MapType)) {
 
41
        if (Rast_is_null_value(ptr, MapType)) {
41
42
            val = nullval;
42
43
        }
43
44
        else {
45
46
        }
46
47
    }
47
48
    if (MapType == FCELL_TYPE) {
48
 
        if (G_is_null_value(ptr, MapType)) {
 
49
        if (Rast_is_null_value(ptr, MapType)) {
49
50
            val = nullval;
50
51
        }
51
52
        else {
53
54
        }
54
55
    }
55
56
    if (MapType == DCELL_TYPE) {
56
 
        if (G_is_null_value(ptr, MapType)) {
 
57
        if (Rast_is_null_value(ptr, MapType)) {
57
58
            val = nullval;
58
59
        }
59
60
        else {
75
76
 
76
77
    /*Simple vtk ASCII header */
77
78
    fprintf(fp, "# vtk DataFile Version 3.0\n");
78
 
    fprintf(fp, "GRASS 6 Export\n");
 
79
    fprintf(fp, "GRASS GIS 7 Export\n");
79
80
    fprintf(fp, "ASCII\n");
80
81
    fprintf(fp, "DATASET STRUCTURED_POINTS\n"); /*We are using the structured point dataset. */
81
82
 
108
109
 
109
110
    /*Simple vtk ASCII header */
110
111
    fprintf(fp, "# vtk DataFile Version 3.0\n");
111
 
    fprintf(fp, "GRASS 6 Export\n");
 
112
    fprintf(fp, "GRASS GIS 7 Export\n");
112
113
    fprintf(fp, "ASCII\n");
113
114
    fprintf(fp, "DATASET STRUCTURED_GRID\n");   /*We are using the structured grid dataset. */
114
115
    fprintf(fp, "DIMENSIONS %i %i %i\n", region.cols, region.rows, 1);
124
125
 
125
126
    /*Simple vtk ASCII header */
126
127
    fprintf(fp, "# vtk DataFile Version 3.0\n");
127
 
    fprintf(fp, "GRASS 6 Export\n");
 
128
    fprintf(fp, "GRASS GIS 7 Export\n");
128
129
    fprintf(fp, "ASCII\n");
129
130
    fprintf(fp, "DATASET POLYDATA\n");  /*We are using polydataset. */
130
131
    fprintf(fp, "POINTS %i float\n", region.cols * region.rows);
173
174
        nullvalue = 0;
174
175
    }
175
176
 
176
 
    raster = G_allocate_raster_buf(out_type);
 
177
    raster = Rast_allocate_buf(out_type);
177
178
 
178
179
    rowcount = 0;
179
180
    for (row = nrows - 1; row >= 0; row--) {
180
181
        colcount = 0;
181
182
        G_percent((row - nrows) * (-1), nrows, 2);
182
183
 
183
 
        if (G_get_raster_row(fd, raster, row, out_type) < 0) {
184
 
            G_fatal_error(_("Unable to read row %i\n"), row);
185
 
            return;
186
 
        }
 
184
        Rast_get_row(fd, raster, row, out_type);
187
185
 
188
186
        nspos = region.ns_res / 2 + region.south + rowcount * region.ns_res;
189
187
        nspos -= y_extent;
190
188
 
191
189
        for (col = 0, ptr = raster; col < ncols;
192
 
             col++, ptr = G_incr_void_ptr(ptr, G_raster_size(out_type))) {
 
190
             col++, ptr = G_incr_void_ptr(ptr, Rast_cell_size(out_type))) {
193
191
            ewpos =
194
192
                region.ew_res / 2 + region.west + colcount * region.ew_res;
195
193
            ewpos -= x_extent;
234
232
 
235
233
 
236
234
    /*First we are writing the coordinate points, the elevation cell is only used for the z coordinate */
237
 
    raster = G_allocate_raster_buf(out_type);
 
235
    raster = Rast_allocate_buf(out_type);
238
236
 
239
237
    rowcount = 0;
240
238
    for (row = nrows - 1; row >= 0; row--) {
241
239
        colcount = 0;
242
240
        G_percent((row - nrows) * (-1), nrows, 10);
243
241
 
244
 
        if (G_get_raster_row(fd, raster, row, out_type) < 0) {
245
 
            G_fatal_error(_("Unable to read row %i\n"), row);
246
 
            return;
247
 
        }
 
242
        Rast_get_row(fd, raster, row, out_type);
248
243
 
249
244
        nspos = region.ns_res / 2 + region.south + rowcount * region.ns_res;
250
245
        nspos -= y_extent;
251
246
 
252
247
        for (col = 0, ptr = raster; col < ncols;
253
 
             col++, ptr = G_incr_void_ptr(ptr, G_raster_size(out_type))) {
 
248
             col++, ptr = G_incr_void_ptr(ptr, Rast_cell_size(out_type))) {
254
249
            ewpos =
255
250
                region.ew_res / 2 + region.west + colcount * region.ew_res;
256
251
            ewpos -= x_extent;
348
343
    fprintf(fp, "LOOKUP_TABLE default\n");
349
344
 
350
345
 
351
 
    raster = G_allocate_raster_buf(out_type);
 
346
    raster = Rast_allocate_buf(out_type);
352
347
 
353
348
    for (row = nrows - 1; row >= 0; row--) {
354
349
        G_percent((row - nrows) * (-1), nrows, 10);
355
350
 
356
 
        if (G_get_raster_row(fd, raster, row, out_type) < 0) {
357
 
            G_fatal_error(_("Unable to read row %i\n"), row);
358
 
            return;
359
 
        }
 
351
        Rast_get_row(fd, raster, row, out_type);
360
352
 
361
353
        for (col = 0, ptr = raster; col < ncols;
362
 
             col++, ptr = G_incr_void_ptr(ptr, G_raster_size(out_type))) {
 
354
             col++, ptr = G_incr_void_ptr(ptr, Rast_cell_size(out_type))) {
363
355
 
364
356
            value = get_raster_value_as_double(out_type, ptr, nullvalue);
365
357
            fprintf(fp, "%.*f ", dp, value);
393
385
 
394
386
    fprintf(fp, "COLOR_SCALARS %s 3\n", varname);
395
387
 
396
 
    redraster = G_allocate_raster_buf(out_type);
397
 
    greenraster = G_allocate_raster_buf(out_type);
398
 
    blueraster = G_allocate_raster_buf(out_type);
 
388
    redraster = Rast_allocate_buf(out_type);
 
389
    greenraster = Rast_allocate_buf(out_type);
 
390
    blueraster = Rast_allocate_buf(out_type);
399
391
 
400
392
    for (row = nrows - 1; row >= 0; row--) {
401
393
        G_percent((row - nrows) * (-1), nrows, 10);
402
394
 
403
 
        if (G_get_raster_row(redfd, redraster, row, out_type) < 0) {
404
 
            G_fatal_error(_("Unable to read row %i\n"), row);
405
 
            return;
406
 
        }
407
 
        if (G_get_raster_row(greenfd, greenraster, row, out_type) < 0) {
408
 
            G_fatal_error(_("Unable to read row %i\n"), row);
409
 
            return;
410
 
        }
411
 
        if (G_get_raster_row(bluefd, blueraster, row, out_type) < 0) {
412
 
            G_fatal_error(_("Unable to read row %i\n"), row);
413
 
            return;
414
 
        }
 
395
        Rast_get_row(redfd, redraster, row, out_type);
 
396
        Rast_get_row(greenfd, greenraster, row, out_type);
 
397
        Rast_get_row(bluefd, blueraster, row, out_type);
415
398
 
416
399
        for (col = 0, redptr = redraster, greenptr = greenraster, blueptr =
417
400
             blueraster; col < ncols;
418
401
             col++, redptr =
419
 
             G_incr_void_ptr(redptr, G_raster_size(out_type)), greenptr =
420
 
             G_incr_void_ptr(greenptr, G_raster_size(out_type)), blueptr =
421
 
             G_incr_void_ptr(blueptr, G_raster_size(out_type))) {
 
402
             G_incr_void_ptr(redptr, Rast_cell_size(out_type)), greenptr =
 
403
             G_incr_void_ptr(greenptr, Rast_cell_size(out_type)), blueptr =
 
404
             G_incr_void_ptr(blueptr, Rast_cell_size(out_type))) {
422
405
 
423
406
            r = get_raster_value_as_double(out_type, redptr, 0.0);
424
407
            g = get_raster_value_as_double(out_type, greenptr, 0.0);
460
443
 
461
444
    fprintf(fp, "VECTORS %s float\n", varname);
462
445
 
463
 
    xraster = G_allocate_raster_buf(out_type);
464
 
    yraster = G_allocate_raster_buf(out_type);
465
 
    zraster = G_allocate_raster_buf(out_type);
 
446
    xraster = Rast_allocate_buf(out_type);
 
447
    yraster = Rast_allocate_buf(out_type);
 
448
    zraster = Rast_allocate_buf(out_type);
466
449
 
467
450
    for (row = nrows - 1; row >= 0; row--) {
468
451
        G_percent((row - nrows) * (-1), nrows, 10);
469
452
 
470
 
        if (G_get_raster_row(xfd, xraster, row, out_type) < 0) {
471
 
            G_fatal_error(_("Unable to read row %i\n"), row);
472
 
            return;
473
 
        }
474
 
        if (G_get_raster_row(yfd, yraster, row, out_type) < 0) {
475
 
            G_fatal_error(_("Unable to read row %i\n"), row);
476
 
            return;
477
 
        }
478
 
        if (G_get_raster_row(zfd, zraster, row, out_type) < 0) {
479
 
            G_fatal_error(_("Unable to read row %i\n"), row);
480
 
            return;
481
 
        }
 
453
        Rast_get_row(xfd, xraster, row, out_type);
 
454
        Rast_get_row(yfd, yraster, row, out_type);
 
455
        Rast_get_row(zfd, zraster, row, out_type);
482
456
 
483
457
        for (col = 0, xptr = xraster, yptr = yraster, zptr =
484
458
             zraster; col < ncols;
485
459
             col++, xptr =
486
 
             G_incr_void_ptr(xptr, G_raster_size(out_type)), yptr =
487
 
             G_incr_void_ptr(yptr, G_raster_size(out_type)), zptr =
488
 
             G_incr_void_ptr(zptr, G_raster_size(out_type))) {
 
460
             G_incr_void_ptr(xptr, Rast_cell_size(out_type)), yptr =
 
461
             G_incr_void_ptr(yptr, Rast_cell_size(out_type)), zptr =
 
462
             G_incr_void_ptr(zptr, Rast_cell_size(out_type))) {
489
463
 
490
464
            x = get_raster_value_as_double(out_type, xptr, 0.0);
491
465
            y = get_raster_value_as_double(out_type, yptr, 0.0);