Пример #1
0
def test_to_dict_no_proj4():
    crs = CRS(
        {
            "a": 6371229.0,
            "b": 6371229.0,
            "lon_0": -10.0,
            "o_lat_p": 30.0,
            "o_lon_p": 0.0,
            "o_proj": "longlat",
            "proj": "ob_tran",
        }
    )
    if LooseVersion(proj_version_str) >= LooseVersion("6.3.0"):
        with pytest.warns(UserWarning):
            assert crs.to_proj4() == (
                "+proj=ob_tran +o_proj=longlat +lon_0=-10 +o_lat_p=30 "
                "+o_lon_p=0 +R=6371229 +no_defs +type=crs"
            )
            assert crs.to_dict() == {
                "R": 6371229,
                "lon_0": -10,
                "no_defs": None,
                "o_lat_p": 30,
                "o_lon_p": 0,
                "o_proj": "longlat",
                "proj": "ob_tran",
                "type": "crs",
            }
    else:
        with pytest.warns(UserWarning):
            assert crs.to_proj4() is None
            assert crs.to_dict() == {}
Пример #2
0
def test_from_esri_wkt():
    projection_string = (
        'PROJCS["USA_Contiguous_Albers_Equal_Area_Conic_USGS_version",'
        'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",'
        'SPHEROID["GRS_1980",6378137.0,298.257222101]],'
        'PRIMEM["Greenwich",0.0],'
        'UNIT["Degree",0.0174532925199433]],'
        'PROJECTION["Albers"],'
        'PARAMETER["false_easting",0.0],'
        'PARAMETER["false_northing",0.0],'
        'PARAMETER["central_meridian",-96.0],'
        'PARAMETER["standard_parallel_1",29.5],'
        'PARAMETER["standard_parallel_2",45.5],'
        'PARAMETER["latitude_of_origin",23.0],'
        'UNIT["Meter",1.0],'
        'VERTCS["NAVD_1988",'
        'VDATUM["North_American_Vertical_Datum_1988"],'
        'PARAMETER["Vertical_Shift",0.0],'
        'PARAMETER["Direction",1.0],UNIT["Centimeter",0.01]]]')
    proj_crs_str = CRS.from_string(projection_string)
    proj_crs_wkt = CRS(projection_string)
    with pytest.warns(UserWarning):
        assert proj_crs_str.to_proj4() == proj_crs_wkt.to_proj4()
        assert proj_crs_str.to_proj4(4) == (
            "+proj=aea +lat_0=23 +lon_0=-96 +lat_1=29.5 "
            "+lat_2=45.5 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +type=crs"
        )
Пример #3
0
def _create_legacy_line(
    grid_name: str,
    crs: CRS,
    clon: float,
    clat: float,
    grid_width: int,
    grid_height: int,
    pixel_size_x: float,
    pixel_size_y: float,
) -> str:
    p = Proj(crs)
    origin_x = p(clon, clat)[0] + (grid_width / 2.0 * pixel_size_x * -1)
    origin_y = p(clon, clat)[1] + (grid_height / 2.0 * pixel_size_y * -1)
    if p.crs.is_geographic:
        # Origin is in degrees so we need to add a unit string to it
        origin_x = "%0.5fdeg" % origin_x
        origin_y = "%0.5fdeg" % origin_y
    else:
        origin_lon, origin_lat = p(origin_x, origin_y, inverse=True)
        origin_x = "%0.5fdeg" % origin_lon
        origin_y = "%0.5fdeg" % origin_lat

    valid_config_line = CONFIG_LINE_FORMAT % {
        "grid_name": grid_name,
        "proj4_str": crs.to_proj4(),
        "origin_x": origin_x,
        "origin_y": origin_y,
        "pixel_size_x": pixel_size_x,
        "pixel_size_y": pixel_size_y,
        "width": grid_width,
        "height": grid_height,
    }
    return valid_config_line
Пример #4
0
def test_to_dict_no_proj4():
    crs = CRS({
        "a": 6371229.0,
        "b": 6371229.0,
        "lon_0": -10.0,
        "o_lat_p": 30.0,
        "o_lon_p": 0.0,
        "o_proj": "longlat",
        "proj": "ob_tran",
    })
    if LooseVersion(__proj_version__) >= LooseVersion("6.3.0"):
        with pytest.warns(UserWarning):
            assert crs.to_dict() == {
                "R": 6371229,
                "lon_0": -10,
                "no_defs": None,
                "o_lat_p": 30,
                "o_lon_p": 0,
                "o_proj": "longlat",
                "proj": "ob_tran",
                "type": "crs",
            }
    else:
        with pytest.warns(UserWarning):
            assert crs.to_proj4() is None
            assert crs.to_dict() == {}
