浏览代码

Use OSRImportFromEPSG() function directly to work around recent changes
in GDAL's handling of +init=XXX PROJ.4 strings


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@31652 15284696-431f-4ddb-bdfa-cd5b030d7da7

Paul Kelly 17 年之前
父节点
当前提交
3930cbfa86
共有 4 个文件被更改,包括 41 次插入7 次删除
  1. 1 1
      general/g.proj/description.html
  2. 37 1
      general/g.proj/input.c
  3. 1 0
      general/g.proj/local_proto.h
  4. 2 5
      general/g.proj/main.c

+ 1 - 1
general/g.proj/description.html

@@ -142,7 +142,7 @@ Create a new location with the co-ordinate system referred to by ESRI-EPSG code
 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>

+ 37 - 1
general/g.proj/input.c

@@ -143,7 +143,43 @@ int input_proj4(char *proj4params)
    
     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

+ 1 - 0
general/g.proj/local_proto.h

@@ -11,6 +11,7 @@ G_PROJ_GLOBAL struct Cell_head cellhd;
 void input_currloc(void);
 int input_wkt(char *);
 int input_proj4(char *);
+int input_epsg(int);
 int input_georef(char *);
 
 /* output.c */

+ 2 - 5
general/g.proj/main.c

@@ -195,12 +195,9 @@ int main(int argc, char *argv[])
     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);