Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust to new oqt schema #275

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions sketch_map_tool/oqt_analyses/oqt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@
OQT_REPORT_NAME = "sketchmap-fitness"


def bbox_to_polygon(bbox: Bbox) -> dict:
def bbox_to_feature_collection(bbox: Bbox) -> dict:
polygon = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[bbox.lon_min, bbox.lat_min],
[bbox.lon_max, bbox.lat_min],
[bbox.lon_max, bbox.lat_max],
[bbox.lon_min, bbox.lat_max],
[bbox.lon_min, bbox.lat_min],
]
],
},
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[bbox.lon_min, bbox.lat_min],
[bbox.lon_max, bbox.lat_min],
[bbox.lon_max, bbox.lat_max],
[bbox.lon_min, bbox.lat_max],
[bbox.lon_min, bbox.lat_min],
]
],
},
}
],
}
return polygon


def get_report(bbox: Bbox, include_svg: bool = True, include_html: bool = False):
url = OQT_API_URL + "/" + "reports" + "/" + OQT_REPORT_NAME
parameters = {
"bpolys": bbox_to_polygon(bbox),
"includeSvg": include_svg,
"includeHtml": include_html,
"flatten": False,
}
parameters = {"bpolys": bbox_to_feature_collection(bbox)}
req = requests.post(url, json=parameters)
if req.status_code == 422:
if req.json()["type"] == "SizeRestrictionError":
Expand All @@ -48,5 +48,4 @@ def get_report(bbox: Bbox, include_svg: bool = True, include_html: bool = False)
raise OQTReportError(
"There seems to be a problem with OQT. Please try again later."
)
report_properties = req.json()["properties"]
return report_properties
return req.json()["features"][0]["properties"]
10 changes: 5 additions & 5 deletions tests/fixtures/cassette/test_as_image
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ interactions:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.1
- python-requests/2.31.0
method: GET
uri: https://maps.heigit.org/osm-carto/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=FALSE&LAYERS=heigit%3Aosm-carto%402xx&WIDTH=1867&HEIGHT=1587&SRS=EPSG%3A3857&STYLES=&BBOX=964472.1973848869%2C6343459.035638228%2C967434.6098457306%2C6345977.635778541
response:
Expand All @@ -25,13 +25,13 @@ interactions:
Connection:
- Upgrade, Keep-Alive
Content-length:
- '886248'
- '886610'
Content-type:
- image/png
Date:
- Tue, 22 Nov 2022 15:23:21 GMT
- Mon, 21 Aug 2023 14:06:13 GMT
Expires:
- Wed, 23 Nov 2022 15:23:21 GMT
- Tue, 22 Aug 2023 14:06:13 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/cassette/test_generate_sketch_map
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ interactions:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.1
- python-requests/2.31.0
method: GET
uri: https://maps.heigit.org/osm-carto/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=FALSE&LAYERS=heigit%3Aosm-carto%402xx&WIDTH=1867&HEIGHT=1587&SRS=EPSG%3A3857&STYLES=&BBOX=964472.1973848869%2C6343459.035638228%2C967434.6098457306%2C6345977.635778541
response:
Expand All @@ -25,13 +25,13 @@ interactions:
Connection:
- Upgrade, Keep-Alive
Content-length:
- '886248'
- '890506'
Content-type:
- image/png
Date:
- Tue, 22 Nov 2022 15:22:11 GMT
- Mon, 21 Aug 2023 14:05:46 GMT
Expires:
- Wed, 23 Nov 2022 15:22:11 GMT
- Tue, 22 Aug 2023 14:05:46 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
10 changes: 5 additions & 5 deletions tests/fixtures/cassette/test_get_map_image
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ interactions:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
- gzip, deflate, br
Connection:
- keep-alive
User-Agent:
- python-requests/2.28.1
- python-requests/2.31.0
method: GET
uri: https://maps.heigit.org/osm-carto/service?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=FALSE&LAYERS=heigit%3Aosm-carto%402xx&WIDTH=1867&HEIGHT=1587&SRS=EPSG%3A3857&STYLES=&BBOX=964472.1973848869%2C6343459.035638228%2C967434.6098457306%2C6345977.635778541
response:
Expand All @@ -25,13 +25,13 @@ interactions:
Connection:
- Upgrade, Keep-Alive
Content-length:
- '886248'
- '886610'
Content-type:
- image/png
Date:
- Tue, 22 Nov 2022 15:22:47 GMT
- Mon, 21 Aug 2023 14:06:12 GMT
Expires:
- Wed, 23 Nov 2022 15:22:47 GMT
- Tue, 22 Aug 2023 14:06:12 GMT
Keep-Alive:
- timeout=5, max=100
Server:
Expand Down
Loading