create.c 2.3 KB

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