File: list.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (88 lines) | stat: -rw-r--r-- 2,671 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>

#include <grass/gis.h>
#include <grass/gprojects.h>
#include <grass/glocale.h>

#include <grass/gis.h>
#include <grass/glocale.h>

#include <gdal.h>

#include "proto.h"

void list_formats(void)
{
    /* -------------------------------------------------------------------- */
    /*      List supported formats and exit.                                */
    /*         code from GDAL 1.2.5  gcore/gdal_misc.cpp                    */
    /*         Copyright (c) 1999, Frank Warmerdam                          */
    /* -------------------------------------------------------------------- */
    int iDr;

    G_message(_("Supported formats:"));
    for (iDr = 0; iDr < GDALGetDriverCount(); iDr++) {
        GDALDriverH hDriver = GDALGetDriver(iDr);
        const char *pszRWFlag;

#ifdef GDAL_DCAP_RASTER
        /* Starting with GDAL 2.0, vector drivers can also be returned */
        /* Only keep raster drivers */
        if (!GDALGetMetadataItem(hDriver, GDAL_DCAP_RASTER, NULL))
            continue;
#endif

        if (GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATE, NULL))
            pszRWFlag = "rw+";
        else if (GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATECOPY, NULL))
            pszRWFlag = "rw";
        else
            pszRWFlag = "ro";

        fprintf(stdout, " %s (%s): %s\n", GDALGetDriverShortName(hDriver),
                pszRWFlag, GDALGetDriverLongName(hDriver));
    }
}

void list_bands(struct Cell_head *cellhd, GDALDatasetH hDS)
{
    struct Cell_head loc_wind;
    struct Key_Value *proj_info = NULL, *proj_units = NULL;
    struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
    int n_bands, i_band, proj_same;
    GDALRasterBandH hBand;
    GDALDataType gdal_type;

    if (GPJ_wkt_to_grass(cellhd, &proj_info, &proj_units,
                         GDALGetProjectionRef(hDS), 0) < 0) {
        proj_same = 0;
    }
    else {

        G_get_default_window(&loc_wind);
        if (loc_wind.proj != PROJECTION_XY) {
            loc_proj_info = G_get_projinfo();
            loc_proj_units = G_get_projunits();
        }

        if (loc_wind.proj != cellhd->proj ||
            (G_compare_projections(loc_proj_info, loc_proj_units, proj_info,
                                   proj_units)) < 0) {
            proj_same = 0;
        }
        else {
            proj_same = 1;
        }
    }

    n_bands = GDALGetRasterCount(hDS);

    for (i_band = 1; i_band <= n_bands; i_band++) {

        hBand = GDALGetRasterBand(hDS, i_band);
        gdal_type = GDALGetRasterDataType(hBand);

        fprintf(stdout, "%d,%s,%d\n", i_band, GDALGetDataTypeName(gdal_type),
                proj_same);
    }
}