[GRASS-SVN] r31652 - grass/trunk/general/g.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 7 09:15:50 EDT 2008


Author: pkelly
Date: 2008-06-07 09:15:50 -0400 (Sat, 07 Jun 2008)
New Revision: 31652

Modified:
   grass/trunk/general/g.proj/description.html
   grass/trunk/general/g.proj/input.c
   grass/trunk/general/g.proj/local_proto.h
   grass/trunk/general/g.proj/main.c
Log:
Use OSRImportFromEPSG() function directly to work around recent changes
in GDAL's handling of +init=XXX PROJ.4 strings


Modified: grass/trunk/general/g.proj/description.html
===================================================================
--- grass/trunk/general/g.proj/description.html	2008-06-07 12:56:26 UTC (rev 31651)
+++ grass/trunk/general/g.proj/description.html	2008-06-07 13:15:50 UTC (rev 31652)
@@ -142,7 +142,7 @@
 900913 (<a href="http://spatialreference.org/ref/user/6/">Google Mercator Projection</a>)<br>
 
 <div class="code"><pre>
-g.proj -c proj4="+init=epsg:900913" loc=google
+g.proj -c epsg=900913 loc=google
 </pre></div>
 
 <p>

Modified: grass/trunk/general/g.proj/input.c
===================================================================
--- grass/trunk/general/g.proj/input.c	2008-06-07 12:56:26 UTC (rev 31651)
+++ grass/trunk/general/g.proj/input.c	2008-06-07 13:15:50 UTC (rev 31652)
@@ -143,8 +143,44 @@
    
     return ret;
 }
-       
+
 /**
+ * \brief Read projection information corresponding to an EPSG co-ordinate 
+ *        system number
+ * 
+ * Determines projection information corresponding to an EPSG co-ordinate 
+ * system number and stores in global structs projinfo and projunits.
+ * Populates global cellhd with default region information.
+ * 
+ * \param epsg_num    EPSG number for co-ordinate system
+ * 
+ * \return        2 if a projected or lat/long co-ordinate system has been
+ *                defined; 1 if an unreferenced XY co-ordinate system has
+ *                been defined
+ **/
+
+int input_epsg(int epsg_num)
+{
+    OGRSpatialReferenceH hSRS;
+    int ret = 0;
+
+    /* Set finder function for locating OGR csv co-ordinate system tables */
+    SetCSVFilenameHook( GPJ_set_csv_loc );
+
+    hSRS = OSRNewSpatialReference(NULL);
+    if (OSRImportFromEPSG(hSRS, epsg_num) != OGRERR_NONE)
+        G_fatal_error(_("Unable to translate EPSG code"));
+
+    ret = GPJ_osr_to_grass(&cellhd, &projinfo, &projunits, hSRS, 0);
+
+    OSRDestroySpatialReference(hSRS);
+   
+    set_default_region();
+   
+    return ret;
+}
+
+/**
  * \brief Read projection and region information associated with a 
  *        georeferenced file
  * 

Modified: grass/trunk/general/g.proj/local_proto.h
===================================================================
--- grass/trunk/general/g.proj/local_proto.h	2008-06-07 12:56:26 UTC (rev 31651)
+++ grass/trunk/general/g.proj/local_proto.h	2008-06-07 13:15:50 UTC (rev 31652)
@@ -11,6 +11,7 @@
 void input_currloc(void);
 int input_wkt(char *);
 int input_proj4(char *);
+int input_epsg(int);
 int input_georef(char *);
 
 /* output.c */

Modified: grass/trunk/general/g.proj/main.c
===================================================================
--- grass/trunk/general/g.proj/main.c	2008-06-07 12:56:26 UTC (rev 31651)
+++ grass/trunk/general/g.proj/main.c	2008-06-07 13:15:50 UTC (rev 31652)
@@ -195,12 +195,9 @@
     else if (inproj4->answer)
         /* Input in PROJ.4 format */
         input_proj4(inproj4->answer);
-    else if (inepsg->answer) {
+    else if (inepsg->answer)
 	/* Input from EPSG code */
-	char buffer[64];
-	sprintf(buffer, "+init=epsg:%s", inepsg->answer);
-	input_proj4(buffer);
-    }
+	input_epsg(atoi(inepsg->answer));
     else 
         /* Input from georeferenced file */
         input_georef(ingeo->answer);



More information about the grass-commit mailing list