Пример #5
0
def test_from_esri_wkt():
    projection_string = (
        'PROJCS["USA_Contiguous_Albers_Equal_Area_Conic_USGS_version",'
        'GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",'
        'SPHEROID["GRS_1980",6378137.0,298.257222101]],'
        'PRIMEM["Greenwich",0.0],'
        'UNIT["Degree",0.0174532925199433]],'
        'PROJECTION["Albers"],'
        'PARAMETER["false_easting",0.0],'
        'PARAMETER["false_northing",0.0],'
        'PARAMETER["central_meridian",-96.0],'
        'PARAMETER["standard_parallel_1",29.5],'
        'PARAMETER["standard_parallel_2",45.5],'
        'PARAMETER["latitude_of_origin",23.0],'
        'UNIT["Meter",1.0],'
        'VERTCS["NAVD_1988",'
        'VDATUM["North_American_Vertical_Datum_1988"],'
        'PARAMETER["Vertical_Shift",0.0],'
        'PARAMETER["Direction",1.0],UNIT["Centimeter",0.01]]]'
    )
    proj_crs_str = CRS.from_string(projection_string)
    proj_crs_wkt = CRS(projection_string)
    assert proj_crs_str.to_proj4() == proj_crs_wkt.to_proj4()
    assert proj_crs_str.to_proj4(4) == (
        "+proj=aea +lat_0=23 +lon_0=-96 +lat_1=29.5 "
        "+lat_2=45.5 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs +type=crs"
    )
    def configure_database_with_custom_crs(self, index) -> None:
        """Function to configure database using custom EPSG
        :return:
        """
        custom_crs = self._load_configfile()

        for custom_crs_code_and_entity in custom_crs:
            custom_crs_entity, custom_crs_code = custom_crs_code_and_entity.split(":")
            resproxy = index._db._engine.execute(
                f"SELECT * FROM spatial_ref_sys WHERE srid = {custom_crs_code}"
            )

            resset = resproxy.first()
            if not resset:
                custom_crs_string = PJCRS(custom_crs[custom_crs_code_and_entity])

                index._db._engine.execute(
                    "INSERT INTO spatial_ref_sys VALUES ({}, '{}', '{}', '{}', '{}');".format(
                        custom_crs_code,
                        custom_crs_entity.upper(),
                        custom_crs_code,
                        custom_crs_string.to_wkt(),
                        custom_crs_string.to_proj4(),
                    )
                )
Пример #7
0
def test_to_dict_no_proj4():
    crs = CRS({
        "a": 6371229.0,
        "b": 6371229.0,
        "lon_0": -10.0,
        "o_lat_p": 30.0,
        "o_lon_p": 0.0,
        "o_proj": "longlat",
        "proj": "ob_tran",
    })
    assert crs.to_proj4() is None
    assert crs.to_dict() == {}
def test_store_shade(tin):
    pts, faces = tin
    uid = "test_tin"
    shade_uid = "test_tin_shade"
    crs = CRS(32633)
    mesh = Mesh.from_points_and_faces(points=pts,
                                      faces=faces,
                                      proj4_str=crs.to_proj4())
    geom = Geometry(mesh=mesh,
                    crs=crs,
                    base_color=(0, 0, 0),
                    material_spec="dummy2")

    with TemporaryDirectory() as directory:
        tin_archive = Path(directory) / "tin_archive"
        shade_archive_path = Path(directory) / "shade_archive"
        tin_archive.mkdir()
        shade_archive_path.mkdir()
        tr = TinRepository(path=tin_archive)
        tr.save(uid=uid, geometry=geom)
        mesh = tr.read(uid=uid).mesh
        start_year = 2019
        start_month = 10
        start_day = 25
        end_year = 2019
        end_month = 10
        end_day = 26
        start_time = datetime(start_year, start_month, start_day)
        end_time = datetime(end_year, end_month, end_day)
        frequency = 3600
        dt = timedelta(seconds=frequency)
        t = start_time
        shade_repo = ShadeRepository(path=shade_archive_path)
        with shade_repo.open(tin_repo=tr,
                             tin_uid=uid,
                             shade_uid=shade_uid,
                             overwrite=True) as shade_writer:
            while t <= end_time:
                shade = mesh.shade(t.timestamp())
                shade_writer.save(t.timestamp(), shade)
                t += dt

        info = shade_repo.info(uid=shade_uid)
        assert info
        assert info["tin_uid"] == uid
        assert info.get("timestamps", False)
        assert isinstance(info["timestamps"], list)
def test_store_and_load_tin(tin):
    pts, faces = tin
    uid = "test_tin"
    crs = CRS(32633)
    mesh = Mesh.from_points_and_faces(points=pts,
                                      faces=faces,
                                      proj4_str=crs.to_proj4())
    geom = Geometry(mesh=mesh,
                    crs=crs,
                    base_color=(0, 0, 0),
                    material_spec="dummy2")
    with TemporaryDirectory() as directory:
        archive = Path(directory)
        tr = TinRepository(path=archive)
        tr.save(uid=uid, geometry=geom)
        geom = tr.read(uid=uid)
        assert np.allclose(geom.points, pts)
        assert np.allclose(geom.faces, faces)