r.in.wms.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #!/usr/bin/env python
  2. """
  3. MODULE: r.in.wms2
  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. #%end
  38. #%option
  39. #% key: region
  40. #% type: string
  41. #% description: Named region to request data for. Current region used if omitted
  42. #% guisection: Request properties
  43. #%end
  44. #%option
  45. #% key: wms_version
  46. #% type:string
  47. #% description:WMS standard
  48. #% options:1.1.1,1.3.0
  49. #% answer:1.1.1
  50. #% guisection: Request properties
  51. #%end
  52. #%option
  53. #% key: format
  54. #% type: string
  55. #% description: Image format requested from the server
  56. #% options: geotiff,tiff,jpeg,gif,png
  57. #% answer: geotiff
  58. #% guisection: Request properties
  59. #%end
  60. #%option
  61. #% key: method
  62. #% type: string
  63. #% description: Reprojection method to use
  64. #% options:near,bilinear,cubic,cubicspline
  65. #% answer:near
  66. #% guisection: Request properties
  67. #%end
  68. #%option
  69. #% key: maxcols
  70. #% type:integer
  71. #% description: Maximum columns to request at a time
  72. #% answer:400
  73. #% guisection: Request properties
  74. #%end
  75. #%option
  76. #% key: maxrows
  77. #% type: integer
  78. #% description: Maximum rows to request at a time
  79. #% answer: 300
  80. #% guisection: Request properties
  81. #%end
  82. #%option
  83. #% key: urlparams
  84. #% type:string
  85. #% description: Addition query parameters for server (only with 'd' flag)
  86. #% guisection: Request properties
  87. #%end
  88. #%option
  89. #% key: styles
  90. #% type: string
  91. #% description: Styles to request from map server
  92. #% multiple: yes
  93. #% guisection: Map style
  94. #%end
  95. #%option
  96. #% key: bgcolor
  97. #% type: string
  98. #% description: Color of map background (only with 'd' flag)
  99. #% guisection: Map style
  100. #%end
  101. #%flag
  102. #% key: o
  103. #% description: Don't request transparent data
  104. #% guisection: Map style
  105. #%end
  106. #%flag
  107. #% key: c
  108. #% description: Get capabilities
  109. #% guisection: Request properties
  110. #% suppress_required: yes
  111. #%end
  112. #%flag
  113. #% key: d
  114. #% description: Do not use GDAL WMS driver
  115. #%end
  116. import os
  117. import sys
  118. sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc', 'r.in.wms2'))
  119. import grass.script as grass
  120. def main():
  121. if flags['d']:
  122. grass.debug("Using own driver")
  123. from wms_drv import WMSDrv
  124. wms = WMSDrv()
  125. else:
  126. grass.debug("Using GDAL WMS driver")
  127. from wms_gdal_drv import WMSGdalDrv
  128. wms = WMSGdalDrv()
  129. if flags['c']:
  130. wms.GetCapabilities(options)
  131. else:
  132. wms.GetMap(options, flags)
  133. return 0
  134. if __name__ == "__main__":
  135. options, flags = grass.parser()
  136. sys.exit(main())