v.in.wfs.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python
  2. ############################################################################
  3. #
  4. # MODULE: v.in.wfs
  5. # AUTHOR(S): Markus Neteler. neteler itc it
  6. # Hamish Bowman (fixes)
  7. # Converted to Python by Glynn Clements
  8. # PURPOSE: WFS support
  9. # COPYRIGHT: (C) 2006, 2007, 2008 Markus Neteler and GRASS Development Team
  10. #
  11. # This program is free software under the GNU General Public
  12. # License (>=v2). Read the file COPYING that comes with GRASS
  13. # for details.
  14. #
  15. # GetFeature example:
  16. # http://mapserver.gdf-hannover.de/cgi-bin/grassuserwfs?REQUEST=GetFeature&SERVICE=WFS&VERSION=1.0.0
  17. #############################################################################
  18. #%Module
  19. #% description: import GetFeature from WFS
  20. #%End
  21. #%option
  22. #% key: wfs
  23. #% type: string
  24. #% description: GetFeature URL starting with http
  25. #%End
  26. #%option
  27. #% key: output
  28. #% type: string
  29. #% gisprompt: new,vector,vector
  30. #% description: Vector output map
  31. #% required : yes
  32. #%End
  33. import os
  34. import grass
  35. import urllib
  36. def main():
  37. out = options['output']
  38. wfs_url = options['wfs']
  39. tmp = grass.tempfile()
  40. tmpxml = tmp + '.xml'
  41. grass.message("Retrieving data ...")
  42. inf = urllib.urlopen(wfs_url)
  43. outf = file(tmpxml, 'wb')
  44. while True:
  45. s = inf.read()
  46. if not s:
  47. break
  48. outf.write(s)
  49. inf.close()
  50. outf.close()
  51. grass.run_command('v.in.ogr', flags = 'o', dsn = tmpxml, out = out)
  52. grass.try_remove(tmpxml)
  53. grass.message("Vector points map <%s> imported from WFS." % out)
  54. if __name__ == "__main__":
  55. options, flags = grass.parser()
  56. main()