main.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_standard_option(G_OPT_R_TYPE);
  43. type->required = NO;
  44. type->answer = "CELL";
  45. nulls = G_define_option();
  46. nulls->key = "null";
  47. nulls->type = TYPE_INTEGER;
  48. nulls->required = NO;
  49. nulls->description = _("Integer representing NULL value data cell");
  50. rows = G_define_option();
  51. rows->key = "rows";
  52. rows->type = TYPE_INTEGER;
  53. rows->required = NO;
  54. rows->description = _("Number of rows to hold in memory");
  55. rows->answer = "4096";
  56. if (G_parser(argc, argv))
  57. exit(EXIT_FAILURE);
  58. sscanf(rows->answer, "%d", &n);
  59. if (n < 1)
  60. G_fatal_error(_("Minimum number of rows to hold in memory is 1"));
  61. if (strcmp(type->answer, "CELL") == 0)
  62. raster_type = CELL_TYPE;
  63. else if (strcmp(type->answer, "FCELL") == 0)
  64. raster_type = FCELL_TYPE;
  65. else if (strcmp(type->answer, "DCELL") == 0)
  66. raster_type = DCELL_TYPE;
  67. else
  68. G_fatal_error(_("Type doesn't exist"));
  69. if (nulls->answer)
  70. *null = atoi(nulls->answer);
  71. else
  72. null = NULL;
  73. exit(poly_to_rast(input->answer, output->answer, title->answer, n, raster_type, null));
  74. }