Skip to content

Commit

Permalink
Fix #332
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderJuestel committed Jul 20, 2024
1 parent 3bd4087 commit 6676046
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 18 deletions.
14 changes: 14 additions & 0 deletions gemgis/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -7191,6 +7191,10 @@ def load_gpx(path: str,
load_gpx_as_dict : Loading a GPX file as dict
load_gpx_as_geometry : Loading a GPX file as Shapely BaseGeometry
.. versionadded:: 1.0.x
.. versionchanged:: 1.2
"""

# Trying to import fiona but returning error if fiona is not installed
Expand Down Expand Up @@ -7246,6 +7250,8 @@ def load_gpx_as_dict(path: str,
.. versionadded:: 1.0.x
.. versionchanged:: 1.2
Example
_______
Expand Down Expand Up @@ -7279,6 +7285,10 @@ def load_gpx_as_dict(path: str,
load_gpx_as : Loading a GPX file as Collection
load_gpx_as_geometry : Loading a GPX file as Shapely BaseGeometry
.. versionadded:: 1.0.x
.. versionchanged:: 1.2
"""

# Trying to import fiona but returning error if fiona is not installed
Expand Down Expand Up @@ -7337,6 +7347,8 @@ def load_gpx_as_geometry(path: str,
.. versionadded:: 1.0.x
.. versionchanged:: 1.2
Example
_______
Expand All @@ -7353,6 +7365,8 @@ def load_gpx_as_geometry(path: str,
load_gpx : Loading a GPX file as Collection
load_gpx_as_dict : Loading a GPX file as dict
.. versionchanged:: 1.2
"""

# Trying to import fiona but returning error if fiona is not installed
Expand Down
69 changes: 51 additions & 18 deletions gemgis/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@
###############################


def load_wms(url: str): # -> owslib.wms.WebMapService:
def load_wms(url: str,
version: str = '1.3.0'): # -> owslib.wms.WebMapService:
"""Loading a WMS Service by URL
Parameters
__________
url : str
Link of the WMS Service, e.g. ``url='https://ows.terrestris.de/osm/service?'``
Link of the WMS Service, e.g. ``url='https://ows.terrestris.de/osm/service?'``.
version : str, default: ``'1.3.0'``
Version of the WMS Service, e.g. ``version='1.3.0'``.
Returns
_______
Expand All @@ -50,6 +54,8 @@ def load_wms(url: str): # -> owslib.wms.WebMapService:
.. versionadded:: 1.0.x
.. versionchanged:: 1.2
Example
_______
Expand Down Expand Up @@ -86,9 +92,14 @@ def load_wms(url: str): # -> owslib.wms.WebMapService:
if not isinstance(url, str):
raise TypeError('URL must be of type string')

# Checking that the version is provided as string
if not isinstance(version, str):
raise TypeError('The WMS Service version must be provided as string')

# Requesting the WMS Service or returning an error if a module may be missing
try:
wms = owslib.wms.WebMapService(url)
wms = owslib.wms.WebMapService(url,
version=version)

return wms
except requests.exceptions.SSLError:
Expand All @@ -97,6 +108,7 @@ def load_wms(url: str): # -> owslib.wms.WebMapService:


def load_as_map(url: str,
version: str,
layer: str,
style: str,
crs: Union[str, dict],
Expand All @@ -116,6 +128,9 @@ def load_as_map(url: str,
url : str
Link of the WMS Service, e.g. ``url='https://ows.terrestris.de/osm/service?'``
version : str, default: ``'1.3.0'``
Version of the WMS Service, e.g. ``version='1.3.0'``.
layer : str
Name of layer to be requested, e.g. ``layer='OSM-WMS'``
Expand Down Expand Up @@ -153,7 +168,6 @@ def load_as_map(url: str,
Variable to create a new directory of directory does not exist
Options include: ``True`` or ``False``, default set to ``False``
Returns
_______
Expand All @@ -162,6 +176,8 @@ def load_as_map(url: str,
.. versionadded:: 1.0.x
.. versionchanged:: 1.2
Example
_______
Expand Down Expand Up @@ -195,6 +211,10 @@ def load_as_map(url: str,
if not isinstance(url, str):
raise TypeError('URL must be of type string')

# Checking that the version is provided as string
if not isinstance(version, str):
raise TypeError('The WMS Service version must be provided as string')

# Checking if the layer name is of type string
if not isinstance(layer, str):
raise TypeError('Layers must be of type string')
Expand Down Expand Up @@ -264,7 +284,7 @@ def load_as_map(url: str,
"The file already exists. Pass overwrite_file=True to overwrite the existing file")

# Loading WMS Service
wms = load_wms(url)
wms = load_wms(url, version=version)

# Creating map object
wms_map = wms.getmap(layers=[layer], styles=[style], srs=crs, bbox=tuple([bbox[0], bbox[2], bbox[1], bbox[3]]),
Expand All @@ -287,6 +307,7 @@ def load_as_map(url: str,


def load_as_array(url: str,
version: str,
layer: str,
style: str,
crs: Union[str, dict],
Expand All @@ -304,44 +325,47 @@ def load_as_array(url: str,
__________
url : str
Link of the WMS Service, e.g. ``url='https://ows.terrestris.de/osm/service?'``
Link of the WMS Service, e.g. ``url='https://ows.terrestris.de/osm/service?'``.
version : str, default: ``'1.3.0'``
Version of the WMS Service, e.g. ``version='1.3.0'``.
layer : str
Name of layer to be requested, e.g. ``layer='OSM-WMS'``
Name of layer to be requested, e.g. ``layer='OSM-WMS'``.
style : str
Name of style of the layer, e.g. ``style='default'``
Name of style of the layer, e.g. ``style='default'``.
crs : str
String or dict containing the CRS, e.g. ``crs='EPSG:4647'``
String or dict containing the CRS, e.g. ``crs='EPSG:4647'``.
bbox : List[Union[float,int]]
List of bounding box coordinates, e.g. ``bbox=[0, 972, 0, 1069]``
List of bounding box coordinates, e.g. ``bbox=[0, 972, 0, 1069]``.
size : List[int]
List of x and y values defining the size of the image, e.g. ``size=[1000,1000]``
List of x and y values defining the size of the image, e.g. ``size=[1000,1000]``.
filetype : str
String of the image type to be downloaded, e.g. 'filetype='image/png'``
String of the image type to be downloaded, e.g. 'filetype='image/png'``.
transparent : bool
Variable if layer is transparent.
Options include: ``True`` or ``False``, default set to ``True``
Options include: ``True`` or ``False``, default set to ``True``.
save_image : bool
Variable to save image.
Options include: ``True`` or ``False``, default set to ``False``
Options include: ``True`` or ``False``, default set to ``False``.
path : str
Path and file name of the file to be saved, e.g. ``path=map.tif``
Path and file name of the file to be saved, e.g. ``path=map.tif``.
overwrite_file : bool
Variable to overwrite an already existing file.
Options include: ``True`` or ``False``, default set to ``False``
Options include: ``True`` or ``False``, default set to ``False``.
create_directory : bool
Variable to create a new directory of directory does not exist
Options include: ``True`` or ``False``, default set to ``False``
Variable to create a new directory of directory does not exist.
Options include: ``True`` or ``False``, default set to ``False``.
Returns
_______
Expand Down Expand Up @@ -372,6 +396,10 @@ def load_as_array(url: str,
load_wms : Load WMS Service
load_as_map : Load Map from WMS Service
.. versionadded:: 1.0.x
.. versionchanged:: 1.2
"""

# Trying to import owslib but returning error if owslib is not installed
Expand All @@ -396,6 +424,10 @@ def load_as_array(url: str,
if not isinstance(url, str):
raise TypeError('URL must be of type string')

# Checking that the version is provided as string
if not isinstance(version, str):
raise TypeError('The WMS Service version must be provided as string')

# Checking if the layer name is of type string
if not isinstance(layer, str):
raise TypeError('Layers must be of type string')
Expand Down Expand Up @@ -466,6 +498,7 @@ def load_as_array(url: str,

# Creating WMS map object
wms_map = load_as_map(url=url,
version=version,
layer=layer,
style=style,
crs=crs,
Expand Down

0 comments on commit 6676046

Please sign in to comment.