main.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /****************************************************************************
  2. *
  3. * MODULE: r.in.poly
  4. * AUTHOR(S): Michael Shapiro, CERL (original contributor)
  5. * PURPOSE: creates GRASS binary raster maps from ASCII files
  6. * COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. *****************************************************************************/
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <grass/gis.h>
  16. #include <grass/glocale.h>
  17. #include "local_proto.h"
  18. int main(int argc, char *argv[])
  19. {
  20. struct GModule *module;
  21. struct Option *input, *output, *title, *rows, *nulls, *type;
  22. int n;
  23. int raster_type;
  24. int null_value;
  25. int *null;
  26. null = &null_value;
  27. G_gisinit(argv[0]);
  28. module = G_define_module();
  29. G_add_keyword(_("raster"));
  30. G_add_keyword(_("import"));
  31. module->description =
  32. _("Creates raster maps from ASCII polygon/line/point data files.");
  33. input = G_define_standard_option(G_OPT_F_INPUT);
  34. input->description = _("Name of input file; or \"-\" to read from stdin");
  35. output = G_define_standard_option(G_OPT_R_OUTPUT);
  36. title = G_define_option();
  37. title->key = "title";
  38. title->key_desc = "phrase";
  39. title->type = TYPE_STRING;
  40. title->required = NO;
  41. title->description = _("Title for resultant raster map");
  42. type = G_define_option();
  43. type->key = "type";
  44. type->type = TYPE_STRING;
  45. type->required = NO;
  46. type->description = _("Output raster type");
  47. type->options = "CELL,FCELL,DCELL";
  48. type->answer = "CELL";
  49. nulls = G_define_option();
  50. nulls->key = "null";
  51. nulls->type = TYPE_INTEGER;
  52. nulls->required = NO;
  53. nulls->description = _("Integer representing NULL value data cell");
  54. rows = G_define_option();
  55. rows->key = "rows";
  56. rows->type = TYPE_INTEGER;
  57. rows->required = NO;
  58. rows->description = _("Number of rows to hold in memory");
  59. rows->answer = "4096";
  60. if (G_parser(argc, argv))
  61. exit(EXIT_FAILURE);
  62. sscanf(rows->answer, "%d", &n);
  63. if (n < 1)
  64. G_fatal_error(_("Minimum number of rows to hold in memory is 1"));
  65. if (strcmp(type->answer, "CELL") == 0)
  66. raster_type = CELL_TYPE;
  67. else if (strcmp(type->answer, "FCELL") == 0)
  68. raster_type = FCELL_TYPE;
  69. else if (strcmp(type->answer, "DCELL") == 0)
  70. raster_type = DCELL_TYPE;
  71. else
  72. G_fatal_error(_("Type doesn't exist"));
  73. if (nulls->answer)
  74. *null = atoi(nulls->answer);
  75. else
  76. null = NULL;
  77. exit(poly_to_rast(input->answer, output->answer, title->answer, n, raster_type, null));
  78. }