Forráskód Böngészése

Convert v.in.wfs to Python

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33523 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 16 éve
szülő
commit
9c642a250f
1 módosított fájl, 65 hozzáadás és 0 törlés
  1. 65 0
      scripts/v.in.wfs/v.in.wfs.py

+ 65 - 0
scripts/v.in.wfs/v.in.wfs.py

@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:	v.in.wfs
+# AUTHOR(S):	Markus Neteler. neteler itc it
+#               Hamish Bowman (fixes)
+#               Converted to Python by Glynn Clements
+# PURPOSE:	WFS support
+# COPYRIGHT:	(C) 2006, 2007, 2008 Markus Neteler and GRASS Development Team
+#
+#		This program is free software under the GNU General Public
+#		License (>=v2). Read the file COPYING that comes with GRASS
+#		for details.
+#
+# GetFeature example:
+# http://mapserver.gdf-hannover.de/cgi-bin/grassuserwfs?REQUEST=GetFeature&SERVICE=WFS&VERSION=1.0.0
+#############################################################################
+
+#%Module
+#% description: import GetFeature from WFS
+#%End
+#%option
+#% key: wfs
+#% type: string
+#% description: GetFeature URL starting with http
+#%End
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new,vector,vector
+#% description: Vector output map
+#% required : yes
+#%End
+
+import os
+import grass
+import urllib
+
+def main():
+    out = options['output']
+    wfs_url = options['wfs']
+
+    tmp = grass.tempfile()
+    tmpxml = tmp + '.xml'
+
+    grass.message("Retrieving data ...")
+    inf = urllib.urlopen(wfs_url)
+    outf = file(tmpxml, 'wb')
+    while True:
+	s = inf.read()
+	if not s:
+	    break
+	outf.write(s)
+    inf.close()
+    outf.close()
+
+    grass.run_command('v.in.ogr', flags = 'o', dsn = tmpxml, out = out)
+    os.remove(tmpxml)
+
+    grass.message("Vector points map <%s> imported from WFS." % out)
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()