Procházet zdrojové kódy

libgis: G_get_projepsg() and G_database_epsg_code()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@60123 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa před 11 roky
rodič
revize
178c0b7fd0
4 změnil soubory, kde provedl 67 přidání a 12 odebrání
  1. 2 0
      include/defs/gis.h
  2. 1 0
      include/gis.h
  3. 34 1
      lib/gis/get_projinfo.c
  4. 30 11
      lib/gis/proj3.c

+ 2 - 0
include/defs/gis.h

@@ -287,6 +287,7 @@ int G_read_ellipsoid_table(int);
 /* get_projinfo.c */
 /* get_projinfo.c */
 struct Key_Value *G_get_projunits(void);
 struct Key_Value *G_get_projunits(void);
 struct Key_Value *G_get_projinfo(void);
 struct Key_Value *G_get_projinfo(void);
+struct Key_Value *G_get_projepsg(void);
 
 
 /* get_window.c */
 /* get_window.c */
 void G_get_window(struct Cell_head *);
 void G_get_window(struct Cell_head *);
@@ -552,6 +553,7 @@ const char *G_database_projection_name(void);
 const char *G_database_datum_name(void);
 const char *G_database_datum_name(void);
 const char *G_database_ellipse_name(void);
 const char *G_database_ellipse_name(void);
 double G_database_units_to_meters_factor(void);
 double G_database_units_to_meters_factor(void);
+const char *G_database_epsg_code(void);
 
 
 /* put_window.c */
 /* put_window.c */
 int G_put_window(const struct Cell_head *);
 int G_put_window(const struct Cell_head *);

+ 1 - 0
include/gis.h

@@ -95,6 +95,7 @@ static const char *GRASS_copyright __attribute__ ((unused))
 
 
 #define PROJECTION_FILE "PROJ_INFO"
 #define PROJECTION_FILE "PROJ_INFO"
 #define UNIT_FILE       "PROJ_UNITS"
 #define UNIT_FILE       "PROJ_UNITS"
+#define EPSG_FILE       "PROJ_EPSG"
 
 
 #ifdef __MINGW32__
 #ifdef __MINGW32__
 #define CONFIG_DIR "GRASS7"
 #define CONFIG_DIR "GRASS7"

+ 34 - 1
lib/gis/get_projinfo.c

@@ -3,7 +3,7 @@
   
   
   \brief GIS Library - Get projection info
   \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
   This program is free software under the GNU General Public License
   (>=v2). Read the file COPYING that comes with GRASS for details.
   (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -21,7 +21,10 @@
   Note: Allocated Key_Value structure should be freed by
   Note: Allocated Key_Value structure should be freed by
   G_free_key_value().
   G_free_key_value().
   
   
+  Prints a warning if no units information available.
+
   \return pointer to Key_Value structure with key/value pairs
   \return pointer to Key_Value structure with key/value pairs
+  \return NULL on failure
 */
 */
 struct Key_Value *G_get_projunits(void)
 struct Key_Value *G_get_projunits(void)
 {
 {
@@ -47,7 +50,10 @@ struct Key_Value *G_get_projunits(void)
   Note: Allocated Key_Value structure should be freed by
   Note: Allocated Key_Value structure should be freed by
   G_free_key_value().
   G_free_key_value().
   
   
+  Prints a warning if no projection information available.
+
   \return pointer to Key_Value structure with key/value pairs
   \return pointer to Key_Value structure with key/value pairs
+  \return NULL on failure
 */
 */
 struct Key_Value *G_get_projinfo(void)
 struct Key_Value *G_get_projinfo(void)
 {
 {
@@ -66,3 +72,30 @@ struct Key_Value *G_get_projinfo(void)
 
 
     return in_proj_keys;
     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;
+}

+ 30 - 11
lib/gis/proj3.c

@@ -1,9 +1,9 @@
 /*!
 /*!
-  \file gis/proj3.c
+  \file lib/gis/proj3.c
 
 
   \brief GIS Library - Projection support (database)
   \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
   This program is free software under the GNU General Public License
   (>=v2). Read the file COPYING that comes with GRASS for details.
   (>=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_proj(const char *);
 static const char *lookup_units(const char *);
 static const char *lookup_units(const char *);
+static const char *lookup_epsg();
 static int equal(const char *, const char *);
 static int equal(const char *, const char *);
 static int lower(char);
 static int lower(char);
 
 
 static int initialized;
 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)
 static void init(void)
 {
 {
@@ -30,12 +31,13 @@ static void init(void)
 
 
     proj_info = G_get_projinfo();
     proj_info = G_get_projinfo();
     proj_units = G_get_projunits();
     proj_units = G_get_projunits();
+    proj_epsg = G_get_projepsg();
 
 
     G_initialize_done(&initialized);
     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
   Returns a string describing the database grid units. It returns a
   plural form (eg. 'feet') if <i>plural</i> is non-zero. Otherwise it
   plural form (eg. 'feet') if <i>plural</i> is non-zero. Otherwise it
@@ -81,7 +83,7 @@ const char *G_database_unit_name(int plural)
 }
 }
 
 
 /*!
 /*!
-  \brief Query cartographic projection
+  \brief Query cartographic projection for the current location
   
   
   Returns a pointer to a string which is a printable name for
   Returns a pointer to a string which is a printable name for
   projection code <i>proj</i> (as returned by G_projection). Returns
   projection code <i>proj</i> (as returned by G_projection). Returns
@@ -153,7 +155,7 @@ double G_database_units_to_meters_factor(void)
 }
 }
 
 
 /*!
 /*!
-  \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
   Returns a pointer to the name of the map datum of the current
   database. If there is no map datum explicitely associated with the
   database. If there is no map datum explicitely associated with the
@@ -183,7 +185,7 @@ const char *G_database_datum_name(void)
 }
 }
 
 
 /*!
 /*!
-  \brief Get ellipsoid name of current database
+  \brief Get ellipsoid name for the current location
   
   
   \return pointer to valid name if ok
   \return pointer to valid name if ok
   \return NULL on error
   \return NULL on error
@@ -206,19 +208,36 @@ const char *G_database_ellipse_name(void)
     return name;
     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();
     init();
     return G_find_key_value(key, proj_info);
     return G_find_key_value(key, proj_info);
 }
 }
 
 
-static const char *lookup_units(const char *key)
+const char *lookup_units(const char *key)
 {
 {
     init();
     init();
     return G_find_key_value(key, proj_units);
     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)
     if (a == NULL || b == NULL)
 	return a == b;
 	return a == b;
@@ -230,7 +249,7 @@ static int equal(const char *a, const char *b)
     return 1;
     return 1;
 }
 }
 
 
-static int lower(char c)
+int lower(char c)
 {
 {
     if (c >= 'A' && c <= 'Z')
     if (c >= 'A' && c <= 'Z')
 	c += 'a' - 'A';
 	c += 'a' - 'A';