Beispiel #1
0
def test_operations__scope_remarks():

    transformer = TransformerGroup(28356, 7856).transformers[0]
    coord_op = CoordinateOperation.from_string(transformer.to_wkt())
    assert coord_op.operations == transformer.operations
    # scope does not transfer for some reason
    # assert [op.scope for op in transformer.operations] == [
    #     op.scope for op in coord_op.operations
    # ]
    assert [op.remarks for op in transformer.operations
            ] == [op.remarks for op in coord_op.operations]
Beispiel #2
0
def test_transformer_group__download_grids__directory(
    get_user_data_dir_mock,
    download_mock,
    tmp_path,
    capsys,
):
    with proj_network_env():
        if pyproj._datadir._USE_GLOBAL_CONTEXT:
            pyproj.set_global_context_network(active=False)
        trans_group = TransformerGroup(4326, 2964, network=False)
        trans_group.download_grids(directory=tmp_path)
        get_user_data_dir_mock.assert_not_called()
        captured = capsys.readouterr()
        assert captured.out == ""
        if grids_available(
                "us_noaa_alaska.tif",
                "ca_nrc_ntv2_0.tif",
                check_network=False,
                check_all=True,
        ):
            download_mock.assert_not_called()
        elif grids_available("us_noaa_alaska.tif", check_network=False):
            download_mock.assert_called_with(
                file_url="https://cdn.proj.org/ca_nrc_ntv2_0.tif",
                short_name="ca_nrc_ntv2_0.tif",
                directory=tmp_path,
                verbose=False,
            )
        elif grids_available("ca_nrc_ntv2_0.tif", check_network=False):
            download_mock.assert_called_with(
                file_url="https://cdn.proj.org/us_noaa_alaska.tif",
                short_name="us_noaa_alaska.tif",
                directory=tmp_path,
                verbose=False,
            )
        else:
            download_mock.assert_has_calls(
                [
                    call(
                        file_url="https://cdn.proj.org/us_noaa_alaska.tif",
                        short_name="us_noaa_alaska.tif",
                        directory=tmp_path,
                        verbose=False,
                    ),
                    call(
                        file_url="https://cdn.proj.org/ca_nrc_ntv2_0.tif",
                        short_name="ca_nrc_ntv2_0.tif",
                        directory=tmp_path,
                        verbose=False,
                    ),
                ],
                any_order=True,
            )
Beispiel #3
0
def test_transformer__operations():
    transformer = TransformerGroup(28356, 7856).transformers[0]
    assert [op.name for op in transformer.operations] == [
        "Inverse of Map Grid of Australia zone 56",
        "GDA94 to GDA2020 (1)",
        "Map Grid of Australia zone 56",
    ]
Beispiel #4
0
def test_transformer_group():
    trans_group = TransformerGroup(7789, 8401)
    assert len(trans_group.transformers) == 2
    assert trans_group.transformers[0].name == "helmert"
    assert trans_group.transformers[1].description == ("ITRF2014 to ETRF2014 (2)")
    assert not trans_group.unavailable_operations
    assert trans_group.best_available
Beispiel #5
0
def test_transformer_group__unavailable():
    trans_group = TransformerGroup(4326, 2964)
    for transformer in trans_group.transformers:
        assert transformer.is_network_enabled == (
            os.environ.get("PROJ_NETWORK") == "ON")

    if grids_available("us_noaa_alaska.tif",
                       "ca_nrc_ntv2_0.tif",
                       check_all=True):
        assert len(trans_group.unavailable_operations) == 0
        assert len(trans_group.transformers) == 10
        assert (trans_group.transformers[0].description ==
                "Inverse of NAD27 to WGS 84 (85) + Alaska Albers")
        assert trans_group.best_available
    elif grids_available("us_noaa_alaska.tif"):
        assert len(trans_group.unavailable_operations) == 1
        assert (trans_group.transformers[0].description ==
                "Inverse of NAD27 to WGS 84 (85) + Alaska Albers")
        assert len(trans_group.transformers) == 9
        assert trans_group.best_available
    elif grids_available("ca_nrc_ntv2_0.tif"):
        assert len(trans_group.unavailable_operations) == 1
        assert (trans_group.transformers[0].description ==
                "Inverse of NAD27 to WGS 84 (7) + Alaska Albers")
        assert len(trans_group.transformers) == 9
        assert not trans_group.best_available
    else:
        assert len(trans_group.unavailable_operations) == 2
        assert (trans_group.unavailable_operations[0].name ==
                "Inverse of NAD27 to WGS 84 (85) + Alaska Albers")
        assert len(trans_group.transformers) == 8
        assert not trans_group.best_available
Beispiel #6
0
def test_transformer_group__unavailable(aoi_data_directory):
    trans_group = TransformerGroup(4326, 2964)
    assert len(trans_group.unavailable_operations) == 1
    assert (trans_group.unavailable_operations[0].name ==
            "Inverse of NAD27 to WGS 84 (33) + Alaska Albers")
    assert len(trans_group.transformers) == 8
    assert trans_group.best_available
Beispiel #7
0
def test_transformer_group__get_transform_crs():
    tg = TransformerGroup("epsg:4258", "epsg:7415")
    if LooseVersion(pyproj.__proj_version__) >= LooseVersion("6.3.1"):
        if not grids_available("nl_nsgi_rdtrans2018.tif"):
            assert len(tg.transformers) == 1
        else:
            assert len(tg.transformers) == 2
    else:
        assert len(tg.transformers) == 4
Beispiel #8
0
def test_transform_group__area_of_interest(aoi_data_directory):
    with pytest.warns(
            UserWarning,
            match="Best transformation is not available due to missing Grid"):
        trans_group = TransformerGroup(4326,
                                       2964,
                                       area_of_interest=AreaOfInterest(
                                           -136.46, 49.0, -60.72, 83.17))
    assert (trans_group.transformers[0].description ==
            "Inverse of NAD27 to WGS 84 (13) + Alaska Albers")
def test_transformer_group__unavailable():
    trans_group = TransformerGroup(4326, 2964)
    if not grids_available("ntv2_0.gsb", "ca_nrc_ntv2_0.tif"):
        assert len(trans_group.unavailable_operations) == 1
        assert (trans_group.unavailable_operations[0].name ==
                "Inverse of NAD27 to WGS 84 (33) + Alaska Albers")
        assert len(trans_group.transformers) == 8
        assert trans_group.best_available
    else:
        assert len(trans_group.unavailable_operations) == 0
        assert len(trans_group.transformers) == 9
        assert trans_group.best_available
Beispiel #10
0
def test_transformer_group__network_enabled():
    with proj_network_env():
        pyproj.network.set_network_enabled(active=True)
        trans_group = TransformerGroup(4326, 2964)
        assert len(trans_group.unavailable_operations) == 0
        assert len(trans_group.transformers) == 10
        assert trans_group.best_available
        for transformer in trans_group.transformers:
            assert transformer.is_network_enabled is True
            for operation in transformer.operations:
                for grid in operation.grids:
                    assert grid.available
Beispiel #11
0
def test_transformer_group__network_enabled():
    with proj_network_env():
        if pyproj._datadir._USE_GLOBAL_CONTEXT:
            pyproj.set_global_context_network(active=True)
        trans_group = TransformerGroup(4326, 2964, network=True)
        assert len(trans_group.unavailable_operations) == 0
        assert len(trans_group.transformers) == 10
        assert trans_group.best_available
        for transformer in trans_group.transformers:
            assert transformer.is_network_enabled is True
            for operation in transformer.operations:
                for grid in operation.grids:
                    assert grid.available
Beispiel #12
0
def test_transformer__operations__scope_remarks():
    transformer = TransformerGroup(28356, 7856).transformers[0]
    assert transformer.scope is None
    assert [op.scope for op in transformer.operations] == [
        None,
        "Conformal transformation of GDA94 coordinates that have been derived through "
        "GNSS CORS.",
        None,
    ]
    assert [str(op.remarks)[:5] for op in transformer.operations] == [
        "None",
        "Scale",
        "None",
    ]
Beispiel #13
0
def test_transformer__operations__scope_remarks():
    transformer = TransformerGroup(28356, 7856).transformers[0]
    assert transformer.scope is None
    assert [op.scope for op in transformer.operations] == [
        "Engineering survey, topographic mapping.",
        "Transformation of GDA94 coordinates that have been derived "
        "through GNSS CORS.",
        "Engineering survey, topographic mapping.",
    ]
    assert [str(op.remarks)[:5].strip() for op in transformer.operations] == [
        "Grid",
        "Scale",
        "Grid",
    ]
Beispiel #14
0
def test_transformer_group__download_grids(get_user_data_dir_mock, tmp_path, capsys):
    get_user_data_dir_mock.return_value = str(tmp_path)
    with proj_network_env():
        if pyproj._datadir._USE_GLOBAL_CONTEXT:
            pyproj.network.set_network_enabled(active=False)
        trans_group = TransformerGroup(4326, 2964, network=False)
        trans_group.download_grids(verbose=True)
        captured = capsys.readouterr()
        get_user_data_dir_mock.assert_called_with(True)
        paths = sorted(Path(path).name for path in glob(str(tmp_path.joinpath("*"))))
        if grids_available(
            "us_noaa_alaska.tif",
            "ca_nrc_ntv2_0.tif",
            check_network=False,
            check_all=True,
        ):
            assert paths == []
            assert captured.out == ""
        elif grids_available("us_noaa_alaska.tif", check_network=False):
            assert paths == ["ca_nrc_ntv2_0.tif"]
            assert (
                captured.out == "Downloading: https://cdn.proj.org/ca_nrc_ntv2_0.tif\n"
            )
        elif grids_available("ca_nrc_ntv2_0.tif", check_network=False):
            assert paths == ["us_noaa_alaska.tif"]
            assert captured.out == (
                "Downloading: https://cdn.proj.org/us_noaa_alaska.tif\n"
            )
        else:
            assert paths == ["ca_nrc_ntv2_0.tif", "us_noaa_alaska.tif"]
            assert captured.out == (
                "Downloading: https://cdn.proj.org/us_noaa_alaska.tif\n"
                "Downloading: https://cdn.proj.org/ca_nrc_ntv2_0.tif\n"
            )
        # make sure not downloaded again
        with proj_env(), patch(
            "pyproj.transformer._download_resource_file"
        ) as download_mock:
            append_data_dir(str(tmp_path))
            trans_group = TransformerGroup(4326, 2964, network=False)
            trans_group.download_grids()
            get_user_data_dir_mock.assert_called_with(True)
            download_mock.assert_not_called()
Beispiel #15
0
def test_transformer_group__network_disabled():
    with proj_network_env():
        if pyproj._datadir._USE_GLOBAL_CONTEXT:
            pyproj.network.set_network_enabled(active=False)
        trans_group = TransformerGroup(4326, 2964, network=False)
        for transformer in trans_group.transformers:
            assert transformer.is_network_enabled is False

        if grids_available(
            "us_noaa_alaska.tif",
            "ca_nrc_ntv2_0.tif",
            check_network=False,
            check_all=True,
        ):
            assert len(trans_group.unavailable_operations) == 0
            assert len(trans_group.transformers) == 10
            assert (
                trans_group.transformers[0].description
                == "Inverse of NAD27 to WGS 84 (85) + Alaska Albers"
            )
            assert trans_group.best_available
        elif grids_available("us_noaa_alaska.tif", check_network=False):
            assert len(trans_group.unavailable_operations) == 1
            assert (
                trans_group.transformers[0].description
                == "Inverse of NAD27 to WGS 84 (85) + Alaska Albers"
            )
            assert len(trans_group.transformers) == 9
            assert trans_group.best_available
        elif grids_available("ca_nrc_ntv2_0.tif", check_network=False):
            assert len(trans_group.unavailable_operations) == 1
            assert (
                trans_group.transformers[0].description
                == "Inverse of NAD27 to WGS 84 (7) + Alaska Albers"
            )
            assert len(trans_group.transformers) == 9
            assert not trans_group.best_available
        else:
            assert len(trans_group.unavailable_operations) == 2
            assert (
                trans_group.unavailable_operations[0].name
                == "Inverse of NAD27 to WGS 84 (85) + Alaska Albers"
            )
            assert len(trans_group.transformers) == 8
            assert not trans_group.best_available
Beispiel #16
0
def test_transformer_equals():
    assert (TransformerGroup(28356, 7856).transformers[0] == TransformerGroup(
        28356, 7856).transformers[0])
Beispiel #17
0
def test_operations():
    transformer = TransformerGroup(28356, 7856).transformers[0]
    coord_op = CoordinateOperation.from_string(transformer.to_wkt())
    assert coord_op.operations == transformer.operations
Beispiel #18
0
def test_transformer_group__get_transform_crs():
    tg = TransformerGroup("epsg:4258", "epsg:7415")
    if not grids_available("nl_nsgi_rdtrans2018.tif"):
        assert len(tg.transformers) == 1
    else:
        assert len(tg.transformers) == 2
Beispiel #19
0
def test_transformer_group__area_of_interest__invalid():
    with pytest.raises(ProjError):
        TransformerGroup(4326,
                         2964,
                         area_of_interest=(-136.46, 49.0, -60.72, 83.17))
Beispiel #20
0
def test_equivalent_transformer_group():
    with pytest.warns(DeprecationWarning):
        TransformerGroup("epsg:4326", 4326, skip_equivalent=True)
Beispiel #21
0
def test_transformer_group__get_transform_crs():
    tg = TransformerGroup("epsg:4258", "epsg:7415")
    assert len(tg.transformers) == 4
Beispiel #22
0
        def execute(self, data):
            wkt_input = data.get('wkt', self.get_default('wkt'))
            geom = wkt.loads(wkt_input)
            params = {
                p: data.get(p, self.get_default(p))
                for p in ('always_xy', 'errcheck', 'radians', 'direction',
                          'src_crs', 'dst_crs', 'best_available',
                          'rounding_precision', 'time', 'minimum_accuracy')
            }
            aoi_params = ('west_lon_degree', 'south_lat_degree',
                          'east_lon_degree', 'north_lat_degree')
            if all(
                    map(lambda b: isinstance(data.get(b, None), Number),
                        aoi_params)):
                params['area_of_interest'] = AreaOfInterest(
                    *map(data.get, aoi_params))
            input_crs = CRS.from_user_input(params.get('src_crs').strip())
            output_crs = CRS.from_user_input(params.get('dst_crs').strip())

            transformerGroup = TransformerGroup(
                crs_from=input_crs,
                crs_to=output_crs,
                skip_equivalent=
                True,  # Don't perform a transformation between equivalent CRSs
                always_xy=params.get('always_xy'),
                area_of_interest=params.get('area_of_interest', None))
            if not len(transformerGroup.transformers):
                raise TransformationUnavailableError(input_crs, output_crs)
            if params.get(
                    'best_available') and not transformerGroup.best_available:
                _operation = transformerGroup.unavailable_operations[0]
                raise BestTransformationUnavailableError(
                    f'Transformation {_operation.name} ({_operation.method_code} {_operation.method_auth_name}) is unavailable',
                    transformerGroup.unavailable_operations[0])
                # try:
                #     transformerGroup.download_grids(verbose=True)
                #     return self.execute(data)
                # except:
                #     raise BestTransformationUnavailableError(f'Transformation {transformerGroup.unavailable_operations[0].name} is unavailable', transformerGroup.unavailable_operations[0])
            elif transformerGroup.best_available:
                is_best_available = True
            else:
                is_best_available = False
            minimum_accuracy = params.get('minimum_accuracy')
            transformer = transformerGroup.transformers[0]
            if minimum_accuracy is not None and transformer.accuracy > minimum_accuracy:
                raise TooInaccurateError(
                    f'The transformation would introduce too much inaccuracy in the output ({transformer.accuracy} > {minimum_accuracy})',
                    transformer.accuracy)
            rounding_precision = max(0, int(params.get('rounding_precision')))
            kwargs = {
                'radians': params['radians'],
                'errcheck': params['errcheck'],
                'direction': params['direction']
            }
            LOGGER.debug(geom.type)
            geom_output = geom_transformation(transformer, geom, params)
            wkt_geom = wkt.dumps(
                geom_output,
                rounding_precision=rounding_precision).replace('"', '')
            if not geom.has_z and geom_output.has_z:
                wkt_geom = wkt_geom.replace('Z', 'M')
                LOGGER.debug('Replaced false Z with M')
            LOGGER.debug(wkt_geom)
            outputs = {
                'wkt': wkt_geom,
                # 'src_crs': input_crs.to_json_dict(),#.to_wkt(version=WktVersion.WKT2_2019, pretty=False),
                # 'dst_crs': output_crs.to_json_dict(),#.to_wkt(version=WktVersion.WKT2_2019, pretty=False),
                # 'area_of_use': {
                #     'west': transformer.area_of_use.west,
                #     'south': transformer.area_of_use.south,
                #     'east': transformer.area_of_use.east,
                #     'north': transformer.area_of_use.north,
                #     'name': transformer.area_of_use.name
                # },
                # 'accuracy': float(transformer.accuracy) if transformer.accuracy != -1 else None,
                'definition': transformer.definition,
                # 'description': transformer.description,
                # 'name': transformer.name,
                # 'remarks': transformer.remarks,
                # 'scope': transformer.scope,
                'transformer': transformer.to_json_dict(),
                # 'transformer_wkt': transformer.to_wkt(version=WktVersion.WKT2_2019),
                'best_available': is_best_available,
                # 'is_bound': output_crs.is_bound,
                # 'is_engineering': output_crs.is_engineering,
                # 'is_geocentric': output_crs.is_geocentric,
                # 'is_geographic': output_crs.is_geographic,
                # 'is_projected': output_crs.is_projected,
                # 'is_vertical': output_crs.is_vertical
            }
            outputs = [{'id': k, 'value': v} for k, v in outputs.items()]
            return outputs
Beispiel #23
0
def test_transformer_group__get_transform_crs():
    tg = TransformerGroup("epsg:4258", "epsg:7415")
    if LooseVersion(pyproj.proj_version_str) >= LooseVersion("6.3.1"):
        assert len(tg.transformers) == 1
    else:
        assert len(tg.transformers) == 4
Beispiel #24
0
def test_operations__scope_remarks():
    operation = TransformerGroup(28356, 7856).transformers[0].operations[1]
    coord_op = CoordinateOperation.from_string(operation.to_wkt())
    assert coord_op == operation
    assert coord_op.remarks == operation.remarks
    assert coord_op.scope == operation.scope