Skip to content

Commit

Permalink
REF: Remove network kwarg from Proj and Transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Sep 20, 2020
1 parent 20b7ddf commit 518a574
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 137 deletions.
18 changes: 9 additions & 9 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ Change Log
* Minimum supported Python version 3.6 (issue #499)
* Minimum PROJ version 7.2 (issues #599 & #689)
* WHL: Removed datumgrids from wheels because not needed with RFC 4 (pull #628)
* Refactor Proj to inherit from Transformer (issue #624)
* ENH: Added :ref:`network` (#675, #691, #695)
* ENH: Added ability to use global context (issue #661)
* ENH: Added transformation grid sync API/CLI (issue #572)
* ENH: Support obects with '__array__' method (pandas.Series, xarray.DataArray, dask.array.Array) (issue #573)
* ENH: Added :func:`pyproj.datadir.get_user_data_dir` (pull #636)
* ENH: Added network methods to Transformer (issue #629)
* ENH: Use 'proj_get_units_from_database' in :func:`pyproj.get_units_map` & cleanup :func:`pyproj.get_codes` (issue #619)
* ENH: Added :attr:`pyproj.transformer.Transformer.is_network_enabled` (issue #629)
* ENH: Added :meth:`pyproj.transformer.TransformerGroup.download_grids` (pull #643)
* ENH: Use 'proj_get_units_from_database' in :func:`pyproj.database.get_units_map` & cleanup :func:`pyproj.database.get_codes` (issue #619)
* ENH: Added support for radians for Proj & Transformer.from_pipeline & use less gil (issue #612)
* ENH: Datum.from_name default to check all datum types (issue #606)
* ENH: Use from_user_input in __eq__ when comparing CRS sub-classes (i.e. PrimeMeridian, Datum, Ellipsoid, etc.) (issue #606)
* ENH: Added :meth:`pyproj.transformer.TransformerGroup.download_grids` (pull #643)
* ENH: Added transformation grid sync API/CLI (issue #572)
* ENH: Add support for coordinate systems with CRS using CF conventions (issue #536)
* ENH: Use `proj_is_equivalent_to_with_ctx` in the place of `proj_is_equivalent_to` internally (issue #666)
* BUG: Add support for identifying engineering/parametric/temporal datums (issue #670)
* ENH: Added ability to use global context (issue #661)
* ENH: Add support for temporal CRS CF coordinate system (issue #672)
* BUG: Fix handling of polygon holes when calculating area in Geod (pull #686)
* ENH: Added :ref:`network` (#675, #691, #695)
* ENH: Added support for debugging internal PROJ (pull #696)
* ENH: Added pathlib support for data directory methods (pull #702)
* ENH: Added `pyproj.database.query_crs_info` (pull #703)
* ENH: Added :func:`pyproj.database.query_crs_info` (pull #703)
* REF: Refactor Proj to inherit from Transformer (issue #624)
* REF: Added `pyproj.database`, `pyproj.aoi`, and `pyproj.list` modules (pull #703)
* BUG: Fix handling of polygon holes when calculating area in Geod (pull #686)

2.6.1
~~~~~
Expand Down
8 changes: 3 additions & 5 deletions docs/transformation_grids.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ Available methods for download include:
- `pyproj sync <cli.html#sync>`__ command line program (pyproj 3+; useful if you use pyproj wheels).
- Enabling `PROJ network <https://proj.org/usage/network.html>`__ capabilities.
.. note:: You can use the `network` kwarg when initializing
:class:`pyproj.Proj` or :class:`pyproj.Transformer <pyproj.transformer.Transformer>`
- Enabling `PROJ network <https://proj.org/usage/network.html>`__ capabilities. See also :ref:`network`.
- Download stable from https://download.osgeo.org/proj or latest from https://github.com/OSGeo/PROJ-data
Expand Down Expand Up @@ -91,7 +88,8 @@ What grids to download?
- Have a machine that can hold and extra 500 MB - 1 GB of data? Then downloading all grids shouldn't be an issue.
- Have a machine with limited space, a great network connection, and PROJ 7+? Look into `PROJ network <https://proj.org/usage/network.html>`__ capabilities.
- Have a machine with limited space, a great network connection, and PROJ 7+?
Look into `PROJ network <https://proj.org/usage/network.html>`__ capabilities. See also :ref:`network`.
- Have a machine with limited space and want to pre-download files?
Expand Down
3 changes: 1 addition & 2 deletions pyproj/_crs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,10 @@ cdef _get_concatenated_operations(PJ_CONTEXT* context, PJ* concatenated_operatio
)
cdef PJ* operation = NULL
cdef PJ_CONTEXT* sub_context = NULL
cdef int network_enabled = proj_context_is_network_enabled(context)
cdef int iii = 0
operations = []
for iii in range(step_count):
sub_context = pyproj_context_create(network=network_enabled)
sub_context = pyproj_context_create()
operation = proj_concatoperation_get_step(
sub_context,
concatenated_operation,
Expand Down
2 changes: 1 addition & 1 deletion pyproj/_datadir.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include "proj.pxi"


cdef PJ_CONTEXT* pyproj_context_create(network=*) except *
cdef PJ_CONTEXT* pyproj_context_create() except *
21 changes: 2 additions & 19 deletions pyproj/_datadir.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,8 @@ cdef void set_context_data_dir(PJ_CONTEXT* context) except *:
free(c_data_dir)


cdef void pyproj_context_set_enable_network(
PJ_CONTEXT* context,
network=None,
) except *:
if network is not None:
enabled = proj_context_set_enable_network(context, bool(network))
if network and not enabled:
warnings.warn("PROJ network cannot be enabled.")


cdef void pyproj_context_initialize(
PJ_CONTEXT* context,
network=None,
bint autoclose_database=True,
) except *:
"""
Expand All @@ -142,30 +131,24 @@ cdef void pyproj_context_initialize(
proj_context_use_proj4_init_rules(context, 1)
if autoclose_database:
proj_context_set_autoclose_database(context, 1)
pyproj_context_set_enable_network(context, network=network)
set_context_data_dir(context)


cdef PJ_CONTEXT* pyproj_context_create(
network=None,
) except *:
cdef PJ_CONTEXT* pyproj_context_create() except *:
"""
Create and initialize the context(s) for pyproj.
This also manages whether the global context is used.
"""
global _USE_GLOBAL_CONTEXT
if _USE_GLOBAL_CONTEXT:
return NULL
cdef PJ_CONTEXT* context = proj_context_create()
pyproj_context_set_enable_network(context, network=network)
return context
return proj_context_create()


def _pyproj_global_context_initialize():
global _USE_GLOBAL_CONTEXT
pyproj_context_initialize(
NULL,
network=None,
autoclose_database=not _USE_GLOBAL_CONTEXT
)

Expand Down
64 changes: 46 additions & 18 deletions pyproj/_transformer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ from pyproj.enums import TransformDirection

proj_version_str: str


class AreaOfInterest(NamedTuple):
west_lon_degree: float
south_lat_degree: float
east_lon_degree: float
north_lat_degree: float


class Factors(NamedTuple):
meridional_scale: float
parallel_scale: float
Expand All @@ -26,19 +28,22 @@ class Factors(NamedTuple):
dy_dlam: float
dy_dphi: float


class _TransformerGroup:
_transformers: Any
_unavailable_operations: List[CoordinateOperation]
_best_available: bool

def __init__(
self,
crs_from: _CRS,
crs_to: _CRS,
skip_equivalent: bool = False,
always_xy: bool = False,
area_of_interest: Optional[AreaOfInterest] = None,
network: Optional[bool] = None,
) -> None: ...
) -> None:
...


class _Transformer(Base):
input_geographic: bool
Expand All @@ -48,35 +53,53 @@ class _Transformer(Base):
projections_equivalent: bool
projections_exact_same: bool
type_name: str

@property
def id(self) -> str: ...
def id(self) -> str:
...

@property
def description(self) -> str: ...
def description(self) -> str:
...

@property
def definition(self) -> str: ...
def definition(self) -> str:
...

@property
def has_inverse(self) -> bool: ...
def has_inverse(self) -> bool:
...

@property
def accuracy(self) -> float: ...
def accuracy(self) -> float:
...

@property
def area_of_use(self) -> AreaOfUse: ...
def area_of_use(self) -> AreaOfUse:
...

@property
def operations(self) -> Union[Tuple[CoordinateOperation], None]: ...
def operations(self) -> Union[Tuple[CoordinateOperation], None]:
...

@property
def is_network_enabled(self) -> bool: ...
def is_network_enabled(self) -> bool:
...

@staticmethod
def from_crs(
crs_from: _CRS,
crs_to: _CRS,
skip_equivalent: bool = False,
always_xy: bool = False,
area_of_interest: Optional[AreaOfInterest] = None,
network: Optional[bool] = None,
) -> "_Transformer": ...
) -> "_Transformer":
...

@staticmethod
def from_pipeline(
proj_pipeline: str, network: Optional[bool] = None
) -> "_Transformer": ...
def from_pipeline(proj_pipeline: str) -> "_Transformer":
...

def _transform(
self,
inx: Any,
Expand All @@ -86,7 +109,9 @@ class _Transformer(Base):
direction: Union[TransformDirection, str],
radians: bool,
errcheck: bool,
) -> None: ...
) -> None:
...

def _transform_sequence(
self,
stride: int,
Expand All @@ -96,7 +121,10 @@ class _Transformer(Base):
time_3rd: bool,
radians: bool,
errcheck: bool,
) -> None: ...
) -> None:
...

def _get_factors(
self, longitude: Any, latitude: Any, radians: bool, errcheck: bool
) -> Factors: ...
) -> Factors:
...
12 changes: 5 additions & 7 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ cdef class _TransformerGroup:
skip_equivalent=False,
always_xy=False,
area_of_interest=None,
network=None,
):
"""
From PROJ docs:
Expand All @@ -124,7 +123,7 @@ cdef class _TransformerGroup:
area of use of the CRS), and by increasing accuracy. Operations
with unknown accuracy are sorted last, whatever their area.
"""
self.context = pyproj_context_create(network=network)
self.context = pyproj_context_create()
cdef PJ_OPERATION_FACTORY_CONTEXT* operation_factory_context = NULL
cdef PJ_OBJ_LIST * pj_operations = NULL
cdef PJ* pj_transform = NULL
Expand Down Expand Up @@ -174,7 +173,7 @@ cdef class _TransformerGroup:
)
num_operations = proj_list_get_count(pj_operations)
for iii in range(num_operations):
context = pyproj_context_create(network=network)
context = pyproj_context_create()
pj_transform = proj_list_get(
context,
pj_operations,
Expand Down Expand Up @@ -306,7 +305,6 @@ cdef class _Transformer(Base):
skip_equivalent=False,
always_xy=False,
area_of_interest=None,
network=None,
):
"""
Create a transformer from CRS objects
Expand Down Expand Up @@ -336,7 +334,7 @@ cdef class _Transformer(Base):
east_lon_degree,
north_lat_degree,
)
transformer.context = pyproj_context_create(network=network)
transformer.context = pyproj_context_create()
transformer.projobj = proj_create_crs_to_crs(
transformer.context,
cstrencode(crs_from.srs),
Expand Down Expand Up @@ -386,12 +384,12 @@ cdef class _Transformer(Base):
return transformer

@staticmethod
def from_pipeline(const char *proj_pipeline, network=None):
def from_pipeline(const char *proj_pipeline):
"""
Create Transformer from a PROJ pipeline string.
"""
cdef _Transformer transformer = _Transformer()
transformer.context = pyproj_context_create(network=network)
transformer.context = pyproj_context_create()
# initialize projection
transformer.projobj = proj_create(
transformer.context,
Expand Down
12 changes: 1 addition & 11 deletions pyproj/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def __init__(
self,
projparams: Any = None,
preserve_units: bool = True,
network=None,
**kwargs,
) -> None:
"""
Expand All @@ -59,19 +58,12 @@ def __init__(
https://proj.org/operations/projections/index.html for examples of
key/value pairs defining different map projections.
.. versionadded:: 3.0.0 network
Parameters
----------
projparams: int, str, dict, pyproj.CRS
A PROJ or WKT string, PROJ dict, EPSG integer, or a pyproj.CRS instance.
preserve_units: bool
If false, will ensure +units=m.
network: bool, optional
Default is None, which uses the system defaults for networking.
If True, it will force the use of network for grids regardless of
any other network setting. If False, it will force disable use of
network for grids regardless of any other network setting.
**kwargs:
PROJ projection parameters.
Expand Down Expand Up @@ -142,9 +134,7 @@ def __init__(
projstring = self.crs.to_proj4() or self.crs.srs

self.srs = re.sub(r"\s\+?type=crs", "", projstring).strip()
super().__init__(
_Transformer.from_pipeline(cstrencode(self.srs), network=network)
)
super().__init__(_Transformer.from_pipeline(cstrencode(self.srs)))

def __call__(
self,
Expand Down
Loading

0 comments on commit 518a574

Please sign in to comment.