From 718437ce91b312968be225bada908bec29a17604 Mon Sep 17 00:00:00 2001 From: Veronica Date: Thu, 21 Dec 2023 13:00:46 +0100 Subject: [PATCH 1/6] v.in.wfs: enhanced for alkis data import --- scripts/v.in.wfs/v.in.wfs.html | 3 ++ scripts/v.in.wfs/v.in.wfs.py | 73 +++++++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/scripts/v.in.wfs/v.in.wfs.html b/scripts/v.in.wfs/v.in.wfs.html index 54deea77537..3592e25cbc9 100644 --- a/scripts/v.in.wfs/v.in.wfs.html +++ b/scripts/v.in.wfs/v.in.wfs.html @@ -13,6 +13,9 @@

WFS import without credentials

# run in Latitude-Longitude location (EPGS code 4326): # download "sentinel:mgrs" layer: v.in.wfs url="https://geoserver.mundialis.de/geoserver/sentinel/wfs?" name="sentinel:mgrs" output=sentinel2_mgrs +# download NRW ALKIS "ave:Flurstueck" attribute: +v.in.wfs url="https://www.wfs.nrw.de/geobasis/wfs_nw_alkis_vereinfacht?" output=wfs_alkis_vereinfacht srs=25832 +name="ave:Flurstueck" version="2.0.0" aoi="335719,5615930,354798,5636274" layer="Flurstueck"

WFS import with API key

diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py index 3d712fb6d32..52d58f6a0ac 100755 --- a/scripts/v.in.wfs/v.in.wfs.py +++ b/scripts/v.in.wfs/v.in.wfs.py @@ -6,6 +6,7 @@ # AUTHOR(S): Markus Neteler. neteler itc it # Hamish Bowman # Converted to Python by Glynn Clements +# edit by Veronica Köß # PURPOSE: WFS support # COPYRIGHT: (C) 2006-2012 Markus Neteler and the GRASS Development Team # @@ -45,6 +46,13 @@ # % required: no # %end # %option +# % key: layer +# % type: string +# % description: name of data layers to import +# % multiple: yes +# % required: yes +# %end +# %option # % key: srs # % type: string # % label: Specify alternate spatial reference system (example: EPSG:4326) @@ -52,6 +60,13 @@ # % required: no # %end # %option +# % key: aoi +# % type: string +# % description: Comma separated coordinates e.g. 335719,5615930,354798,5636274 in the region srs +# % multiple: yes +# % required: no +# %end +# %option # % key: maximum_features # % type: integer # % label: Maximum number of features to download @@ -64,6 +79,14 @@ # % description: (default: start with the first feature) # %end # %option +# % key: version +# % type: string +# % required: no +# % multiple: no +# % description: version of wfs, e.g.:1.0.0 or 2.0.0 +# % answer: 1.0.0 +# %end +# %option # % key: username # % type: string # % required: no @@ -94,21 +117,37 @@ from grass.script.utils import try_remove from grass.script import core as grass -from urllib.request import urlopen -from urllib.request import build_opener, install_opener -from urllib.request import HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler -from urllib.error import URLError, HTTPError +try: + from urllib2 import urlopen, URLError, HTTPError + from urllib2 import build_opener, install_opener + from urllib2 import HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler +except ImportError: + from urllib.request import urlopen + from urllib.request import build_opener, install_opener + from urllib.request import HTTPPasswordMgrWithDefaultRealm + from urllib.request import HTTPBasicAuthHandler + from urllib.error import URLError, HTTPError def main(): out = options["output"] wfs_url = options["url"] - request_base = "REQUEST=GetFeature&SERVICE=WFS&VERSION=1.0.0" + request_base = "REQUEST=GetFeature&SERVICE=WFS" wfs_url += request_base + version_num = options["version"] if options["name"]: - wfs_url += "&TYPENAME=" + options["name"] + if tuple([int(x) for x in version_num.split(".")]) >= (2, 0, 0): + wfs_url += "&TYPENAMES=" + options["name"] + else: + wfs_url += "&TYPENAME=" + options["name"] + + if options["aoi"]: + wfs_url += "&BBOX=" + options["aoi"] + + if options["version"]: + wfs_url += "&VERSION=" + version_num if options["srs"]: wfs_url += "&SRS=" + options["srs"] @@ -130,7 +169,12 @@ def main(): wfs_url += "&BBOX=" + bbox if flags["l"]: - wfs_url = options["url"] + "REQUEST=GetCapabilities&SERVICE=WFS&VERSION=1.0.0" + if options["version"]: + wfs_url += "&VERSION=" + options["version"] + else: + wfs_url = options["url"] + "REQUEST=GetCapabilities&SERVICE=WFS" + + print(wfs_url) tmp = grass.tempfile() tmpxml = tmp + ".xml" @@ -169,9 +213,7 @@ def main(): inf = urlopen(wfs_url) except HTTPError as e: # GTC WFS request HTTP failure - grass.fatal( - _("The server couldn't fulfill the request.\nError code: %s") % e.code - ) + grass.fatal(_("Server couldn't fulfill the request.\nError code: %s") % e.code) except URLError as e: # GTC WFS request network failure grass.fatal(_("Failed to reach the server.\nReason: %s") % e.reason) @@ -197,7 +239,16 @@ def main(): grass.message(_("Importing data...")) try: - grass.run_command("v.in.ogr", flags="o", input=tmpxml, output=out) + if options["layer"]: + grass.run_command( + "v.in.ogr", + flags="o", + input=tmpxml, + output=out, + layer=options["layer"], + ) + else: + grass.run_command("v.in.ogr", flags="o", input=tmpxml, output=out) grass.message(_("Vector map <%s> imported from WFS.") % out) except Exception: grass.message(_("WFS import failed")) From 8c4b4526a78ef2f3650b8d5308424202b015e710 Mon Sep 17 00:00:00 2001 From: Veronica Date: Mon, 22 Jan 2024 19:25:10 +0100 Subject: [PATCH 2/6] v.in.wfs: including suggestions --- scripts/v.in.wfs/v.in.wfs.py | 40 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py index 52d58f6a0ac..6487bddccee 100755 --- a/scripts/v.in.wfs/v.in.wfs.py +++ b/scripts/v.in.wfs/v.in.wfs.py @@ -6,9 +6,9 @@ # AUTHOR(S): Markus Neteler. neteler itc it # Hamish Bowman # Converted to Python by Glynn Clements -# edit by Veronica Köß +# German ALKIS support added by Veronica Köß # PURPOSE: WFS support -# COPYRIGHT: (C) 2006-2012 Markus Neteler and the GRASS Development Team +# COPYRIGHT: (C) 2006-2023 Markus Neteler and the GRASS Development Team # # This program is free software under the GNU General # Public License (>=v2). Read the file COPYING that @@ -48,9 +48,9 @@ # %option # % key: layer # % type: string -# % description: name of data layers to import +# % description: Name of data layers to import # % multiple: yes -# % required: yes +# % required: no # %end # %option # % key: srs @@ -60,13 +60,6 @@ # % required: no # %end # %option -# % key: aoi -# % type: string -# % description: Comma separated coordinates e.g. 335719,5615930,354798,5636274 in the region srs -# % multiple: yes -# % required: no -# %end -# %option # % key: maximum_features # % type: integer # % label: Maximum number of features to download @@ -117,25 +110,28 @@ from grass.script.utils import try_remove from grass.script import core as grass +""" try: from urllib2 import urlopen, URLError, HTTPError from urllib2 import build_opener, install_opener from urllib2 import HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler + except ImportError: - from urllib.request import urlopen - from urllib.request import build_opener, install_opener - from urllib.request import HTTPPasswordMgrWithDefaultRealm - from urllib.request import HTTPBasicAuthHandler - from urllib.error import URLError, HTTPError +""" +from urllib.request import urlopen +from urllib.request import build_opener, install_opener +from urllib.request import HTTPPasswordMgrWithDefaultRealm +from urllib.request import HTTPBasicAuthHandler +from urllib.error import URLError, HTTPError def main(): out = options["output"] wfs_url = options["url"] + version_num = options["version"] - request_base = "REQUEST=GetFeature&SERVICE=WFS" + request_base = "REQUEST=GetFeature&SERVICE=WFS&VERSION=" + version_num wfs_url += request_base - version_num = options["version"] if options["name"]: if tuple([int(x) for x in version_num.split(".")]) >= (2, 0, 0): @@ -143,12 +139,6 @@ def main(): else: wfs_url += "&TYPENAME=" + options["name"] - if options["aoi"]: - wfs_url += "&BBOX=" + options["aoi"] - - if options["version"]: - wfs_url += "&VERSION=" + version_num - if options["srs"]: wfs_url += "&SRS=" + options["srs"] @@ -179,7 +169,7 @@ def main(): tmp = grass.tempfile() tmpxml = tmp + ".xml" - grass.debug(wfs_url) + # grass.debug(wfs_url) # Set user and password if given if options["username"] and options["password"]: From 21cd21f1db9a3c1e92fe35ce5024dd20fa292b52 Mon Sep 17 00:00:00 2001 From: VeronicaKoess <102957661+VeronicaKoess@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:43:41 +0100 Subject: [PATCH 3/6] v.in.wfs.py: small changes based on review --- scripts/v.in.wfs/v.in.wfs.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py index 6487bddccee..db272344178 100755 --- a/scripts/v.in.wfs/v.in.wfs.py +++ b/scripts/v.in.wfs/v.in.wfs.py @@ -8,7 +8,7 @@ # Converted to Python by Glynn Clements # German ALKIS support added by Veronica Köß # PURPOSE: WFS support -# COPYRIGHT: (C) 2006-2023 Markus Neteler and the GRASS Development Team +# COPYRIGHT: (C) 2006-2024 Markus Neteler and the GRASS Development Team # # This program is free software under the GNU General # Public License (>=v2). Read the file COPYING that @@ -159,17 +159,14 @@ def main(): wfs_url += "&BBOX=" + bbox if flags["l"]: - if options["version"]: - wfs_url += "&VERSION=" + options["version"] - else: - wfs_url = options["url"] + "REQUEST=GetCapabilities&SERVICE=WFS" + wfs_url = options["url"] + "REQUEST=GetCapabilities&SERVICE=WFS" print(wfs_url) tmp = grass.tempfile() tmpxml = tmp + ".xml" - # grass.debug(wfs_url) + grass.debug(wfs_url) # Set user and password if given if options["username"] and options["password"]: From 21048e4b33e71cb61b55a09aaa01967c50483e5e Mon Sep 17 00:00:00 2001 From: VeronicaKoess <102957661+VeronicaKoess@users.noreply.github.com> Date: Tue, 6 Feb 2024 10:43:15 +0100 Subject: [PATCH 4/6] Update v.in.wfs.html --- scripts/v.in.wfs/v.in.wfs.html | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/v.in.wfs/v.in.wfs.html b/scripts/v.in.wfs/v.in.wfs.html index 3592e25cbc9..6308a4b3da4 100644 --- a/scripts/v.in.wfs/v.in.wfs.html +++ b/scripts/v.in.wfs/v.in.wfs.html @@ -14,8 +14,9 @@

