create.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <errno.h>
  2. #include <string.h>
  3. #include <grass/gis.h>
  4. #include <grass/glocale.h>
  5. #include "local_proto.h"
  6. void create_location(char *location)
  7. {
  8. int ret;
  9. ret = G_make_location(location, &cellhd, projinfo, projunits);
  10. if (ret == 0)
  11. G_message(_("Location <%s> created"), location);
  12. else if (ret == -1)
  13. G_fatal_error(_("Unable to create location <%s>: %s"),
  14. location, strerror(errno));
  15. else if (ret == -2)
  16. G_fatal_error(_("Unable to create projection files: %s"),
  17. strerror(errno));
  18. else
  19. /* Shouldn't happen */
  20. G_fatal_error(_("Unable to create location <%s>"), location);
  21. G_message(_("You can switch to the new location by\n`%s=%s`"),
  22. "g.mapset mapset=PERMANENT location", location);
  23. }
  24. void modify_projinfo()
  25. {
  26. const char *mapset = G_mapset();
  27. struct Cell_head old_cellhd;
  28. if (strcmp(mapset, "PERMANENT") != 0)
  29. G_fatal_error(_("You must select the PERMANENT mapset before updating the "
  30. "current location's projection (current mapset is <%s>)."),
  31. mapset);
  32. /* Read projection information from current location first */
  33. G_get_default_window(&old_cellhd);
  34. char path[GPATH_MAX];
  35. /* Write out the PROJ_INFO, and PROJ_UNITS if available. */
  36. if (projinfo != NULL) {
  37. G_file_name(path, "", "PROJ_INFO", "PERMANENT");
  38. G_write_key_value_file(path, projinfo);
  39. }
  40. if (projunits != NULL) {
  41. G_file_name(path, "", "PROJ_UNITS", "PERMANENT");
  42. G_write_key_value_file(path, projunits);
  43. }
  44. if ((old_cellhd.zone != cellhd.zone) ||
  45. (old_cellhd.proj != cellhd.proj)) {
  46. /* Recreate the default, and current window files if projection
  47. * number or zone have changed */
  48. G__put_window(&cellhd, "", "DEFAULT_WIND");
  49. G__put_window(&cellhd, "", "WIND");
  50. G_message(_("Default region was updated to the new projection, but if you have "
  51. "multiple mapsets `g.region -d` should be run in each to update the "
  52. "region from the default"));
  53. }
  54. G_important_message(_("Projection information updated"));
  55. }