v.db.droprow.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: v.db.droprow
  5. # AUTHOR(S): Markus Neteler
  6. # Pythonized by Martin Landa
  7. # PURPOSE: Interface to v.extract -r to drop ...
  8. # COPYRIGHT: (C) 2009 by the GRASS Development Team
  9. #
  10. # This program is free software under the GNU General Public
  11. # License (>=v2). Read the file COPYING that comes with GRASS
  12. # for details.
  13. #
  14. #############################################################################
  15. #%module
  16. #% description: Removes a vector object (point, line, area, face etc.) from a vector map through attribute selection.
  17. #% keywords: vector
  18. #% keywords: database
  19. #% keywords: attribute table
  20. #%end
  21. #%option
  22. #% key: input
  23. #% type: string
  24. #% gisprompt: old,vector,vector
  25. #% key_desc : name
  26. #% description: Vector map for which to drop vector objects
  27. #% required : yes
  28. #%end
  29. #%option
  30. #% key: output
  31. #% type: string
  32. #% gisprompt: new,vector,vector
  33. #% key_desc : name
  34. #% description: Name for output vector map
  35. #% required : yes
  36. #%end
  37. #%option
  38. #% key: layer
  39. #% type: integer
  40. #% description: Layer of attribute table to use for selection
  41. #% answer: 1
  42. #% required : no
  43. #%end
  44. #%option
  45. #% key: where
  46. #% type: string
  47. #% description: WHERE conditions for vector delete, without 'where' keyword (e.g. "elevation IS NULL")
  48. #% required : yes
  49. #%end
  50. import sys
  51. import grass.script as grass
  52. def main():
  53. # delete vectors via reverse selection
  54. ret = grass.run_command('v.extract',
  55. flags = 'r',
  56. input = options['input'], layer = options['layer'],
  57. output = options['output'], where = options['where'])
  58. if ret != 0:
  59. return 1
  60. # write cmd history:
  61. grass.vector_history(map = options['output'])
  62. return 0
  63. if __name__ == "__main__":
  64. options, flags = grass.parser()
  65. sys.exit(main())