r_vareas.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* Function: vectfile
  2. **
  3. ** This PostScript version is just slightly modified p.map code.
  4. **
  5. ** Modified by: Paul W. Carlson March 1992
  6. ** Modified by: Janne Soimasuo August 1994 line_cat added
  7. ** Modified by: Radim Blazek Jan 2000 acolor, label added
  8. */
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <grass/gis.h>
  12. #include <grass/colors.h>
  13. #include <grass/raster.h>
  14. #include <grass/vector.h>
  15. #include "vector.h"
  16. #include "local_proto.h"
  17. #define KEY(x) (strcmp(key,x)==0)
  18. static char *help[] = {
  19. "color color",
  20. "rgbcolumn column",
  21. "width #",
  22. "masked [y|n]",
  23. "acolor r g b",
  24. "label label",
  25. "lpos 0|1-20",
  26. "pat EPS pattern file",
  27. "scale #",
  28. "pwidth #",
  29. ""
  30. };
  31. int read_vareas(char *name, char *mapset)
  32. {
  33. char fullname[GNAME_MAX + GMAPSET_MAX + 5];
  34. char buf[1024], eps_file[GPATH_MAX];
  35. char *key, *data;
  36. double width;
  37. int itmp, vec;
  38. int r, g, b;
  39. int ret;
  40. struct Map_info Map;
  41. vector_alloc(); /* allocate space */
  42. sprintf(fullname, "%s in %s", name, mapset);
  43. Vect_set_open_level(2);
  44. if (2 > Vect_open_old(&Map, name, mapset)) {
  45. error(fullname, "", "can't open vector map");
  46. gobble_input();
  47. return 0;
  48. }
  49. Vect_close(&Map);
  50. vec = vector.count;
  51. vector.layer[vec].type = VAREAS;
  52. vector.layer[vec].name = G_store(name);
  53. vector.layer[vec].mapset = G_store(mapset);
  54. vector.layer[vec].masked = 0;
  55. vector.layer[vec].field = 1;
  56. vector.layer[vec].cats = NULL;
  57. vector.layer[vec].where = NULL;
  58. vector.layer[vec].width = 1.;
  59. vector.layer[vec].cwidth = 0.;
  60. vector.layer[vec].offset = 0.;
  61. vector.layer[vec].coffset = 0.;
  62. set_color(&(vector.layer[vec].color), 0, 0, 0);
  63. set_color(&(vector.layer[vec].fcolor), 125, 125, 125);
  64. vector.layer[vec].rgbcol = NULL;
  65. vector.layer[vec].linestyle = NULL;
  66. vector.layer[vec].ref = LINE_REF_CENTER;
  67. vector.layer[vec].label = NULL;
  68. vector.layer[vec].lpos = -1;
  69. vector.layer[vec].pat = NULL;
  70. vector.layer[vec].scale = 1.;
  71. vector.layer[vec].pwidth = 1.;
  72. while (input(2, buf, help)) {
  73. if (!key_data(buf, &key, &data))
  74. continue;
  75. if (KEY("masked")) {
  76. vector.layer[vec].masked = yesno(key, data);
  77. if (vector.layer[vec].masked)
  78. PS.mask_needed = 1;
  79. continue;
  80. }
  81. if (KEY("layer")) {
  82. G_strip(data);
  83. vector.layer[vec].field = atoi(data);
  84. continue;
  85. }
  86. if (KEY("cats")) {
  87. G_strip(data);
  88. vector.layer[vec].cats = G_store(data);
  89. continue;
  90. }
  91. if (KEY("where")) {
  92. G_strip(data);
  93. vector.layer[vec].where = G_store(data);
  94. continue;
  95. }
  96. if (KEY("width")) {
  97. width = -1.;
  98. *mapset = 0;
  99. if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) {
  100. width = 1.;
  101. error(key, data, "illegal width (vareas)");
  102. continue;
  103. }
  104. if (mapset[0] == 'i')
  105. width = width / 72.;
  106. vector.layer[vec].width = width;
  107. continue;
  108. }
  109. if (KEY("color")) {
  110. ret = G_str_to_color(data, &r, &g, &b);
  111. if (ret == 1)
  112. set_color(&(vector.layer[vec].color), r, g, b);
  113. else if (ret == 2)
  114. unset_color(&(vector.layer[vec].color));
  115. else
  116. error(key, data, "illegal color request (vareas)");
  117. continue;
  118. }
  119. if (KEY("rgbcolumn")) {
  120. G_strip(data);
  121. vector.layer[vec].rgbcol = G_store(data);
  122. continue;
  123. }
  124. if (KEY("fcolor")) { /* area color */
  125. ret = G_str_to_color(data, &r, &g, &b);
  126. if (ret == 1)
  127. set_color(&(vector.layer[vec].fcolor), r, g, b);
  128. else if (ret == 2)
  129. unset_color(&(vector.layer[vec].fcolor));
  130. else
  131. error(key, data, "illegal color request (vareas)");
  132. continue;
  133. }
  134. if (KEY("label")) { /* map legend label */
  135. G_strip(data);
  136. vector.layer[vec].label = G_store(data);
  137. continue;
  138. }
  139. if (KEY("lpos")) {
  140. if (sscanf(data, "%d", &itmp) < 1 || itmp < 0) {
  141. itmp = -1;
  142. error(key, data, "illegal lpos (vareas)");
  143. continue;
  144. }
  145. vector.layer[vec].lpos = itmp;
  146. continue;
  147. }
  148. if (KEY("pat") || KEY("pattern")) {
  149. G_chop(data);
  150. /* expand "$GISBASE" if present */
  151. if (strncmp(data, "$GISBASE", 8) != 0)
  152. strcpy(eps_file, data);
  153. else {
  154. strcpy(eps_file, G_gisbase());
  155. data += 8;
  156. strcat(eps_file, data);
  157. }
  158. vector.layer[vec].pat = G_store(eps_file);
  159. continue;
  160. }
  161. if (KEY("scale")) {
  162. G_chop(data);
  163. vector.layer[vec].scale = atof(data);
  164. continue;
  165. }
  166. if (KEY("pwidth")) {
  167. width = -1.;
  168. if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) {
  169. width = 0.;
  170. error(key, data, "illegal pwidth (vareas)");
  171. continue;
  172. }
  173. if (mapset[0] == 'i')
  174. width = width / 72.;
  175. vector.layer[vec].pwidth = width;
  176. continue;
  177. }
  178. error(key, "", "illegal request (vareas)");
  179. }
  180. vector.count++;
  181. return 1;
  182. }