mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-10 12:00:21 +08:00
PERF: Implement cached transformer.from_crs for to_crs (#2762)
This commit is contained in:
+6
-2
@@ -2,6 +2,7 @@ import numbers
|
||||
import operator
|
||||
import warnings
|
||||
import inspect
|
||||
from functools import lru_cache
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
@@ -29,6 +30,9 @@ from . import _vectorized as vectorized
|
||||
from .sindex import _get_sindex_class
|
||||
|
||||
|
||||
TransformerFromCRS = lru_cache(Transformer.from_crs)
|
||||
|
||||
|
||||
class GeometryDtype(ExtensionDtype):
|
||||
type = BaseGeometry
|
||||
name = "geometry"
|
||||
@@ -779,7 +783,7 @@ class GeometryArray(ExtensionArray):
|
||||
if self.crs.is_exact_same(crs):
|
||||
return self
|
||||
|
||||
transformer = Transformer.from_crs(self.crs, crs, always_xy=True)
|
||||
transformer = TransformerFromCRS(self.crs, crs, always_xy=True)
|
||||
|
||||
new_data = vectorized.transform(self.data, transformer.transform)
|
||||
return GeometryArray(new_data, crs=crs)
|
||||
@@ -837,7 +841,7 @@ class GeometryArray(ExtensionArray):
|
||||
y_center = np.mean([miny, maxy])
|
||||
# ensure using geographic coordinates
|
||||
else:
|
||||
transformer = Transformer.from_crs(self.crs, "EPSG:4326", always_xy=True)
|
||||
transformer = TransformerFromCRS(self.crs, "EPSG:4326", always_xy=True)
|
||||
if compat.PYPROJ_GE_31:
|
||||
minx, miny, maxx, maxy = transformer.transform_bounds(
|
||||
minx, miny, maxx, maxy
|
||||
|
||||
Reference in New Issue
Block a user