[GRASS-SVN] r46187 - in grass/trunk: include lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Wed May 4 15:36:56 EDT 2011


Author: martinl
Date: 2011-05-04 12:36:56 -0700 (Wed, 04 May 2011)
New Revision: 46187

Modified:
   grass/trunk/include/gis.h
   grass/trunk/lib/gis/proj1.c
   grass/trunk/lib/gis/proj2.c
   grass/trunk/lib/gis/proj3.c
Log:
libgis: G_database_unit_name() should return localized unit name


Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h	2011-05-04 17:07:33 UTC (rev 46186)
+++ grass/trunk/include/gis.h	2011-05-04 19:36:56 UTC (rev 46187)
@@ -64,6 +64,7 @@
 /*!
   \brief List of units
 */
+#define U_UNDEFINED    -1
 #define U_UNKNOWN       0
 #define U_ACRES		1
 #define U_HECTARES	2

Modified: grass/trunk/lib/gis/proj1.c
===================================================================
--- grass/trunk/lib/gis/proj1.c	2011-05-04 17:07:33 UTC (rev 46186)
+++ grass/trunk/lib/gis/proj1.c	2011-05-04 19:36:56 UTC (rev 46187)
@@ -1,15 +1,15 @@
 /*!
-  \file gis/proj1.c
- *
- * \brief GIS Library - Projection support (window related)
- *
- * (C) 2001-2010 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.
- *
- * \author Original author CERL
- */
+  \file lib/gis/proj1.c
+ 
+  \brief GIS Library - Projection support (window related)
+  
+  (C) 2001-2011 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.
+  
+  \author Original author CERL
+*/
 
 #include <grass/gis.h>
 
@@ -17,12 +17,13 @@
   \brief Query cartographic projection
   
   This routine returns a code indicating the projection for the active
-  region. The current values are:
+  region. The current values are (see gis.h)
 
-   - PROJECTION_XY  0 - x,y (Raw imagery)
-   - PROJECTION_UTM 1 - UTM   Universal Transverse Mercator
-   - PROJECTION_SP  2 - State Plane (in feet)
-   - PROJECTION_LL  3 - Latitude-Longitude
+   - PROJECTION_XY      0 - x,y (Raw imagery)
+   - PROJECTION_UTM     1 - UTM   Universal Transverse Mercator
+   - PROJECTION_SP      2 - State Plane (in feet)
+   - PROJECTION_LL      3 - Latitude-Longitude
+   - PROJECTION_OTHER  99 - others
 
    Others may be added in the future.
 

Modified: grass/trunk/lib/gis/proj2.c
===================================================================
--- grass/trunk/lib/gis/proj2.c	2011-05-04 17:07:33 UTC (rev 46186)
+++ grass/trunk/lib/gis/proj2.c	2011-05-04 19:36:56 UTC (rev 46187)
@@ -1,9 +1,9 @@
 /*!
-  \file gis/proj2.c
+  \file lib/gis/proj2.c
 
   \brief GIS Library - Projection support (internal subroutines)
   
-  (C) 2001-2010 by the GRASS Development Team
+  (C) 2001-2011 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.
@@ -15,12 +15,18 @@
 #include <grass/glocale.h>
 
 /*!
-  \brief Get projection units code
+  \brief Get projection units code (for internal use only)
 
   \param n projection code
 
-  \return units code
-  \return -1 if not defined
+  Supported units (see gis.h):
+   - U_UNKNOWN (XY)
+   - U_METERS  (UTM)
+   - U_FEET    (SP)
+   - U_DEGREES (LL)
+   
+  \return units code (see gis.h)
+  \return U_UNDEFINED if not defined
 */
 int G__projection_units(int n)
 {
@@ -34,8 +40,9 @@
     case PROJECTION_LL:
 	return U_DEGREES;
     default:
-	return -1;
+	return U_UNDEFINED;
     }
+    return U_UNDEFINED;
 }
 
 /*!

Modified: grass/trunk/lib/gis/proj3.c
===================================================================
--- grass/trunk/lib/gis/proj3.c	2011-05-04 17:07:33 UTC (rev 46186)
+++ grass/trunk/lib/gis/proj3.c	2011-05-04 19:36:56 UTC (rev 46187)
@@ -35,34 +35,47 @@
 }
 
 /*!
-  \brief Get database units name
+  \brief Get database units (localized) name
   
   Returns a string describing the database grid units. It returns a
-  plural form (eg. 'feet') if <i>plural</i> is true. Otherwise it
+  plural form (eg. 'feet') if <i>plural</i> is non-zero. Otherwise it
   returns a singular form (eg. 'foot').
   
-  \param plural plural form if true
+  \param plural plural form if non-zero
   
-  \return units name
+  \return localized units name
 */
 const char *G_database_unit_name(int plural)
 {
-    int n;
+    int units;
     const char *name;
-
-    switch (n = G_projection()) {
-    case PROJECTION_XY:
-    case PROJECTION_UTM:
-    case PROJECTION_LL:
-    case PROJECTION_SP:
-	return G_get_units_name(G__projection_units(n), plural, 0);
+    
+    units = G__projection_units(G_projection());
+    
+    if (units == U_UNDEFINED) {
+	name = lookup_units(plural ? "units" : "unit");
+	if (!name)
+	    return plural ? _("units") : _("unit");
+	
+	if (strcasecmp(name, "meter") == 0 || strcasecmp(name, "meters") == 0)
+	    units = U_METERS;
+	else if (strcasecmp(name, "kilometer") == 0 || strcasecmp(name, "kilometers") == 0)
+	    units = U_KILOMETERS;
+	else if (strcasecmp(name, "acre") == 0 || strcasecmp(name, "acres") == 0)
+	    units = U_ACRES;
+	else if (strcasecmp(name, "hectare") == 0 || strcasecmp(name, "hectares") == 0)
+	    units = U_HECTARES;
+	else if (strcasecmp(name, "mile") == 0 || strcasecmp(name, "miles") == 0)
+	    units = U_MILES;
+	else if (strcasecmp(name, "foot") == 0 || strcasecmp(name, "feet") == 0)
+	    units = U_FEET;
+	else if (strcasecmp(name, "degree") == 0 || strcasecmp(name, "degrees") == 0)
+	    units = U_DEGREES;
+	else
+	    units = U_UNDEFINED;
     }
-
-    name = lookup_units(plural ? "units" : "unit");
-    if (!name)
-	return plural ? "units" : "unit";
-
-    return name;
+    
+    return G_get_units_name(units, plural, FALSE);
 }
 
 /*!



More information about the grass-commit mailing list