TclCommandGeoUnion.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. description = '%s %s' % ("--", "Run the Union (join) geometry operation on the elements of a Geometry object.")
  12. # Dictionary of types from Tcl command, needs to be ordered
  13. arg_names = collections.OrderedDict([
  14. ('name', str),
  15. ])
  16. # Dictionary of types from Tcl command, needs to be ordered , this is for options like -optionname value
  17. option_types = collections.OrderedDict([
  18. ])
  19. # array of mandatory options for current Tcl command: required = {'name','outname'}
  20. required = ['name']
  21. # structured help for current command, args needs to be ordered
  22. help = {
  23. 'main': ('Runs a union operation (addition) on the components '
  24. 'of the geometry object. For example, if it contains '
  25. '2 intersecting polygons, this operation adds them into'
  26. 'a single larger polygon.'),
  27. 'args': collections.OrderedDict([
  28. ('name', 'Name of the Geometry Object that contain the components to be joined. Required.'),
  29. ]),
  30. 'examples': ['geo_union target_geo']
  31. }
  32. def execute(self, args, unnamed_args):
  33. """
  34. :param args:
  35. :param unnamed_args:
  36. :return:
  37. """
  38. obj_name = args['name']
  39. try:
  40. obj = self.app.collection.get_by_name(str(obj_name))
  41. except Exception:
  42. return "Could not retrieve object: %s" % obj_name
  43. if obj is None:
  44. return "Object not found: %s" % obj_name
  45. obj.union()