v.what.vect.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. #
  3. ############################################################################
  4. #
  5. # MODULE: v.what.vect
  6. # AUTHOR(S): Markus Neteler, converted to Python by Glynn Clements
  7. # PURPOSE: Uploads attributes at the location of vector points to the table.
  8. # COPYRIGHT: (C) 2005, 2008, 2011 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: Uploads vector values at positions of vector points to the table.
  17. #% keywords: vector
  18. #% keywords: sampling
  19. #% keywords: database
  20. #% keywords: position
  21. #% keywords: querying
  22. #% keywords: attribute table
  23. #%end
  24. #%option G_OPT_V_MAP
  25. #% label: Name of vector points map for which to edit attributes
  26. #%end
  27. #%option G_OPT_V_FIELD
  28. #%end
  29. #%option G_OPT_DB_COLUMN
  30. #% description: Name of attribute column to be updated with the query result
  31. #% required: yes
  32. #%end
  33. #%option G_OPT_V_MAP
  34. #% key: query_map
  35. #% label: Name of vector map to be queried
  36. #% required : yes
  37. #%end
  38. #%option G_OPT_V_FIELD
  39. #% key: query_layer
  40. #%end
  41. #%option G_OPT_DB_COLUMN
  42. #% key: query_column
  43. #% description: Name of attribute column to be queried
  44. #% required: yes
  45. #%end
  46. #%option
  47. #% key: dmax
  48. #% type: double
  49. #% description: Maximum query distance in map units
  50. #% answer: 0.0
  51. #% required: no
  52. #%end
  53. import sys
  54. from grass.script import core as grass
  55. from grass.exceptions import CalledModuleError
  56. def main():
  57. try:
  58. grass.run_command('v.distance',
  59. from_=options['map'],
  60. to=options['qmap'],
  61. column=options['column'],
  62. to_column=options['qcolumn'],
  63. upload='to_attr',
  64. dmax=options['dmax'],
  65. from_layer=options['layer'],
  66. to_layer=options['qlayer'])
  67. except CalledModuleError:
  68. return 1
  69. else:
  70. return 0
  71. if __name__ == "__main__":
  72. options, flags = grass.parser()
  73. sys.exit(main())