Commit 3e7d39be authored by Mark Hewitt's avatar Mark Hewitt
Browse files

Merge branch 'feature/crs-ct-list' into 'main'

crs transforms command

See merge request !8
parents 422469ca 5767bab4
Pipeline #76895 passed with stages
in 3 minutes and 46 seconds
......@@ -28,6 +28,11 @@ For more information, specify the `-h` flag:
Change Log
==========
0.0.26
------
- crs transforms command
0.0.25
------
......
......@@ -12,4 +12,4 @@
""" OSDU command line environment"""
__VERSION__ = "0.0.25"
__VERSION__ = "0.0.26"
......@@ -23,15 +23,15 @@ from osducli.config import CONFIG_CRS_CATALOG_URL
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(
"crses[].{Authority:baseCRSAuthorityCode.auth,Code:baseCRSAuthorityCode.code,Type:crstype}"
"crses[].{Name:aliasNames[0],Authority:baseCRSAuthorityCode.auth,Code:baseCRSAuthorityCode.code,Type:crstype,Source:source}" # noqa: E501 pylint:disable=line-too-long
)
def _click_command(state: State):
"""List CRS's"""
"""List coordinate referense systems"""
return crs_list(state)
def crs_list(state: State):
"""List CRS's
"""List coordinate referense systems
Args:
state (State): Global state
......
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""CRS Catalog transforms command"""
import click
from osducli.click_cli import CustomClickCommand, State, command_with_output
from osducli.cliclient import CliOsduClient, handle_cli_exceptions
from osducli.config import CONFIG_CRS_CATALOG_URL
# click entry point
@click.command(cls=CustomClickCommand)
@handle_cli_exceptions
@command_with_output(
"cts[].{Name:aliasNames[0],FromAuthority:fromCRSAuthorityCode.auth,FromCode:fromCRSAuthorityCode.code,ToAuthority:toCRSAuthorityCode.auth,ToCode:toCRSAuthorityCode.code,Source:source}" # noqa: E501 pylint:disable=line-too-long
)
def _click_command(state: State):
"""List coordinate referense transforms"""
return crs_transforms(state)
def crs_transforms(state: State):
"""List coordinate referense transforms
Args:
state (State): Global state
"""
connection = CliOsduClient(state.config)
json = connection.cli_get_returning_json(CONFIG_CRS_CATALOG_URL, "ct?limit=10000")
return json
{
"offset": 0,
"count": 228,
"totalCount": 228,
"cts": [
{
"description": "Coord Op Scope: MAGNA-SIRGAS is a national realization of SIRGAS and coincident with WGS 84 to within 1 metre. This transformation has an accuracy equal to the coincidence figure. | Tfm Accuracy: 1 | Information Source: OGP",
"lastModified": "20170714",
"aliasNames": [
"MAGNA-SIRGAS to WGS 84 (1)"
],
"namedReference": {
"name": "MAGNA_To_WGS_1984_1",
"persistableReference": "{\"wkt\":\"GEOGTRAN[\\\"MAGNA_To_WGS_1984_1\\\",GEOGCS[\\\"GCS_MAGNA\\\",DATUM[\\\"D_MAGNA\\\",SPHEROID[\\\"GRS_1980\\\",6378137.0,298.257222101]],PRIMEM[\\\"Greenwich\\\",0.0],UNIT[\\\"Degree\\\",0.0174532925199433]],GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137.0,298.257223563]],PRIMEM[\\\"Greenwich\\\",0.0],UNIT[\\\"Degree\\\",0.0174532925199433]],METHOD[\\\"Geocentric_Translation\\\"],PARAMETER[\\\"X_Axis_Translation\\\",0.0],PARAMETER[\\\"Y_Axis_Translation\\\",0.0],PARAMETER[\\\"Z_Axis_Translation\\\",0.0],AUTHORITY[\\\"EPSG\\\",15738]]\",\"ver\":\"PE_10_3_1\",\"name\":\"MAGNA_To_WGS_1984_1\",\"authCode\":{\"auth\":\"EPSG\",\"code\":\"15738\"},\"type\":\"ST\"}"
},
"source": "OGP",
"fromCRSAuthorityCode": {
"auth": "EPSG",
"code": "4686"
},
"toCRSAuthorityCode": {
"auth": "EPSG",
"code": "4326"
},
"areaOfUse": {
"description": "Colombia - onshore and offshore. Includes San Andres y Providencia, Malpelo Islands, Roncador Bank, Serrana Bank and Serranilla Bank.",
"lastModified": "20140501",
"aliasNames": [],
"name": "Colombia",
"essence": {
"authCode": {
"auth": "EPSG",
"code": "1070"
},
"type": "AOU",
"boundBox": {
"lonMin": -84.77,
"latMin": -4.23,
"lonMax": -66.87,
"latMax": 15.51
}
}
}
},
{
"description": "Coord Op Scope: For military purposes only. Accuracy 3m, 5m and 5m in X, Y and Z axes. | Tfm Accuracy: 8 | Remarks: Derived at 22 stations. | Information Source: U.S. Defense Mapping Agency TR8350.2 September 1987.",
"lastModified": "20141119",
"aliasNames": [
"SAD69 to WGS 84 (4)",
"SAN-C"
],
"namedReference": {
"name": "SAD_1969_To_WGS_1984_4",
"persistableReference": "{\"wkt\":\"GEOGTRAN[\\\"SAD_1969_To_WGS_1984_4\\\",GEOGCS[\\\"GCS_South_American_1969\\\",DATUM[\\\"D_South_American_1969\\\",SPHEROID[\\\"GRS_1967_Truncated\\\",6378160.0,298.25]],PRIMEM[\\\"Greenwich\\\",0.0],UNIT[\\\"Degree\\\",0.0174532925199433]],GEOGCS[\\\"GCS_WGS_1984\\\",DATUM[\\\"D_WGS_1984\\\",SPHEROID[\\\"WGS_1984\\\",6378137.0,298.257223563]],PRIMEM[\\\"Greenwich\\\",0.0],UNIT[\\\"Degree\\\",0.0174532925199433]],METHOD[\\\"Geocentric_Translation\\\"],PARAMETER[\\\"X_Axis_Translation\\\",-60.0],PARAMETER[\\\"Y_Axis_Translation\\\",-2.0],PARAMETER[\\\"Z_Axis_Translation\\\",-41.0],AUTHORITY[\\\"EPSG\\\",1867]]\",\"ver\":\"PE_10_3_1\",\"name\":\"SAD_1969_To_WGS_1984_4\",\"authCode\":{\"auth\":\"EPSG\",\"code\":\"1867\"},\"type\":\"ST\"}"
},
"source": "U.S. Defense Mapping Agency TR8350.2 September 1987.",
"fromCRSAuthorityCode": {
"auth": "EPSG",
"code": "4618"
},
"toCRSAuthorityCode": {
"auth": "EPSG",
"code": "4326"
},
"areaOfUse": {
"description": "Brazil - onshore southeast of a line beginning at the intersection of the 53\u00b0W meridian with the northern national boundary then running southwards to 14\u00b0S, then westwards to the national boundary.",
"lastModified": "20140501",
"aliasNames": [],
"name": "Brazil - onshore south of 14\u00b0S and east of 53\u00b0W",
"essence": {
"authCode": {
"auth": "EPSG",
"code": "3887"
},
"type": "AOU",
"boundBox": {
"lonMin": -60.58,
"latMin": -33.78,
"lonMax": -34.74,
"latMax": 4.43
}
}
}
}
]
}
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test cases for crs transforms"""
import json
import unittest
from os import path
import mock
from click.testing import CliRunner
from mock import patch
from osducli.__main__ import cli
from osducli.click_cli import State
from osducli.cliclient import CliOsduClient
from osducli.commands.crs.transforms import crs_transforms
from tests.helpers import MockConfig
class StatusTests(unittest.TestCase):
"""Test cases for crs transforms"""
# region CLI interface
def test_checkrefs_default_params(self):
"""test cli with required parameters"""
with mock.patch(
"osducli.commands.crs.transforms.crs_transforms", return_value=None
) as mock_crs_list:
runner = CliRunner()
result = runner.invoke(cli, ["crs", "transforms"])
mock_crs_list.assert_called_once_with(mock.ANY)
self.assertEqual(result.exit_code, 0)
# endregion CLI interface
def test_with_output(self):
"""Test json output"""
data_folder = path.join(path.dirname(path.realpath(__file__)), "data")
data_path = path.join(data_folder, "transforms.json")
with open(data_path) as file:
data = json.load(file)
with patch(
"osducli.cliclient.CliOsduClient.cli_get_returning_json", return_value=data
) as _:
state = State()
state.config = MockConfig
state.output = "json"
results = crs_transforms(state)
self.assertDictEqual(data, results)
def test_user_friendly_output(self): # pylint: disable=R0201
"""Test user friendly output"""
data_folder = path.join(path.dirname(path.realpath(__file__)), "data")
data_path = path.join(data_folder, "transforms.json")
with open(data_path) as file:
data = json.load(file)
with patch(
"osducli.cliclient.CliOsduClient.cli_get_returning_json", return_value=data
) as _:
state = State()
state.config = MockConfig
_ = crs_transforms(state)
# TO DO - Verify stdout.
@patch.object(CliOsduClient, "cli_get_returning_json", side_effect=SystemExit(1))
def test_exit_on_error(self, mock_cli_get_returning_json): # pylint: disable=W0613
"""Test any exit error is propogated"""
state = State()
state.config = MockConfig
with self.assertRaises(SystemExit) as sysexit:
_ = crs_transforms(state)
self.assertEqual(sysexit.exception.code, 1)
if __name__ == "__main__":
import nose2
nose2.main()
......@@ -411,6 +411,7 @@ class HelpTextTests(unittest.TestCase):
"info",
"list",
"summary",
"transforms",
),
)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment