v.what.vect.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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(
  63. "v.distance",
  64. from_=options["map"],
  65. to=options["query_map"],
  66. column=options["column"],
  67. to_column=options["query_column"],
  68. upload="to_attr",
  69. dmax=options["dmax"],
  70. from_layer=options["layer"],
  71. to_layer=options["query_layer"],
  72. )
  73. except CalledModuleError:
  74. return 1
  75. else:
  76. return 0
  77. if __name__ == "__main__":
  78. options, flags = grass.parser()
  79. sys.exit(main())