TclCommandGeoUnion.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from tclCommands.TclCommand import TclCommand
  2. import collections
  3. class TclCommandGeoUnion(TclCommand):
  4. """
  5. Tcl shell command to run a union (addition) operation on the
  6. components of a geometry object.
  7. example:
  8. """
  9. # List of all command aliases, to be able use old names for backward compatibility (add_poly, add_polygon)
  10. aliases = ['geo_union']
  11. # Dictionary of types from Tcl command, needs to be ordered
  12. arg_names = collections.OrderedDict([
  13. ('name', str),
  14. ])
  15. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  16. option_types = collections.OrderedDict([
  17. ])
  18. # array of mandatory options for current Tcl command: required = {'name','outname'}
  19. required = ['name']
  20. # structured help for current command, args needs to be ordered
  21. help = {
  22. 'main': ('Runs a union operation (addition) on the components '
  23. 'of the geometry object. For example, if it contains '
  24. '2 intersecting polygons, this opperation adds them into'
  25. 'a single larger polygon.'),
  26. 'args': collections.OrderedDict([
  27. ('name', 'Name of the Geometry Object.'),
  28. ]),
  29. 'examples': []
  30. }
  31. def execute(self, args, unnamed_args):
  32. """
  33. :param args:
  34. :param unnamed_args:
  35. :return:
  36. """
  37. obj_name = args['name']
  38. try:
  39. obj = self.app.collection.get_by_name(str(obj_name))
  40. except:
  41. return "Could not retrieve object: %s" % obj_name
  42. if obj is None:
  43. return "Object not found: %s" % obj_name
  44. obj.union()