[GRASS-SVN] r66970 - grass/branches/releasebranch_7_0/scripts/v.import

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 28 09:13:10 PST 2015


Author: martinl
Date: 2015-11-28 09:13:10 -0800 (Sat, 28 Nov 2015)
New Revision: 66970

Modified:
   grass/branches/releasebranch_7_0/scripts/v.import/v.import.py
Log:
v.import: add new parameters <epsg> and <datum_trans> to override input SRS [news]


Modified: grass/branches/releasebranch_7_0/scripts/v.import/v.import.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.import/v.import.py	2015-11-28 17:01:07 UTC (rev 66969)
+++ grass/branches/releasebranch_7_0/scripts/v.import/v.import.py	2015-11-28 17:13:10 UTC (rev 66970)
@@ -23,8 +23,6 @@
 #% keyword: projection
 #%end
 #%option G_OPT_F_BIN_INPUT
-#% key: input
-#% required: yes
 #% description: Name of OGR datasource to be imported
 #% guisection: Input
 #%end
@@ -64,6 +62,21 @@
 #% answer: 1e-13
 #% guisection: Output
 #%end
+#%option
+#% key: epsg
+#% type: integer
+#% options: 1-1000000
+#% guisection: Input SRS
+#% description: EPSG projection code
+#%end
+#%option
+#% key: datum_trans
+#% type: integer
+#% options: -1-100
+#% guisection: Input SRS
+#% label: Index number of datum transform parameters
+#% description: -1 to list available datum transform parameters
+#%end
 #%flag
 #% key: f
 #% description: List supported OGR formats and exit
@@ -123,6 +136,14 @@
     if options['encoding']:
         vopts['encoding'] = options['encoding']
 
+    if options['datum_trans'] and options['datum_trans'] == '-1':
+        # list datum transform parameters
+        if not options['epsg']:
+            grass.fatal(_("Missing value for parameter <%s>") % 'epsg')
+        
+        return grass.run_command('g.proj', epsg=options['epsg'],
+                                 datum_trans=options['datum_trans'])
+    
     grassenv = grass.gisenv()
     tgtloc = grassenv['LOCATION_NAME']
     tgtmapset = grassenv['MAPSET']
@@ -157,15 +178,18 @@
     # switch to temp location
     os.environ['GISRC'] = str(SRCGISRC)
 
-    # compare source and target srs
-    insrs = grass.read_command('g.proj', flags='j', quiet=True)
-
+    if options['epsg']: # force given EPSG
+        kwargs = {}
+        if options['datum_trans']:
+            kwargs['datum_trans'] = options['datum_trans']
+        grass.run_command('g.proj', flags='c', epsg=options['epsg'], **kwargs)
+        
     # switch to target location
     os.environ['GISRC'] = str(tgtgisrc)
 
-    if insrs == tgtsrs:
-        # try v.in.ogr directly
-        grass.message(_("Importing <%s>...") % OGRdatasource) 
+    # try v.in.ogr directly
+    if grass.run_command('v.in.ogr', input=OGRdatasource, flags='j',
+                         errors='status', quiet=True) == 0:
         try:
             grass.run_command('v.in.ogr', input=OGRdatasource,
                               flags=vflags, **vopts)
@@ -181,6 +205,9 @@
     # switch to temp location
     os.environ['GISRC'] = str(SRCGISRC)
 
+    # print projection at verbose level
+    grass.verbose(grass.read_command('g.proj', flags='p').rstrip(os.linesep))
+    
     # make sure input is not xy
     if grass.parse_command('g.proj', flags='g')['name'] == 'xy_location_unprojected':
         grass.fatal(_("Coordinate reference system not available for input <%s>") % OGRdatasource)



More information about the grass-commit mailing list