Skip to content

Commit c41830f

Browse files
committed
ENH: add grid_size to feature api
1 parent 9b8a636 commit c41830f

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 0.5.0 (2023-06-15)
4+
5+
Feature API can now query different resolutions of the data grid.
6+
37
## 0.4.0 (2023-03-02)
48

59
Added Geocoding API covering Switzerland.

udlai/feature_api.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def attribute_detail(token, attribute_id):
174174
_propagate_error(response)
175175

176176

177-
def features(token, latitude, longitude, attribute_id, index_by="id"):
177+
def features(token, latitude, longitude, attribute_id, index_by="id", grid_size=25):
178178
"""
179179
An API Endpoint that will return the attributes for provided
180180
coordinates. The API expects the attribute IDs, that can be fetched using
@@ -197,6 +197,10 @@ def features(token, latitude, longitude, attribute_id, index_by="id"):
197197
index_by : {"id", "name"}
198198
One of the ``{"id", "name"}`` denoting whether the output should be indexed
199199
using the original attribute ID or its name
200+
grid_size : {25, 75, 225, 675}
201+
Resolution of the UDL grid to be queried. Smaller resolutions are more precise
202+
but may contain gaps, larger resolutions are aggregated and are more likely to
203+
cover entirety of built up area.
200204
201205
Returns
202206
-------
@@ -261,6 +265,7 @@ def features(token, latitude, longitude, attribute_id, index_by="id"):
261265
}
262266
for x in attribute_id
263267
],
268+
"grid_size": f"grid{grid_size}",
264269
}
265270

266271
# calling the API
@@ -273,7 +278,6 @@ def features(token, latitude, longitude, attribute_id, index_by="id"):
273278
json=json_data,
274279
)
275280
if response.status_code == 200:
276-
277281
dict_raw = response.json()
278282

279283
if "error" in dict_raw:
@@ -307,6 +311,7 @@ def features(token, latitude, longitude, attribute_id, index_by="id"):
307311
}
308312
for x in attribute_id
309313
],
314+
"grid_size": f"grid{grid_size}",
310315
}
311316

312317
response = requests.post(
@@ -319,7 +324,6 @@ def features(token, latitude, longitude, attribute_id, index_by="id"):
319324
)
320325

321326
if response.status_code == 200:
322-
323327
d = defaultdict(list)
324328
missing = False
325329
for pt in response.json()["results"]:

udlai/tests/test_feature_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ def test_multi_attr(self):
106106
assert c in r.columns
107107
assert r["net_betw_speed"].notna().sum() == 2
108108

109+
def test_grid_size(self):
110+
r25 = udlai.features(token, 47.37, 8.54, [113, 172], index_by="name")
111+
r675 = udlai.features(
112+
token, 47.37, 8.54, [113, 172], index_by="name", grid_size=675
113+
)
114+
assert r25["net_betw_speed"] != r675["net_betw_speed"]
115+
109116

110117
class TestAggregate:
111118
def setup_method(self):

0 commit comments

Comments
 (0)