[GRASS-SVN] r65883 - grass-addons/grass7/general/g.proj.identify

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Aug 11 01:41:59 PDT 2015


Author: krejcmat
Date: 2015-08-11 01:41:59 -0700 (Tue, 11 Aug 2015)
New Revision: 65883

Modified:
   grass-addons/grass7/general/g.proj.identify/g.proj.identify.html
   grass-addons/grass7/general/g.proj.identify/g.proj.identify.py
Log:
g.proj.identify addon: add epsg2standards

Modified: grass-addons/grass7/general/g.proj.identify/g.proj.identify.html
===================================================================
--- grass-addons/grass7/general/g.proj.identify/g.proj.identify.html	2015-08-11 07:29:15 UTC (rev 65882)
+++ grass-addons/grass7/general/g.proj.identify/g.proj.identify.html	2015-08-11 08:41:59 UTC (rev 65883)
@@ -1,11 +1,16 @@
 <h2>DESCRIPTION</h2>
 
-<em>g.proj.identify</em> allows to automaticaly identify EPSG code for given WKT prj. User can print EPSG from currnt location or for given WKT file.
+<em>g.proj.identify</em> allows to automaticaly identify EPSG code for given WKT prj.
+User can print EPSG from current location or for given WKT file.
+Conversion from given EPSG code to WKT and proj4 is supported.
 
 <h2>EXAMPLE</h2>
 <div class="code"><pre>
 print EPSG code of current Location- without parameters
 g.proj.identify
+
+print WKT and proj4 for gieven EPSG code
+g.proj.identify.py -p -w epsg=4326
 </pre></div>
 
 <h2>SEE ALSO</h2>

Modified: grass-addons/grass7/general/g.proj.identify/g.proj.identify.py
===================================================================
--- grass-addons/grass7/general/g.proj.identify/g.proj.identify.py	2015-08-11 07:29:15 UTC (rev 65882)
+++ grass-addons/grass7/general/g.proj.identify/g.proj.identify.py	2015-08-11 08:41:59 UTC (rev 65883)
@@ -20,9 +20,17 @@
 
 #%option G_OPT_F_INPUT
 #% key: wkt
+#% label: WKT prj input
 #% required: no
 #%end
 
+#%option
+#% key: epsg
+#% type: integer
+#% label: EPSG input
+#% required: no
+#%end
+
 #%flag
 #% key: p
 #% label: Proj4
@@ -30,12 +38,6 @@
 #%end
 
 #%flag
-#% key: s
-#% label: Shape prj
-#% description: Print Shape prj
-#%end
-
-#%flag
 #% key: w
 #% label: WKT
 #% description: Print WKT
@@ -62,24 +64,17 @@
                quiet=True,
                stdout_=PIPE)
         proj=proj.outputs.stdout
-        esriprj2standards(proj)
+        wkt2standards(proj)
     except:
         grass.error('WKT input error')
 
-def esriprj2standards(prj_txt):
+def wkt2standards(prj_txt):
     srs = osr.SpatialReference()
     srs.ImportFromESRI([prj_txt])
-    if flags['s']:
-        str='shape_prj=%s' % prj_txt
-        #str.rstrip()
-        print str
-        return
     if flags['w']:
         print('wkt=%s' % srs.ExportToWkt())
-        return
     if flags['p']:
         print('proj4=%s' % srs.ExportToProj4())
-        return
     srs.AutoIdentifyEPSG()
     try :
         int(srs.GetAuthorityCode(None))
@@ -87,13 +82,32 @@
     except:
         grass.error('Epsg code cannot be identified')
 
+def epsg2standards(epsg):
+    srs = osr.SpatialReference()
+    srs.ImportFromEPSG(int(epsg))
+    if flags['w']:
+        print('wkt=%s' % srs.ExportToWkt())
+    if flags['p']:
+        print('proj4=%s' % srs.ExportToProj4())
+
 def main():
-    if options['wkt']:
-        io=open(options['wkt'],'r')
-        wkt=io.read().rstrip()
-        esriprj2standards(wkt)
+    epsg=options['epsg']
+    pathwkt=options['wkt']
+    if epsg and pathwkt:
+        grass.error('Only one type of conversions can be processed concurrently')
+
+    if epsg:
+        epsg2standards(epsg)
     else:
-        grassEpsg()
+        if pathwkt:
+            try:
+                io= open(pathwkt,'r')
+                wkt=io.read().rstrip()
+                wkt2standards(wkt)
+            except IOError as e:
+                grass.error('Cannot open file %s, %s'%(e.errno, e.strerror))
+        else:
+            grassEpsg()
 
 if __name__ == "__main__":
     options, flags = grass.parser()



More information about the grass-commit mailing list