r.in.wms.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #!/usr/bin/env python
  2. """
  3. MODULE: r.in.wms
  4. AUTHOR(S): Stepan Turek <stepan.turek AT seznam.cz>
  5. PURPOSE: Downloads and imports data from WMS server.
  6. COPYRIGHT: (C) 2012 Stepan Turek, and by the GRASS Development Team
  7. This program is free software under the GNU General Public License
  8. (>=v2). Read the file COPYING that comes with GRASS for details.
  9. """
  10. #%module
  11. #% description: Downloads and imports data from WMS servers.
  12. #% keywords: raster
  13. #% keywords: import
  14. #% keywords: wms
  15. #%end
  16. #%option
  17. #% key: mapserver
  18. #% type: string
  19. #% description:URL of WMS server
  20. #% required: yes
  21. #%end
  22. #%option
  23. #% key: layers
  24. #% type: string
  25. #% description: Layers to request from map server
  26. #% multiple: yes
  27. #% required: yes
  28. #%end
  29. #%option G_OPT_R_OUTPUT
  30. #% description: Name for output raster map
  31. #%end
  32. #%option
  33. #% key: srs
  34. #% type: integer
  35. #% description: EPSG number of source projection for request
  36. #% guisection: Request properties
  37. #% required: yes
  38. #%end
  39. #%option
  40. #% key: region
  41. #% type: string
  42. #% description: Named region to request data for. Current region used if omitted
  43. #% guisection: Request properties
  44. #%end
  45. #%option
  46. #% key: wms_version
  47. #% type:string
  48. #% description:WMS standard
  49. #% options:1.1.1,1.3.0
  50. #% answer:1.1.1
  51. #% guisection: Request properties
  52. #%end
  53. #%option
  54. #% key: format
  55. #% type: string
  56. #% description: Image format requested from the server
  57. #% options: geotiff,tiff,jpeg,gif,png
  58. #% answer: geotiff
  59. #% guisection: Request properties
  60. #%end
  61. #%option
  62. #% key: method
  63. #% type: string
  64. #% description: Reprojection method to use
  65. #% options:near,bilinear,cubic,cubicspline
  66. #% answer:near
  67. #% guisection: Request properties
  68. #%end
  69. #%option
  70. #% key: maxcols
  71. #% type:integer
  72. #% description: Maximum columns to request at a time
  73. #% answer:400
  74. #% guisection: Request properties
  75. #%end
  76. #%option
  77. #% key: maxrows
  78. #% type: integer
  79. #% description: Maximum rows to request at a time
  80. #% answer: 300
  81. #% guisection: Request properties
  82. #%end
  83. #%option
  84. #% key: urlparams
  85. #% type:string
  86. #% description: Addition query parameters for server (only with 'd' flag)
  87. #% guisection: Request properties
  88. #%end
  89. #%option
  90. #% key: styles
  91. #% type: string
  92. #% description: Styles to request from map server
  93. #% multiple: yes
  94. #% guisection: Map style
  95. #%end
  96. #%option
  97. #% key: bgcolor
  98. #% type: string
  99. #% description: Color of map background (only with 'd' flag)
  100. #% guisection: Map style
  101. #%end
  102. #%flag
  103. #% key: o
  104. #% description: Don't request transparent data
  105. #% guisection: Map style
  106. #%end
  107. #%flag
  108. #% key: c
  109. #% description: Get capabilities
  110. #% guisection: Request properties
  111. #% suppress_required: yes
  112. #%end
  113. #%flag
  114. #% key: d
  115. #% description: Do not use GDAL WMS driver
  116. #%end
  117. import os
  118. import sys
  119. sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc', 'r.in.wms'))
  120. import grass.script as grass
  121. def main():
  122. if flags['d']:
  123. grass.debug("Using own driver")
  124. from wms_drv import WMSDrv
  125. wms = WMSDrv()
  126. else:
  127. grass.debug("Using GDAL WMS driver")
  128. from wms_gdal_drv import WMSGdalDrv
  129. wms = WMSGdalDrv()
  130. if flags['c']:
  131. wms.GetCapabilities(options)
  132. else:
  133. wms.GetMap(options, flags)
  134. return 0
  135. if __name__ == "__main__":
  136. options, flags = grass.parser()
  137. sys.exit(main())