[GRASS-SVN] r65879 - in grass-addons/grass7/general: . g.proj.identify

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Aug 10 09:28:14 PDT 2015


Author: krejcmat
Date: 2015-08-10 09:28:14 -0700 (Mon, 10 Aug 2015)
New Revision: 65879

Added:
   grass-addons/grass7/general/g.proj.identify/
   grass-addons/grass7/general/g.proj.identify/Makefile
   grass-addons/grass7/general/g.proj.identify/g.proj.identify.html
   grass-addons/grass7/general/g.proj.identify/g.proj.identify.py
Log:
Module for EPSG identifying

Copied: grass-addons/grass7/general/g.proj.identify/Makefile (from rev 65421, grass-addons/grass7/general/g.proj.all/Makefile)
===================================================================
--- grass-addons/grass7/general/g.proj.identify/Makefile	                        (rev 0)
+++ grass-addons/grass7/general/g.proj.identify/Makefile	2015-08-10 16:28:14 UTC (rev 65879)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = g.proj.identify
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/general/g.proj.identify/g.proj.identify.html
===================================================================
--- grass-addons/grass7/general/g.proj.identify/g.proj.identify.html	                        (rev 0)
+++ grass-addons/grass7/general/g.proj.identify/g.proj.identify.html	2015-08-10 16:28:14 UTC (rev 65879)
@@ -0,0 +1,22 @@
+<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.
+
+<h2>EXAMPLE</h2>
+<div class="code"><pre>
+print EPSG code of current Location- without parameters
+g.proj.identify
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em>
+  <a href="g.proj.html">r.proj</a>,
+</em>
+
+<h2>AUTHORS</h2>
+
+Matej Krejci, <a href="http://geo.fsv.cvut.cz/gwiki/osgeorel">OSGeoREL</a>
+at the Czech Technical University in Prague, developed
+during <a href="http://trac.osgeo.org/grass/wiki/GSoC/2014/MetadataForGRASS">Google
+Summer of Code 2015</a> (mentors: Martin Landa)

Added: grass-addons/grass7/general/g.proj.identify/g.proj.identify.py
===================================================================
--- grass-addons/grass7/general/g.proj.identify/g.proj.identify.py	                        (rev 0)
+++ grass-addons/grass7/general/g.proj.identify/g.proj.identify.py	2015-08-10 16:28:14 UTC (rev 65879)
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+# -*- coding: utf-8
+"""
+ at module  g.proj.identify
+ at brief   Module for automatic identification of EPSG from definition of projection in WKT format.
+
+(C) 2014 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.
+
+ at author Matej Krejci <matejkrejci gmail.com> (GSoC 2015)
+"""
+
+#%module
+#% description: Autoidentify of EPSG from WKT
+#% keyword: EPSG
+#% keyword: WKT
+#% keyword: .prj
+#%end
+
+#%option G_OPT_F_INPUT
+#% key: wkt
+#% required: no
+#%end
+
+#%flag
+#% key: p
+#% label: Proj4
+#% description: Print Proj4 format
+#%end
+
+#%flag
+#% key: s
+#% label: Shape prj
+#% description: Print Shape prj
+#%end
+
+#%flag
+#% key: w
+#% label: WKT
+#% description: Print WKT
+#%end
+
+from grass.script import core as grass
+from grass.pygrass.modules import Module
+from subprocess import PIPE
+from osgeo import osr
+
+def grassEpsg():
+    proj=Module('g.proj',
+               flags='p',
+               quiet=True,
+               stdout_=PIPE)
+    proj=proj.outputs.stdout
+    for line in proj.splitlines():
+        if 'EPSG' in line:
+            epsg=line.split(':')[1].replace(' ','')
+            print('epsg=%s' % epsg)
+    try:
+        proj=Module('g.proj',
+               flags='wf',
+               quiet=True,
+               stdout_=PIPE)
+        proj=proj.outputs.stdout
+        esriprj2standards(proj)
+    except:
+        grass.error('WKT input error')
+
+def esriprj2standards(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))
+        print('epsg=%s' % srs.GetAuthorityCode(None))
+    except:
+        grass.error('Epsg code cannot be identified')
+
+def main():
+    if options['wkt']:
+        io=open(options['wkt'],'r')
+        wkt=io.read().rstrip()
+        esriprj2standards(wkt)
+    else:
+        grassEpsg()
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()



More information about the grass-commit mailing list