g.gui.vdigit.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: g.gui.vdigit
  5. # AUTHOR(S): Martin Landa <landa.martin gmail.com>
  6. # PURPOSE: wxGUI Vector Digitizer
  7. # COPYRIGHT: (C) 2007-2013 by Martin Landa, and the GRASS Development Team
  8. #
  9. # This program is free software; you can 1redistribute it and/or
  10. # modify it under the terms of the GNU General Public License as
  11. # published by the Free Software Foundation; either version 2 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful, but
  15. # WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. # General Public License for more details.
  18. #
  19. ############################################################################
  20. #%module
  21. #% description: Interactive editing and digitization of vector maps.
  22. #% keywords: general
  23. #% keywords: GUI
  24. #% keywords: vector
  25. #% keywords: editing
  26. #% keywords: digitization
  27. #%end
  28. #%option G_OPT_V_MAP
  29. #%label: Name of vector map to load
  30. #%end
  31. import os
  32. import sys
  33. import grass.script as grass
  34. import wx
  35. if __name__ == '__main__':
  36. gui_wx_path = os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython')
  37. if gui_wx_path not in sys.path:
  38. sys.path.append(gui_wx_path)
  39. from core.globalvar import CheckWxVersion
  40. from core.utils import _, GuiModuleMain
  41. from mapdisp.frame import MapFrame
  42. from core.giface import StandaloneGrassInterface
  43. from core.settings import UserSettings
  44. from vdigit.main import haveVDigit, errorMsg
  45. class VDigitMapFrame(MapFrame):
  46. def __init__(self, vectorMap):
  47. MapFrame.__init__(self, parent = None, giface = StandaloneGrassInterface(),
  48. title = _("GRASS GIS Vector Digitizer"), size = (850, 600))
  49. # load vector map
  50. mapLayer = self.GetMap().AddLayer(ltype = 'vector',
  51. command = ['d.vect', 'map=%s' % vectorMap],
  52. active = True, name = vectorMap, hidden = False, opacity = 1.0,
  53. render = True)
  54. # switch toolbar
  55. self.AddToolbar('vdigit', fixed = True)
  56. # start editing
  57. self.toolbars['vdigit'].StartEditing(mapLayer)
  58. def main():
  59. # allow immediate rendering
  60. driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
  61. if driver == 'png':
  62. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  63. else:
  64. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  65. app = wx.PySimpleApp()
  66. if not CheckWxVersion([2, 9]):
  67. wx.InitAllImageHandlers()
  68. frame = VDigitMapFrame(options['map'])
  69. frame.Show()
  70. app.MainLoop()
  71. if __name__ == "__main__":
  72. grass.set_raise_on_error(False)
  73. options, flags = grass.parser()
  74. if not haveVDigit:
  75. grass.fatal(_("Vector digitizer not available. %s") % errorMsg)
  76. if not grass.find_file(name = options['map'], element = 'vector',
  77. mapset = grass.gisenv()['MAPSET'])['fullname']:
  78. grass.fatal(_("Vector map <%s> not found in current mapset") % options['map'])
  79. GuiModuleMain(main)