WFS import without credentials

# download "sentinel:mgrs" layer: v.in.wfs url="https://geoserver.mundialis.de/geoserver/sentinel/wfs?" name="sentinel:mgrs" output=sentinel2_mgrs # download NRW ALKIS "ave:Flurstueck" attribute: -v.in.wfs url="https://www.wfs.nrw.de/geobasis/wfs_nw_alkis_vereinfacht?" output=wfs_alkis_vereinfacht srs=25832 -name="ave:Flurstueck" version="2.0.0" aoi="335719,5615930,354798,5636274" layer="Flurstueck" +# set the aoi before as region with g.region and fetch only for current reagion with r flag +v.in.wfs url="https://www.wfs.nrw.de/geobasis/wfs_nw_alkis_vereinfacht?" -r output=wfs_alkis_vereinfacht srs=25832 +name="ave:Flurstueck" version="2.0.0" layer="Flurstueck"

WFS import with API key

From 797ea809d0f5b397bb65543122f907ca984eb96c Mon Sep 17 00:00:00 2001 From: VeronicaKoess <102957661+VeronicaKoess@users.noreply.github.com> Date: Tue, 6 Feb 2024 10:44:00 +0100 Subject: [PATCH 5/6] Update v.in.wfs.py --- scripts/v.in.wfs/v.in.wfs.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py index db272344178..b098becc2ab 100755 --- a/scripts/v.in.wfs/v.in.wfs.py +++ b/scripts/v.in.wfs/v.in.wfs.py @@ -110,14 +110,6 @@ from grass.script.utils import try_remove from grass.script import core as grass -""" -try: - from urllib2 import urlopen, URLError, HTTPError - from urllib2 import build_opener, install_opener - from urllib2 import HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler - -except ImportError: -""" from urllib.request import urlopen from urllib.request import build_opener, install_opener from urllib.request import HTTPPasswordMgrWithDefaultRealm From 944ae931b90b53b4d58316ccf29cb1c4710817f4 Mon Sep 17 00:00:00 2001 From: Markus Neteler Date: Tue, 6 Feb 2024 14:19:33 +0100 Subject: [PATCH 6/6] wording fixes --- scripts/v.in.wfs/v.in.wfs.html | 4 ++-- scripts/v.in.wfs/v.in.wfs.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/v.in.wfs/v.in.wfs.html b/scripts/v.in.wfs/v.in.wfs.html index 6308a4b3da4..a2f854139eb 100644 --- a/scripts/v.in.wfs/v.in.wfs.html +++ b/scripts/v.in.wfs/v.in.wfs.html @@ -13,8 +13,8 @@

WFS import without credentials

# run in Latitude-Longitude location (EPGS code 4326): # download "sentinel:mgrs" layer: v.in.wfs url="https://geoserver.mundialis.de/geoserver/sentinel/wfs?" name="sentinel:mgrs" output=sentinel2_mgrs -# download NRW ALKIS "ave:Flurstueck" attribute: -# set the aoi before as region with g.region and fetch only for current reagion with r flag +# download NRW ALKIS "ave:Flurstueck" attribute: +# set the AOI beforehand with g.region and limit import to current region with -r flag v.in.wfs url="https://www.wfs.nrw.de/geobasis/wfs_nw_alkis_vereinfacht?" -r output=wfs_alkis_vereinfacht srs=25832 name="ave:Flurstueck" version="2.0.0" layer="Flurstueck" diff --git a/scripts/v.in.wfs/v.in.wfs.py b/scripts/v.in.wfs/v.in.wfs.py index b098becc2ab..a983b87cab4 100755 --- a/scripts/v.in.wfs/v.in.wfs.py +++ b/scripts/v.in.wfs/v.in.wfs.py @@ -76,7 +76,7 @@ # % type: string # % required: no # % multiple: no -# % description: version of wfs, e.g.:1.0.0 or 2.0.0 +# % description: version of WFS, e.g.:1.0.0 or 2.0.0 # % answer: 1.0.0 # %end # %option