list.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include <grass/gprojects.h>
  4. #include <grass/glocale.h>
  5. #include <grass/gis.h>
  6. #include <grass/glocale.h>
  7. #include <gdal.h>
  8. #include "proto.h"
  9. void list_formats(void)
  10. {
  11. /* -------------------------------------------------------------------- */
  12. /* List supported formats and exit. */
  13. /* code from GDAL 1.2.5 gcore/gdal_misc.cpp */
  14. /* Copyright (c) 1999, Frank Warmerdam */
  15. /* -------------------------------------------------------------------- */
  16. int iDr;
  17. G_message(_("Supported formats:"));
  18. for (iDr = 0; iDr < GDALGetDriverCount(); iDr++) {
  19. GDALDriverH hDriver = GDALGetDriver(iDr);
  20. const char *pszRWFlag;
  21. #ifdef GDAL_DCAP_RASTER
  22. /* Starting with GDAL 2.0, vector drivers can also be returned */
  23. /* Only keep raster drivers */
  24. if (!GDALGetMetadataItem(hDriver, GDAL_DCAP_RASTER, NULL))
  25. continue;
  26. #endif
  27. if (GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATE, NULL))
  28. pszRWFlag = "rw+";
  29. else if (GDALGetMetadataItem(hDriver, GDAL_DCAP_CREATECOPY, NULL))
  30. pszRWFlag = "rw";
  31. else
  32. pszRWFlag = "ro";
  33. fprintf(stdout, " %s (%s): %s\n",
  34. GDALGetDriverShortName(hDriver),
  35. pszRWFlag, GDALGetDriverLongName(hDriver));
  36. }
  37. }
  38. void list_bands(struct Cell_head *cellhd, GDALDatasetH hDS)
  39. {
  40. struct Cell_head loc_wind;
  41. struct Key_Value *proj_info = NULL, *proj_units = NULL;
  42. struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
  43. int n_bands, i_band, proj_same;
  44. GDALRasterBandH hBand;
  45. GDALDataType gdal_type;
  46. if (GPJ_wkt_to_grass(cellhd, &proj_info,
  47. &proj_units, GDALGetProjectionRef(hDS), 0) < 0) {
  48. proj_same = 0;
  49. }
  50. else {
  51. G_get_default_window(&loc_wind);
  52. if (loc_wind.proj != PROJECTION_XY) {
  53. loc_proj_info = G_get_projinfo();
  54. loc_proj_units = G_get_projunits();
  55. }
  56. if (loc_wind.proj != cellhd->proj ||
  57. (G_compare_projections
  58. (loc_proj_info, loc_proj_units, proj_info, proj_units)) < 0) {
  59. proj_same = 0;
  60. }
  61. else {
  62. proj_same = 1;
  63. }
  64. }
  65. n_bands = GDALGetRasterCount(hDS);
  66. for (i_band = 1; i_band <= n_bands; i_band++) {
  67. hBand = GDALGetRasterBand(hDS, i_band);
  68. gdal_type = GDALGetRasterDataType(hBand);
  69. fprintf(stdout, "%d,%s,%d\n", i_band, GDALGetDataTypeName(gdal_type),
  70. proj_same);
  71. }
  72. }