def test_get_data_dir__missing(): with proj_env(), pytest.raises(DataDirError), patch( "pyproj.datadir.os.path.abspath", return_value="INVALID" ), patch("pyproj.datadir.find_executable", return_value=None): set_data_dir(None) os.environ.pop("PROJ_LIB", None) get_data_dir()
def test_get_data_dir__missing(): with proj_env(), pytest.raises(DataDirError), patch( "pyproj.datadir.os.path.abspath", return_value="INVALID" ), patch("pyproj.datadir.find_executable", return_value=None): set_data_dir(None) os.environ.pop("PROJ_LIB", None) assert get_data_dir() is None
def test_get_data_dir__from_env_var(): with proj_env(), temporary_directory() as tmpdir, patch( "pyproj.datadir.os.path.abspath", return_value="INVALID"): set_data_dir(None) os.environ["PROJ_LIB"] = tmpdir create_projdb(tmpdir) assert get_data_dir() == tmpdir
def test_get_data_dir__from_env_var__multiple(): with proj_env(), temporary_directory() as tmpdir, patch( "pyproj.datadir.os.path.abspath", return_value="INVALID" ): set_data_dir(None) os.environ["PROJ_LIB"] = os.pathsep.join([tmpdir, tmpdir, tmpdir]) create_projdb(tmpdir) assert get_data_dir() == os.pathsep.join([tmpdir, tmpdir, tmpdir])
def proj_env(): """ Ensure environment variable the same at the end of the test. """ try: yield finally: # make sure the data dir is cleared set_data_dir(None)
def test_get_data_dir__from_path(): with proj_env(), temporary_directory() as tmpdir, patch( "pyproj.datadir.os.path.abspath", return_value="INVALID" ), patch("pyproj.datadir.find_executable") as find_exe: set_data_dir(None) os.environ.pop("PROJ_LIB", None) find_exe.return_value = os.path.join(tmpdir, "bin", "proj") proj_dir = os.path.join(tmpdir, "share", "proj") os.makedirs(proj_dir) create_projdb(proj_dir) assert get_data_dir() == proj_dir
def test_get_data_dir__internal(): with proj_env(), temporary_directory() as tmpdir: set_data_dir(None) os.environ["PROJ_LIB"] = tmpdir create_projdb(tmpdir) internal_proj_dir = os.path.join(tmpdir, "proj_dir", "share", "proj") os.makedirs(internal_proj_dir) create_projdb(internal_proj_dir) with patch("pyproj.datadir.os.path.abspath") as abspath_mock: abspath_mock.return_value = os.path.join(tmpdir, "randomfilename.py") assert get_data_dir() == internal_proj_dir
def test_get_data_dir__from_path(): with proj_env(), temporary_directory() as tmpdir, patch( "pyproj.datadir.os.path.abspath", return_value="INVALID"), patch( "pyproj.datadir.find_executable") as find_exe: set_data_dir(None) os.environ.pop("PROJ_LIB", None) find_exe.return_value = os.path.join(tmpdir, "bin", "proj") proj_dir = os.path.join(tmpdir, "share", "proj") os.makedirs(proj_dir) create_projdb(proj_dir) assert get_data_dir() == proj_dir
def proj_env(): """ Ensure environment variable the same at the end of the test. """ unset_data_dir() try: yield finally: # make sure the data dir is cleared unset_data_dir() # reset back to the original path set_data_dir(get_data_dir())
def proj_env(): """ Ensure environment variable the same at the end of the test. """ proj_lib = os.environ.get("PROJ_LIB") try: yield finally: # make sure the data dir is cleared set_data_dir(None) if proj_lib is not None: # add it back if it used to be there os.environ["PROJ_LIB"] = proj_lib else: # remove it if it wasn't there previously os.environ.pop("PROJ_LIB", None)
def test_get_data_dir__from_user(projdir_type, tmp_path): tmpdir = tmp_path / "proj" tmpdir.mkdir() tmpdir_env = tmp_path / "proj_env" tmpdir_env.mkdir() with proj_env(), patch.dict( os.environ, {"PROJ_LIB": str(tmpdir_env)}, clear=True ), patch("pyproj.datadir.Path.absolute", return_value=tmpdir / "datadir.py"), patch( "pyproj.datadir.sys.prefix", str(tmpdir_env) ): # noqa: E501 create_projdb(tmpdir) create_projdb(tmpdir_env) set_data_dir(projdir_type(tmpdir)) internal_proj_dir = tmpdir / "proj_dir" / "share" / "proj" internal_proj_dir.mkdir(parents=True) create_projdb(internal_proj_dir) assert get_data_dir() == str(tmpdir)
def test_get_data_dir__from_user(): with proj_env(), temporary_directory() as tmpdir, patch( "pyproj.datadir.os") as os_mock, patch( "pyproj.datadir.sys") as sys_mock, temporary_directory( ) as tmpdir_env: # noqa: E501 setup_os_mock( os_mock, abspath_return=os.path.join(tmpdir, "randomfilename.py"), proj_dir=tmpdir_env, ) sys_mock.prefix = tmpdir_env create_projdb(tmpdir) create_projdb(tmpdir_env) set_data_dir(tmpdir) internal_proj_dir = os.path.join(tmpdir, "proj_dir", "share", "proj") os.makedirs(internal_proj_dir) create_projdb(internal_proj_dir) assert get_data_dir() == tmpdir
def test_get_data_dir__from_user(tmp_path): tmpdir = tmp_path / "proj" tmpdir.mkdir() tmpdir = str(tmpdir) tmpdir_env = tmp_path / "proj_env" tmpdir_env.mkdir() tmpdir_env = str(tmpdir_env) with proj_env(), patch("pyproj.datadir.os") as os_mock, patch( "pyproj.datadir.sys") as sys_mock: # noqa: E501 setup_os_mock( os_mock, abspath_return=os.path.join(tmpdir, "randomfilename.py"), proj_dir=tmpdir_env, ) sys_mock.prefix = tmpdir_env create_projdb(tmpdir) create_projdb(tmpdir_env) set_data_dir(tmpdir) internal_proj_dir = os.path.join(tmpdir, "proj_dir", "share", "proj") os.makedirs(internal_proj_dir) create_projdb(internal_proj_dir) assert get_data_dir() == tmpdir
import logging from numbers import Number from pyproj import CRS, datadir from pyproj.transformer import Transformer, AreaOfInterest, TransformerGroup from pyproj.enums import WktVersion, TransformDirection from shapely import wkt from shapely.geometry import Polygon, MultiPoint, MultiLineString, MultiPolygon, GeometryCollection from shapely.ops import transform LOGGER = logging.getLogger(__name__) CURRENT_YEAR = float(datetime.datetime.now().year) _USER_PROJ_DATA = os.getenv('PROJ_DIR', None) if _USER_PROJ_DATA and datadir.get_data_dir() != _USER_PROJ_DATA: datadir.set_data_dir(_USER_PROJ_DATA) datadir.append_data_dir(_USER_PROJ_DATA) #: Process metadata and description PROCESS_METADATA = { 'version': '1.2.0', 'id': 'wkt-reprojector', 'title': 'WKT Reprojector', 'description': 'An example process that reprojects a geometry from one CRS to another, using PROJ v6. This will take account of possible datum shifts. Because of the use of PROJ v6, late-binding can be used, and 4D coordinates (three spatial components and one temporal component) are supported.', 'keywords': [ 'reprojection', 'PROJ', '2D', '3D', '4D', 'spatiotemporal transformation'
import math from tkinter import * from tkinter import filedialog, messagebox from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg from pyproj import Proj, transform from pyproj import _datadir, datadir from copy import deepcopy datadir.set_data_dir("./proj/") import traceback import matplotlib import matplotlib.pyplot import shapefile import os import numpy as np matplotlib.use('TkAgg') class PlotFrame(Frame): def clamp(self, n, smallest, largest): val = max(smallest, min(n, largest)) if n > largest or n < smallest: print("WARNING: Clamped " + n + " to " + val + " for arccos") return val def disable_stuff(self): self.importbutt.config(state="normal")