[GRASS-SVN] r60123 - in grass/trunk: include include/defs lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon May 5 13:58:48 PDT 2014
Author: martinl
Date: 2014-05-05 13:58:48 -0700 (Mon, 05 May 2014)
New Revision: 60123
Modified:
grass/trunk/include/defs/gis.h
grass/trunk/include/gis.h
grass/trunk/lib/gis/get_projinfo.c
grass/trunk/lib/gis/proj3.c
Log:
libgis: G_get_projepsg() and G_database_epsg_code()
Modified: grass/trunk/include/defs/gis.h
===================================================================
--- grass/trunk/include/defs/gis.h 2014-05-05 19:40:05 UTC (rev 60122)
+++ grass/trunk/include/defs/gis.h 2014-05-05 20:58:48 UTC (rev 60123)
@@ -287,6 +287,7 @@
/* get_projinfo.c */
struct Key_Value *G_get_projunits(void);
struct Key_Value *G_get_projinfo(void);
+struct Key_Value *G_get_projepsg(void);
/* get_window.c */
void G_get_window(struct Cell_head *);
@@ -552,6 +553,7 @@
const char *G_database_datum_name(void);
const char *G_database_ellipse_name(void);
double G_database_units_to_meters_factor(void);
+const char *G_database_epsg_code(void);
/* put_window.c */
int G_put_window(const struct Cell_head *);
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2014-05-05 19:40:05 UTC (rev 60122)
+++ grass/trunk/include/gis.h 2014-05-05 20:58:48 UTC (rev 60123)
@@ -95,6 +95,7 @@
#define PROJECTION_FILE "PROJ_INFO"
#define UNIT_FILE "PROJ_UNITS"
+#define EPSG_FILE "PROJ_EPSG"
#ifdef __MINGW32__
#define CONFIG_DIR "GRASS7"
Modified: grass/trunk/lib/gis/get_projinfo.c
===================================================================
--- grass/trunk/lib/gis/get_projinfo.c 2014-05-05 19:40:05 UTC (rev 60122)
+++ grass/trunk/lib/gis/get_projinfo.c 2014-05-05 20:58:48 UTC (rev 60123)
@@ -3,7 +3,7 @@
\brief GIS Library - Get projection info
- (C) 1999-2008, 2011 by the GRASS Development Team
+ (C) 1999-2014 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@@ -21,7 +21,10 @@
Note: Allocated Key_Value structure should be freed by
G_free_key_value().
+ Prints a warning if no units information available.
+
\return pointer to Key_Value structure with key/value pairs
+ \return NULL on failure
*/
struct Key_Value *G_get_projunits(void)
{
@@ -47,7 +50,10 @@
Note: Allocated Key_Value structure should be freed by
G_free_key_value().
+ Prints a warning if no projection information available.
+
\return pointer to Key_Value structure with key/value pairs
+ \return NULL on failure
*/
struct Key_Value *G_get_projinfo(void)
{
@@ -66,3 +72,30 @@
return in_proj_keys;
}
+
+/*!
+ \brief Gets EPSG information for the current location
+
+ Note: Allocated Key_Value structure should be freed by
+ G_free_key_value().
+
+ \return pointer to Key_Value structure with key/value pairs
+ \return NULL when EPSG code is defined for location
+*/
+struct Key_Value *G_get_projepsg(void)
+{
+ struct Key_Value *in_epsg_keys;
+ char path[GPATH_MAX];
+
+ G_file_name(path, "", EPSG_FILE, PERMANENT);
+ if (access(path, 0) != 0) {
+ if (G_projection() != PROJECTION_XY) {
+ G_debug(1, "<%s> file not found for location <%s>",
+ EPSG_FILE, G_location());
+ }
+ return NULL;
+ }
+ in_epsg_keys = G_read_key_value_file(path);
+
+ return in_epsg_keys;
+}
Modified: grass/trunk/lib/gis/proj3.c
===================================================================
--- grass/trunk/lib/gis/proj3.c 2014-05-05 19:40:05 UTC (rev 60122)
+++ grass/trunk/lib/gis/proj3.c 2014-05-05 20:58:48 UTC (rev 60123)
@@ -1,9 +1,9 @@
/*!
- \file gis/proj3.c
+ \file lib/gis/proj3.c
\brief GIS Library - Projection support (database)
- (C) 2001-2010 by the GRASS Development Team
+ (C) 2001-2014 by the GRASS Development Team
This program is free software under the GNU General Public License
(>=v2). Read the file COPYING that comes with GRASS for details.
@@ -17,11 +17,12 @@
static const char *lookup_proj(const char *);
static const char *lookup_units(const char *);
+static const char *lookup_epsg();
static int equal(const char *, const char *);
static int lower(char);
static int initialized;
-static struct Key_Value *proj_info, *proj_units;
+static struct Key_Value *proj_info, *proj_units, *proj_epsg;
static void init(void)
{
@@ -30,12 +31,13 @@
proj_info = G_get_projinfo();
proj_units = G_get_projunits();
+ proj_epsg = G_get_projepsg();
G_initialize_done(&initialized);
}
/*!
- \brief Get database units (localized) name
+ \brief Get units (localized) name for the current location
Returns a string describing the database grid units. It returns a
plural form (eg. 'feet') if <i>plural</i> is non-zero. Otherwise it
@@ -81,7 +83,7 @@
}
/*!
- \brief Query cartographic projection
+ \brief Query cartographic projection for the current location
Returns a pointer to a string which is a printable name for
projection code <i>proj</i> (as returned by G_projection). Returns
@@ -153,7 +155,7 @@
}
/*!
- \brief Get datum name for database
+ \brief Get datum name for the current location
Returns a pointer to the name of the map datum of the current
database. If there is no map datum explicitely associated with the
@@ -183,7 +185,7 @@
}
/*!
- \brief Get ellipsoid name of current database
+ \brief Get ellipsoid name for the current location
\return pointer to valid name if ok
\return NULL on error
@@ -206,20 +208,37 @@
return name;
}
-static const char *lookup_proj(const char *key)
+/*!
+ \brief Get EPGS code for the current location
+
+ \return pointer to valid EPSG code on success
+ \return NULL on error
+*/
+const char *G_database_epsg_code(void)
{
+ return lookup_epsg();
+}
+
+const char *lookup_proj(const char *key)
+{
init();
return G_find_key_value(key, proj_info);
}
-static const char *lookup_units(const char *key)
+const char *lookup_units(const char *key)
{
init();
return G_find_key_value(key, proj_units);
}
-static int equal(const char *a, const char *b)
+const char *lookup_epsg()
{
+ init();
+ return G_find_key_value("epsg", proj_epsg);
+}
+
+int equal(const char *a, const char *b)
+{
if (a == NULL || b == NULL)
return a == b;
while (*a && *b)
@@ -230,7 +249,7 @@
return 1;
}
-static int lower(char c)
+int lower(char c)
{
if (c >= 'A' && c <= 'Z')
c += 'a' - 'A';
More information about the grass-commit
mailing list