Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REF: Remove network kwarg from Proj and Transformer #708

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 1 addition & 5 deletions pyproj/_transformer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class _TransformerGroup:
skip_equivalent: bool = False,
always_xy: bool = False,
area_of_interest: Optional[AreaOfInterest] = None,
network: Optional[bool] = None,
) -> None: ...

class _Transformer(Base):
Expand Down Expand Up @@ -71,12 +70,9 @@ class _Transformer(Base):
skip_equivalent: bool = False,
always_xy: bool = False,
area_of_interest: Optional[AreaOfInterest] = None,
network: Optional[bool] = None,
) -> "_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 Down
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
2 changes: 1 addition & 1 deletion pyproj/crs/_cf1x8.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _rotated_latitude_longitude(cf_params):
}

_GEOGRAPHIC_GRID_MAPPING_NAME_MAP = {
"rotated_latitude_longitude": _rotated_latitude_longitude,
"rotated_latitude_longitude": _rotated_latitude_longitude
}


Expand Down
6 changes: 1 addition & 5 deletions pyproj/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ def set_ca_bundle_path(ca_bundle_path: Union[Path, str, bool, None] = None) -> N
or an empty string then it will default to the system settings or environment
variables.
"""
env_var_names = (
"PROJ_CURL_CA_BUNDLE",
"CURL_CA_BUNDLE",
"SSL_CERT_FILE",
)
env_var_names = ("PROJ_CURL_CA_BUNDLE", "CURL_CA_BUNDLE", "SSL_CERT_FILE")
if ca_bundle_path is False:
# need to reset CA Bundle path to use system settings
# or environment variables because it
Expand Down
17 changes: 2 additions & 15 deletions pyproj/proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ class Proj(Transformer):
"""

def __init__(
self,
projparams: Any = None,
preserve_units: bool = True,
network=None,
**kwargs,
self, projparams: Any = None, preserve_units: bool = True, **kwargs
) -> None:
"""
A Proj class instance is initialized with proj map projection
Expand All @@ -59,19 +55,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 +131,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
5 changes: 1 addition & 4 deletions pyproj/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ def _bbox_from_geom(geom: Dict[str, Any]) -> Optional[BBox]:


def _filter_bbox(
feature: Dict[str, Any],
bbox: BBox,
spatial_test: str,
include_world_coverage: bool,
feature: Dict[str, Any], bbox: BBox, spatial_test: str, include_world_coverage: bool
) -> bool:
"""
Filter by the bounding box. Designed to use with 'filter'
Expand Down
Loading