Skip to content

Commit

Permalink
Add projection reuse (and bump version)
Browse files Browse the repository at this point in the history
  • Loading branch information
Diviloper committed Feb 20, 2024
1 parent b637659 commit 5452e3c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pymeos/pymeos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
MeosGeoJsonOutputError,
)

__version__ = "1.1.3rc1"
__version__ = "1.1.3rc2"
__all__ = [
# initialization
"pymeos_initialize",
Expand Down
6 changes: 5 additions & 1 deletion pymeos/pymeos/main/tpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class TPoint(Temporal[shp.Point, TG, TI, TS, TSS], TSimplifiable, ABC):
Abstract class for temporal points.
"""

_projection_cache: dict[tuple[int, int], 'LWPROJ'] = {}

# ------------------------- Constructors ----------------------------------
def __init__(self, _inner) -> None:
super().__init__()
Expand Down Expand Up @@ -500,7 +502,9 @@ def transform(self: Self, srid: int) -> Self:
MEOS Functions:
tpoint_transform
"""
result = tpoint_transform(self._inner, srid)
if (self.srid(), srid) not in self._projection_cache:
self._projection_cache[(self.srid(), srid)] = lwproj_transform(self.srid(), srid)
result = tpoint_transform_pj(self._inner, srid, self._projection_cache[(self.srid(), srid)])
return Temporal._factory(result)

# ------------------------- Restrictions ----------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pymeos/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ license = { file = 'LICENSE' }

requires-python = '>=3.7'
dependencies = [
'pymeos-cffi ==1.1.0rc1',
'pymeos-cffi ==1.1.0rc2',
'python-dateutil',
'shapely',
]
Expand Down
4 changes: 3 additions & 1 deletion pymeos_cffi/pymeos_cffi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .enums import *
from .errors import *

__version__ = "1.1.0rc1"
__version__ = "1.1.0rc2"
__all__ = [
# Exceptions
"MeosException",
Expand Down Expand Up @@ -1003,6 +1003,8 @@
"tpoint_round",
"tpoint_transform",
"tpoint_transform_pipeline",
"tpoint_transform_pj",
"lwproj_transform",
"tpointarr_round",
"temporal_append_tinstant",
"temporal_append_tsequence",
Expand Down
19 changes: 19 additions & 0 deletions pymeos_cffi/pymeos_cffi/builder/meos.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,23 @@ extern double lwpoint_get_m(const LWPOINT *point);
extern int lwgeom_has_z(const LWGEOM *geom);
extern int lwgeom_has_m(const LWGEOM *geom);

struct PJconsts;
typedef struct PJconsts PJ;

typedef struct LWPROJ
{
PJ* pj;


bool pipeline_is_forward;


uint8_t source_is_latlong;

double source_semi_major_metre;
double source_semi_minor_metre;
} LWPROJ;



typedef struct
Expand Down Expand Up @@ -1511,6 +1528,8 @@ extern Temporal *tint_shift_value(const Temporal *temp, int shift);
extern Temporal *tpoint_round(const Temporal *temp, int maxdd);
extern Temporal *tpoint_transform(const Temporal *temp, int32 srid);
extern Temporal *tpoint_transform_pipeline(const Temporal *temp, char *pipelinestr, int32 srid, bool is_forward);
extern Temporal *tpoint_transform_pj(const Temporal *temp, int32 srid, const LWPROJ* pj);
extern LWPROJ *lwproj_transform(int32 srid_from, int32 srid_to);
extern Temporal **tpointarr_round(const Temporal **temp, int count, int maxdd);

extern Temporal *temporal_append_tinstant(Temporal *temp, const TInstant *inst, double maxdist, Interval *maxt, bool expand);
Expand Down
2 changes: 1 addition & 1 deletion pymeos_cffi/pymeos_cffi/builder/templates/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .enums import *
from .errors import *

__version__ = "1.1.0rc1"
__version__ = "1.1.0rc2"
__all__ = [
# Exceptions
"MeosException",
Expand Down
19 changes: 19 additions & 0 deletions pymeos_cffi/pymeos_cffi/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7733,6 +7733,25 @@ def tpoint_transform_pipeline(
return result if result != _ffi.NULL else None


def tpoint_transform_pj(
temp: "const Temporal *", srid: int, pj: "const LWPROJ*"
) -> "Temporal *":
temp_converted = _ffi.cast("const Temporal *", temp)
srid_converted = _ffi.cast("int32", srid)
pj_converted = _ffi.cast("const LWPROJ*", pj)
result = _lib.tpoint_transform_pj(temp_converted, srid_converted, pj_converted)
_check_error()
return result if result != _ffi.NULL else None


def lwproj_transform(srid_from: int, srid_to: int) -> "LWPROJ *":
srid_from_converted = _ffi.cast("int32", srid_from)
srid_to_converted = _ffi.cast("int32", srid_to)
result = _lib.lwproj_transform(srid_from_converted, srid_to_converted)
_check_error()
return result if result != _ffi.NULL else None


def tpointarr_round(temp: "const Temporal **", count: int, maxdd: int) -> "Temporal **":
temp_converted = [_ffi.cast("const Temporal *", x) for x in temp]
result = _lib.tpointarr_round(temp_converted, count, maxdd)
Expand Down

0 comments on commit 5452e3c

Please sign in to comment.