g.gui.vdigit.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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-2012 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 gettext
  34. import grass.script as grass
  35. import wx
  36. if __name__ == '__main__':
  37. sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
  38. from core.globalvar import CheckWxVersion
  39. from mapdisp.frame import MapFrame
  40. from core.giface import StandaloneGrassInterface
  41. from core.settings import UserSettings
  42. from vdigit.main import haveVDigit, errorMsg
  43. class VDigitMapFrame(MapFrame):
  44. def __init__(self, vectorMap):
  45. MapFrame.__init__(self, parent = None, giface = StandaloneGrassInterface(),
  46. title = _("GRASS GIS Vector Digitizer"), size = (850, 600))
  47. # load vector map
  48. mapLayer = self.GetMap().AddLayer(ltype = 'vector',
  49. command = ['d.vect', 'map=%s' % vectorMap],
  50. active = True, name = vectorMap, hidden = False, opacity = 1.0,
  51. render = True)
  52. # switch toolbar
  53. self.AddToolbar('vdigit', fixed = True)
  54. # start editing
  55. self.toolbars['vdigit'].StartEditing(mapLayer)
  56. def main():
  57. if not haveVDigit:
  58. grass.fatal(_("Vector digitizer not available. %s") % errorMsg)
  59. if not grass.find_file(name = options['map'], element = 'vector',
  60. mapset = grass.gisenv()['MAPSET'])['fullname']:
  61. grass.fatal(_("Vector map <%s> not found in current mapset") % options['map'])
  62. # allow immediate rendering
  63. driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
  64. if driver == 'png':
  65. os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
  66. else:
  67. os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
  68. app = wx.PySimpleApp()
  69. if not CheckWxVersion([2, 9]):
  70. wx.InitAllImageHandlers()
  71. frame = VDigitMapFrame(options['map'])
  72. frame.Show()
  73. app.MainLoop()
  74. if __name__ == "__main__":
  75. gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
  76. grass.set_raise_on_error(False)
  77. options, flags = grass.parser()
  78. main()