Преглед на файлове

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 години
родител
ревизия
1b35ff81e9
променени са 1 файла, в които са добавени 19 реда и са изтрити 9 реда
  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_mapset,
     rename_location,
     rename_location,
 )
 )
+from grass.script.core import create_environment
+from grass.script.utils import try_remove
 
 
 from core import globalvar
 from core import globalvar
 from core.gcmd import GError, GMessage, DecodeString, RunCommand
 from core.gcmd import GError, GMessage, DecodeString, RunCommand
@@ -209,7 +211,7 @@ def create_location_interactively(guiparent, grassdb):
 
 
     if gWizard.georeffile:
     if gWizard.georeffile:
         message = _(
         message = _(
-            "Do you want to import {}"
+            "Do you want to import {} "
             "to the newly created location?"
             "to the newly created location?"
         ).format(gWizard.georeffile)
         ).format(gWizard.georeffile)
         dlg = wx.MessageDialog(parent=guiparent,
         dlg = wx.MessageDialog(parent=guiparent,
@@ -219,7 +221,11 @@ def create_location_interactively(guiparent, grassdb):
                                wx.ICON_QUESTION)
                                wx.ICON_QUESTION)
         dlg.CenterOnParent()
         dlg.CenterOnParent()
         if dlg.ShowModal() == wx.ID_YES:
         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()
         dlg.Destroy()
 
 
     if gWizard.default_region:
     if gWizard.default_region:
@@ -663,27 +669,31 @@ def can_switch_mapset_interactive(guiparent, grassdb, location, mapset):
     return can_switch
     return can_switch
 
 
 
 
-def import_file(guiparent, filePath):
+def import_file(guiparent, filePath, env):
     """Tries to import file as vector or raster.
     """Tries to import file as vector or raster.
 
 
     If successful sets default region from imported map.
     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]
     mapName = os.path.splitext(os.path.basename(filePath))[0]
     vectors = RunCommand('v.in.ogr', input=filePath, flags='l',
     vectors = RunCommand('v.in.ogr', input=filePath, flags='l',
-                         read=True)
+                         read=True, env=env)
 
 
     wx.BeginBusyCursor()
     wx.BeginBusyCursor()
     wx.GetApp().Yield()
     wx.GetApp().Yield()
     if vectors:
     if vectors:
         # vector detected
         # vector detected
         returncode, error = RunCommand(
         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:
     else:
         returncode, error = RunCommand(
         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()
     wx.EndBusyCursor()
 
 
     if returncode != 0:
     if returncode != 0: