GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72645
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
get_projinfo.c
Go to the documentation of this file.
1 /*!
2  \file lib/gis/get_projinfo.c
3 
4  \brief GIS Library - Get projection info
5 
6  (C) 1999-2014 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 */
11 
12 #include <unistd.h>
13 #include <grass/gis.h>
14 #include <grass/glocale.h>
15 
16 #define PERMANENT "PERMANENT"
17 
18 /*!
19  \brief Gets units information for location
20 
21  Note: Allocated Key_Value structure should be freed by
22  G_free_key_value().
23 
24  Prints a warning if no units information available.
25 
26  \return pointer to Key_Value structure with key/value pairs
27  \return NULL on failure
28 */
30 {
31  struct Key_Value *in_units_keys;
32  char path[GPATH_MAX];
33 
34  G_file_name(path, "", UNIT_FILE, PERMANENT);
35  if (access(path, 0) != 0) {
36  if (G_projection() != PROJECTION_XY) {
37  G_warning(_("<%s> file not found for location <%s>"),
39  }
40  return NULL;
41  }
42  in_units_keys = G_read_key_value_file(path);
43 
44  return in_units_keys;
45 }
46 
47 /*!
48  \brief Gets projection information for location
49 
50  Note: Allocated Key_Value structure should be freed by
51  G_free_key_value().
52 
53  Prints a warning if no projection information available.
54 
55  \return pointer to Key_Value structure with key/value pairs
56  \return NULL on failure
57 */
59 {
60  struct Key_Value *in_proj_keys;
61  char path[GPATH_MAX];
62 
64  if (access(path, 0) != 0) {
65  if (G_projection() != PROJECTION_XY) {
66  G_warning(_("<%s> file not found for location <%s>"),
68  }
69  return NULL;
70  }
71  in_proj_keys = G_read_key_value_file(path);
72 
73  return in_proj_keys;
74 }
75 
76 /*!
77  \brief Gets EPSG information for the current location
78 
79  Note: Allocated Key_Value structure should be freed by
80  G_free_key_value().
81 
82  \return pointer to Key_Value structure with key/value pairs
83  \return NULL when EPSG code is defined for location
84 */
86 {
87  struct Key_Value *in_epsg_keys;
88  char path[GPATH_MAX];
89 
90  G_file_name(path, "", EPSG_FILE, PERMANENT);
91  if (access(path, 0) != 0) {
92  if (G_projection() != PROJECTION_XY) {
93  G_debug(1, "<%s> file not found for location <%s>",
95  }
96  return NULL;
97  }
98  in_epsg_keys = G_read_key_value_file(path);
99 
100  return in_epsg_keys;
101 }
const char * G_location(void)
Get current location name.
Definition: location.c:32
#define PERMANENT
Definition: get_projinfo.c:16
struct Key_Value * G_get_projunits(void)
Gets units information for location.
Definition: get_projinfo.c:29
#define PROJECTION_XY
Projection code - XY coordinate system (unreferenced data)
Definition: gis.h:93
#define NULL
Definition: ccmath.h:32
struct Key_Value * G_read_key_value_file(const char *file)
Read key/values pairs from file.
Definition: key_value3.c:53
char * G_file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
Definition: file_name.c:38
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
#define GPATH_MAX
Definition: gis.h:151
struct Key_Value * G_get_projinfo(void)
Gets projection information for location.
Definition: get_projinfo.c:58
Definition: gis.h:479
struct Key_Value * G_get_projepsg(void)
Gets EPSG information for the current location.
Definition: get_projinfo.c:85
#define EPSG_FILE
Definition: gis.h:105
Definition: path.h:16
#define _(str)
Definition: glocale.h:13
#define UNIT_FILE
Definition: gis.h:104
int G_projection(void)
Query cartographic projection.
Definition: proj1.c:32
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:204
#define PROJECTION_FILE
Definition: gis.h:103