Browse Source

wxGUI: fix importing data when new location was created (#1416)

Previously it imported the data into the current mapset not the new one,
also sets the default region from that data, previously it extended the region which is not
appropriate here.
Anna Petrasova 4 năm trước cách đây
mục cha
commit
1b35ff81e9
1 tập tin đã thay đổi với 19 bổ sung9 xóa
  1. 19 9
      gui/wxpython/startup/guiutils.py

+ 19 - 9
gui/wxpython/startup/guiutils.py

@@ -41,6 +41,8 @@ from grass.grassdb.manage import (
     rename_mapset,
     rename_location,
 )
+from grass.script.core import create_environment
+from grass.script.utils import try_remove
 
 from core import globalvar
 from core.gcmd import GError, GMessage, DecodeString, RunCommand
@@ -209,7 +211,7 @@ def create_location_interactively(guiparent, grassdb):
 
     if gWizard.georeffile:
         message = _(
-            "Do you want to import {}"
+            "Do you want to import {} "
             "to the newly created location?"
         ).format(gWizard.georeffile)
         dlg = wx.MessageDialog(parent=guiparent,
@@ -219,7 +221,11 @@ def create_location_interactively(guiparent, grassdb):
                                wx.ICON_QUESTION)
         dlg.CenterOnParent()
         if dlg.ShowModal() == wx.ID_YES:
-            import_file(guiparent, gWizard.georeffile)
+            gisrc_file, env = create_environment(gWizard.grassdatabase,
+                                                 gWizard.location,
+                                                 'PERMANENT')
+            import_file(guiparent, gWizard.georeffile, env)
+            try_remove(gisrc_file)
         dlg.Destroy()
 
     if gWizard.default_region:
@@ -663,27 +669,31 @@ def can_switch_mapset_interactive(guiparent, grassdb, location, mapset):
     return can_switch
 
 
-def import_file(guiparent, filePath):
+def import_file(guiparent, filePath, env):
     """Tries to import file as vector or raster.
 
     If successful sets default region from imported map.
     """
-    RunCommand('db.connect', flags='c')
+    RunCommand('db.connect', flags='c', env=env)
     mapName = os.path.splitext(os.path.basename(filePath))[0]
     vectors = RunCommand('v.in.ogr', input=filePath, flags='l',
-                         read=True)
+                         read=True, env=env)
 
     wx.BeginBusyCursor()
     wx.GetApp().Yield()
     if vectors:
         # vector detected
         returncode, error = RunCommand(
-            'v.in.ogr', input=filePath, output=mapName, flags='e',
-            getErrorMsg=True)
+            'v.in.ogr', input=filePath, output=mapName,
+            getErrorMsg=True, env=env)
+        if returncode == 0:
+            RunCommand('g.region', flags='s', vector=mapName, env=env)
     else:
         returncode, error = RunCommand(
-            'r.in.gdal', input=filePath, output=mapName, flags='e',
-            getErrorMsg=True)
+            'r.in.gdal', input=filePath, output=mapName,
+            getErrorMsg=True, env=env)
+        if returncode == 0:
+            RunCommand('g.region', flags='s', raster=mapName, env=env)
     wx.EndBusyCursor()
 
     if returncode != 0: