Skip to content

Commit

Permalink
Add area of use and bounding box to CRS info
Browse files Browse the repository at this point in the history
Closes #18
  • Loading branch information
kbevers committed Mar 28, 2022
1 parent 3e5be17 commit bc5419c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
11 changes: 10 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import json
import pprint

import pytest

Expand All @@ -22,7 +23,9 @@ def _assert_result(entry, expected_json_output):
"""
print(entry)
decoded_response = _get_and_decode_response(entry)
print(decoded_response)
pprint.pprint(decoded_response)
print("-----")
pprint.pprint(expected_json_output)
assert decoded_response == expected_json_output


Expand Down Expand Up @@ -315,6 +318,8 @@ def test_crs_return_srid(api_from_v1_1):
"v4": None,
"v4_short": None,
"srid": "EPSG:25832",
"area_of_use": "Europe between 6°E and 12°E: Austria; Belgium; Denmark - onshore and offshore; Germany - onshore and offshore; Norway including - onshore and offshore; Spain - offshore.",
"bounding_box": [6.0, 38.76, 12.0, 84.33],
},
"EPSG:23032+5733": {
"country": "DK",
Expand All @@ -329,6 +334,8 @@ def test_crs_return_srid(api_from_v1_1):
"v4": None,
"v4_short": None,
"srid": "EPSG:23032+5733",
"area_of_use": "Denmark - onshore.",
"bounding_box": [8.0, 54.51, 15.24, 57.8],
},
"DK:S34S": {
"country": "DK",
Expand All @@ -343,6 +350,8 @@ def test_crs_return_srid(api_from_v1_1):
"v4": None,
"v4_short": None,
"srid": "DK:S34S",
"area_of_use": "Denmark - Sealand onshore",
"bounding_box": [11.0, 54.5, 12.8, 56.5],
},
}

Expand Down
35 changes: 33 additions & 2 deletions webproj/api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from cmath import inf
import os
import json
from pathlib import Path

from flask import Flask
from flask_cors import CORS
from flask_restx import Api, Resource, fields, abort
from flask_restx import Api, Resource, abort
import pyproj
from pyproj.transformer import Transformer, AreaOfInterest

Expand Down Expand Up @@ -207,11 +208,41 @@ def get(self, crs):
"""
Retrieve information about a given coordinate reference system
Version 1.1 includes the SRID in the CRS info.
Version 1.1 includes the SRID, area of use and bounding box in
the CRS info.
"""

output = super().get(crs)
output["srid"] = crs

# determine area of use and bounding box
try:
crs_from_db = pyproj.CRS.from_user_input(crs.upper())
if crs_from_db.is_compound:
area = inf
for subcrs in crs_from_db.sub_crs_list:
aou = subcrs.area_of_use
bbox_area = aou.east - aou.west * aou.north - aou.south
if bbox_area < area:
output["area_of_use"] = subcrs.area_of_use.name
output["bounding_box"] = list(subcrs.area_of_use.bounds)
else:
output["area_of_use"] = crs_from_db.area_of_use.name
output["bounding_box"] = list(crs_from_db.area_of_use.bounds)
except pyproj.exceptions.CRSError:
# special cases not in proj.db
if crs == "DK:S34J":
output["area_of_use"] = "Denmark - Jutland onshore"
output["bounding_box"] = [8.0, 54.5, 11.0, 57.75]
elif crs == "DK:S34S":
output["area_of_use"] = "Denmark - Sealand onshore"
output["bounding_box"] = [11.0, 54.5, 12.8, 56.5]
elif crs == "DK:S45B":
output["area_of_use"] = "Denmark - Bornholm onshore"
output["bounding_box"] = [14.6, 54.9, 15.2, 55.3]
else:
abort(404, message=f"'{crs}' not available")

return output


Expand Down

0 comments on commit bc5419c

Please sign in to comment.