v.what.vect.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env python3
  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. #% keyword: vector
  18. #% keyword: sampling
  19. #% keyword: database
  20. #% keyword: position
  21. #% keyword: querying
  22. #% keyword: attribute table
  23. #%end
  24. #%option G_OPT_V_MAP
  25. #% label: Name of vector points map for which to edit attributes
  26. #% guidependency: layer,column
  27. #%end
  28. #%option G_OPT_V_FIELD
  29. #% guidependency: column
  30. #%end
  31. #%option G_OPT_DB_COLUMN
  32. #% description: Name of attribute column to be updated with the query result
  33. #% required: yes
  34. #%end
  35. #%option G_OPT_V_MAP
  36. #% key: query_map
  37. #% label: Name of vector map to be queried
  38. #% required : yes
  39. #% guidependency: query_layer,query_column
  40. #%end
  41. #%option G_OPT_V_FIELD
  42. #% key: query_layer
  43. #% guidependency: query_column
  44. #%end
  45. #%option G_OPT_DB_COLUMN
  46. #% key: query_column
  47. #% description: Name of attribute column to be queried
  48. #% required: yes
  49. #%end
  50. #%option
  51. #% key: dmax
  52. #% type: double
  53. #% description: Maximum query distance in map units (meters for ll)
  54. #% answer: 0.0
  55. #% required: no
  56. #%end
  57. import sys
  58. from grass.script import core as grass
  59. from grass.exceptions import CalledModuleError
  60. def main():
  61. try:
  62. grass.run_command('v.distance',
  63. from_=options['map'],
  64. to=options['query_map'],
  65. column=options['column'],
  66. to_column=options['query_column'],
  67. upload='to_attr',
  68. dmax=options['dmax'],
  69. from_layer=options['layer'],
  70. to_layer=options['query_layer'])
  71. except CalledModuleError:
  72. return 1
  73. else:
  74. return 0
  75. if __name__ == "__main__":
  76. options, flags = grass.parser()
  77. sys.exit(main())