Skip to content

Commit

Permalink
REF: Add custom proj_create_crs_to_crs to allow options
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Mar 20, 2021
1 parent 8a19f39 commit b2aba68
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
42 changes: 42 additions & 0 deletions pyproj/_transformer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ from pyproj._crs cimport (
)
from pyproj._datadir cimport pyproj_context_create, pyproj_context_destroy

from pyproj._datadir import _LOGGER
from pyproj.aoi import AreaOfInterest
from pyproj.compat import cstrencode, pystrdecode
from pyproj.enums import ProjVersion, TransformDirection
Expand Down Expand Up @@ -233,6 +234,46 @@ cdef _CRS get_transform_crs(_CRS in_crs):
return in_crs.source_crs if in_crs.is_bound else in_crs


cdef PJ* proj_create_crs_to_crs(
PJ_CONTEXT *ctx,
const char *source_crs_str,
const char *target_crs_str,
PJ_AREA *area,
const char* const *options,
):
"""
This is the same as proj_create_crs_to_crs in proj.h
with the options added. It is a hack for stabilily
reasons.
Reference: https://github.com/pyproj4/pyproj/pull/800
"""
cdef PJ *source_crs = proj_create(ctx, source_crs_str)
if source_crs == NULL:
_LOGGER.debug(
"PROJ_DEBUG: proj_create_crs_to_crs: Cannot instantiate source_crs"
)
return NULL
cdef PJ *target_crs = proj_create(ctx, target_crs_str)
if target_crs == NULL:
proj_destroy(source_crs)
_LOGGER.debug(
"PROJ_DEBUG: proj_create_crs_to_crs: Cannot instantiate target_crs"
)
return NULL

cdef PJ* transform = proj_create_crs_to_crs_from_pj(
ctx,
source_crs,
target_crs,
area,
options,
)
proj_destroy(source_crs)
proj_destroy(target_crs)
return transform


cdef class _Transformer(Base):
def __cinit__(self):
self._area_of_use = None
Expand Down Expand Up @@ -371,6 +412,7 @@ cdef class _Transformer(Base):
cstrencode(crs_from.srs),
cstrencode(crs_to.srs),
pj_area_of_interest,
NULL,
)
finally:
if pj_area_of_interest != NULL:
Expand Down
8 changes: 7 additions & 1 deletion pyproj/proj.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ cdef extern from "proj.h":
double *t, size_t st, size_t nt
) nogil
ctypedef struct PJ_AREA
PJ *proj_create_crs_to_crs(PJ_CONTEXT *ctx, const char *source_crs, const char *target_crs, PJ_AREA *area)
PJ *proj_create_crs_to_crs_from_pj(
PJ_CONTEXT *ctx,
PJ *source_crs,
PJ *target_crs,
PJ_AREA *area,
const char* const *options,
)

ctypedef enum PJ_COMPARISON_CRITERION:
PJ_COMP_STRICT
Expand Down

0 comments on commit b2aba68

Please sign in to comment.