@@ -122,9 +122,26 @@ def get_latest(
122122
123123
124124class SwissTopoClient :
125- """swisstopo client."""
125+ """swisstopo client.
126126
127- def __init__ (self ):
127+ Parameters
128+ ----------
129+ region : region-like, optional
130+ Region to get the data for. Can any argument accepted by the pyregeon library.
131+ If None, all the collection data will be returned.
132+ region_crs : crs-like, optional
133+ Coordinate reference system (CRS) of the region. Required if `region` is a naive
134+ geometry or a list of bounding box coordinates. Ignored if `region` already has
135+ a CRS.
136+
137+ """
138+
139+ def __init__ (
140+ self ,
141+ * ,
142+ region : RegionType | None = None ,
143+ region_crs : CRSType = None ,
144+ ):
128145 """Initialize a swisstopo client."""
129146 with warnings .catch_warnings ():
130147 warnings .simplefilter ("ignore" )
@@ -133,12 +150,23 @@ def __init__(self):
133150 client .add_conforms_to ("COLLECTIONS" )
134151 self ._client = client
135152
153+ if region is not None :
154+ # rather than inheriting from `RegionMixin`, we just use the
155+ # `_process_region_arg` static method
156+ self .region = (
157+ RegionMixin ._process_region_arg (region , region_crs = region_crs )
158+ .to_crs (CLIENT_CRS )
159+ .iloc [0 ]
160+ )
161+ else :
162+ # set it to so that it passes the default `None` value to the `intersects`
163+ # keyword argument in `pystac_client.client.Search`.
164+ self .region = None
165+
136166 def gdf_from_collection (
137167 self ,
138168 collection_id : str ,
139169 * ,
140- region : RegionType | None = None ,
141- region_crs : CRSType = None ,
142170 datetime : DatetimeLike | None = None ,
143171 collection_extents_crs : CRSType | None = None ,
144172 ) -> gpd .GeoDataFrame :
@@ -147,16 +175,8 @@ def gdf_from_collection(
147175 collection_extents_crs = self ._client .get_collection (
148176 collection_id
149177 ).extra_fields ["crs" ][0 ]
150- if region is not None :
151- # TODO: make the client bound to a region (i.e., inherit from `RegionMixin`)
152- # so that we only need to do this once?
153- region = (
154- RegionMixin ._process_region_arg (region , region_crs = region_crs )
155- .to_crs (CLIENT_CRS )
156- .iloc [0 ]
157- )
158178 search = self ._client .search (
159- collections = [collection_id ], intersects = region , datetime = datetime
179+ collections = [collection_id ], intersects = self . region , datetime = datetime
160180 )
161181 return gpd .GeoDataFrame (
162182 _postprocess_items_gdf (_items_to_gdf (search .items_as_dicts ()))
0 commit comments