g.gui.vdigit.py 3.1 KB

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