get_projinfo.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*!
  2. \file lib/gis/get_projinfo.c
  3. \brief GIS Library - Get projection info
  4. (C) 1999-2014 by the GRASS Development Team
  5. This program is free software under the GNU General Public License
  6. (>=v2). Read the file COPYING that comes with GRASS for details.
  7. */
  8. #include <unistd.h>
  9. #include <grass/gis.h>
  10. #include <grass/glocale.h>
  11. #define PERMANENT "PERMANENT"
  12. /*!
  13. \brief Gets units information for location
  14. Note: Allocated Key_Value structure should be freed by
  15. G_free_key_value().
  16. Prints a warning if no units information available.
  17. \return pointer to Key_Value structure with key/value pairs
  18. \return NULL on failure
  19. */
  20. struct Key_Value *G_get_projunits(void)
  21. {
  22. struct Key_Value *in_units_keys;
  23. char path[GPATH_MAX];
  24. G_file_name(path, "", UNIT_FILE, PERMANENT);
  25. if (access(path, 0) != 0) {
  26. if (G_projection() != PROJECTION_XY) {
  27. G_warning(_("<%s> file not found for location <%s>"),
  28. UNIT_FILE, G_location());
  29. }
  30. return NULL;
  31. }
  32. in_units_keys = G_read_key_value_file(path);
  33. return in_units_keys;
  34. }
  35. /*!
  36. \brief Gets projection information for location
  37. Note: Allocated Key_Value structure should be freed by
  38. G_free_key_value().
  39. Prints a warning if no projection information available.
  40. \return pointer to Key_Value structure with key/value pairs
  41. \return NULL on failure
  42. */
  43. struct Key_Value *G_get_projinfo(void)
  44. {
  45. struct Key_Value *in_proj_keys;
  46. char path[GPATH_MAX];
  47. G_file_name(path, "", PROJECTION_FILE, PERMANENT);
  48. if (access(path, 0) != 0) {
  49. if (G_projection() != PROJECTION_XY) {
  50. G_warning(_("<%s> file not found for location <%s>"),
  51. PROJECTION_FILE, G_location());
  52. }
  53. return NULL;
  54. }
  55. in_proj_keys = G_read_key_value_file(path);
  56. return in_proj_keys;
  57. }
  58. /*!
  59. \brief Gets EPSG information for the current location
  60. Note: Allocated Key_Value structure should be freed by
  61. G_free_key_value().
  62. \return pointer to Key_Value structure with key/value pairs
  63. \return NULL when EPSG code is defined for location
  64. */
  65. struct Key_Value *G_get_projepsg(void)
  66. {
  67. struct Key_Value *in_epsg_keys;
  68. char path[GPATH_MAX];
  69. G_file_name(path, "", EPSG_FILE, PERMANENT);
  70. if (access(path, 0) != 0) {
  71. if (G_projection() != PROJECTION_XY) {
  72. G_debug(1, "<%s> file not found for location <%s>",
  73. EPSG_FILE, G_location());
  74. }
  75. return NULL;
  76. }
  77. in_epsg_keys = G_read_key_value_file(path);
  78. return in_epsg_keys;
  79. }