diff --git a/pygeoapi/provider/speckle.py b/pygeoapi/provider/speckle.py index d976d75..dc2deb2 100644 --- a/pygeoapi/provider/speckle.py +++ b/pygeoapi/provider/speckle.py @@ -157,50 +157,14 @@ class SpeckleProvider(BaseProvider): return fields def _load(self, skip_geometry=None, properties=[], select_properties=[]): - """Validate Speckle data""" + """Load and validate Speckle data""" - from pygeoapi.provider.speckle_utils.crs_utils import create_crs_from_authid + from pygeoapi.provider.speckle_utils.url_utils import get_set_url_parameters if self.data == "": return - raise ValueError( - "Please provide Speckle project link as an argument, e.g.: http://localhost:5000/?limit=100000&speckleUrl=https://app.speckle.systems/projects/55a29f3e9d/models/2d497a381d" - ) - if ( - isinstance(self.data, str) - and "speckleurl=" in self.data.lower() - and "projects" in self.data - and "models" in self.data - ): - crs_authid = "" - for item in self.data.lower().split("&"): - - # if CRS authid is found, rest will be ignored - if "crsauthid=" in item: - crs_authid = item.split("crsauthid=")[1] - elif "lat=" in item: - try: - self.lat = float(item.split("lat=")[1]) - except: - pass - # raise ValueError(f"Invalid Lat input, must be numeric: {item.split('lat=')[1]}") - elif "lon=" in item: - try: - self.lon = float(item.split("lon=")[1]) - except: - pass - # raise ValueError(f"Invalid Lon input, must be numeric: {item.split('lon=')[1]}") - elif "northdegrees=" in item: - try: - self.north_degrees = float(item.split("northdegrees=")[1]) - except: - pass - # raise ValueError(f"Invalid NorthDegrees input, must be numeric: {item.split('northdegrees=')[1]}") - - # if CRS assigned, create one: - if len(crs_authid)>3: - create_crs_from_authid(self) + get_set_url_parameters(self) # check if it's a new request (self.data was updated and doesn't match self.url) new_request = False diff --git a/pygeoapi/provider/speckle_utils/url_utils.py b/pygeoapi/provider/speckle_utils/url_utils.py new file mode 100644 index 0000000..6a2d58a --- /dev/null +++ b/pygeoapi/provider/speckle_utils/url_utils.py @@ -0,0 +1,43 @@ + + +from typing import Dict + + +def get_set_url_parameters(self: "SpeckleProvider"): + + from pygeoapi.provider.speckle_utils.crs_utils import create_crs_from_authid + + if ( + isinstance(self.data, str) + and "speckleurl=" in self.data.lower() + and "projects" in self.data + and "models" in self.data + ): + crs_authid = "" + for item in self.data.lower().split("&"): + + # if CRS authid is found, rest will be ignored + if "crsauthid=" in item: + crs_authid = item.split("crsauthid=")[1] + elif "lat=" in item: + try: + self.lat = float(item.split("lat=")[1]) + except: + pass + # raise ValueError(f"Invalid Lat input, must be numeric: {item.split('lat=')[1]}") + elif "lon=" in item: + try: + self.lon = float(item.split("lon=")[1]) + except: + pass + # raise ValueError(f"Invalid Lon input, must be numeric: {item.split('lon=')[1]}") + elif "northdegrees=" in item: + try: + self.north_degrees = float(item.split("northdegrees=")[1]) + except: + pass + # raise ValueError(f"Invalid NorthDegrees input, must be numeric: {item.split('northdegrees=')[1]}") + + # if CRS parameter present, create and assign CRS: + if len(crs_authid)>3: + create_crs_from_authid(self)