diff --git a/pyproj/crs/crs.py b/pyproj/crs/crs.py index 44f6c886d..51bf05bed 100644 --- a/pyproj/crs/crs.py +++ b/pyproj/crs/crs.py @@ -321,8 +321,8 @@ def _crs(self): self._local.crs = _CRS(self.srs) return self._local.crs - @staticmethod - def from_authority(auth_name: str, code: Union[str, int]) -> "CRS": + @classmethod + def from_authority(cls, auth_name: str, code: Union[str, int]) -> "CRS": """ .. versionadded:: 2.2.0 @@ -339,10 +339,10 @@ def from_authority(auth_name: str, code: Union[str, int]) -> "CRS": ------- CRS """ - return CRS(_prepare_from_authority(auth_name, code)) + return cls(_prepare_from_authority(auth_name, code)) - @staticmethod - def from_epsg(code: Union[str, int]) -> "CRS": + @classmethod + def from_epsg(cls, code: Union[str, int]) -> "CRS": """Make a CRS from an EPSG code Parameters @@ -354,10 +354,10 @@ def from_epsg(code: Union[str, int]) -> "CRS": ------- CRS """ - return CRS(_prepare_from_epsg(code)) + return cls(_prepare_from_epsg(code)) - @staticmethod - def from_proj4(in_proj_string: str) -> "CRS": + @classmethod + def from_proj4(cls, in_proj_string: str) -> "CRS": """ .. versionadded:: 2.2.0 @@ -374,10 +374,10 @@ def from_proj4(in_proj_string: str) -> "CRS": """ if not is_proj(in_proj_string): raise CRSError(f"Invalid PROJ string: {in_proj_string}") - return CRS(_prepare_from_string(in_proj_string)) + return cls(_prepare_from_string(in_proj_string)) - @staticmethod - def from_wkt(in_wkt_string: str) -> "CRS": + @classmethod + def from_wkt(cls, in_wkt_string: str) -> "CRS": """ .. versionadded:: 2.2.0 @@ -394,10 +394,10 @@ def from_wkt(in_wkt_string: str) -> "CRS": """ if not is_wkt(in_wkt_string): raise CRSError(f"Invalid WKT string: {in_wkt_string}") - return CRS(_prepare_from_string(in_wkt_string)) + return cls(_prepare_from_string(in_wkt_string)) - @staticmethod - def from_string(in_crs_string: str) -> "CRS": + @classmethod + def from_string(cls, in_crs_string: str) -> "CRS": """ Make a CRS from: @@ -416,7 +416,7 @@ def from_string(in_crs_string: str) -> "CRS": ------- CRS """ - return CRS(_prepare_from_string(in_crs_string)) + return cls(_prepare_from_string(in_crs_string)) def to_string(self) -> str: """ @@ -437,8 +437,8 @@ def to_string(self) -> str: return ":".join(auth_info) return self.srs - @staticmethod - def from_user_input(value: Any, **kwargs) -> "CRS": + @classmethod + def from_user_input(cls, value: Any, **kwargs) -> "CRS": """ Initialize a CRS class instance with: - PROJ string @@ -463,7 +463,7 @@ def from_user_input(value: Any, **kwargs) -> "CRS": """ if isinstance(value, CRS): return value - return CRS(value, **kwargs) + return cls(value, **kwargs) def get_geod(self) -> Optional[Geod]: """ @@ -480,8 +480,8 @@ def get_geod(self) -> Optional[Geod]: b=self.ellipsoid.semi_minor_metre, ) - @staticmethod - def from_dict(proj_dict: dict) -> "CRS": + @classmethod + def from_dict(cls, proj_dict: dict) -> "CRS": """ .. versionadded:: 2.2.0 @@ -496,10 +496,10 @@ def from_dict(proj_dict: dict) -> "CRS": ------- CRS """ - return CRS(_prepare_from_dict(proj_dict)) + return cls(_prepare_from_dict(proj_dict)) - @staticmethod - def from_json(crs_json: str) -> "CRS": + @classmethod + def from_json(cls, crs_json: str) -> "CRS": """ .. versionadded:: 2.4.0 @@ -514,10 +514,10 @@ def from_json(crs_json: str) -> "CRS": ------- CRS """ - return CRS.from_json_dict(_load_proj_json(crs_json)) + return cls.from_json_dict(_load_proj_json(crs_json)) - @staticmethod - def from_json_dict(crs_dict: dict) -> "CRS": + @classmethod + def from_json_dict(cls, crs_dict: dict) -> "CRS": """ .. versionadded:: 2.4.0 @@ -532,7 +532,7 @@ def from_json_dict(crs_dict: dict) -> "CRS": ------- CRS """ - return CRS(json.dumps(crs_dict)) + return cls(json.dumps(crs_dict)) def to_dict(self) -> dict: """ diff --git a/pyproj/transformer.py b/pyproj/transformer.py index 1549fa93a..7fa238dae 100644 --- a/pyproj/transformer.py +++ b/pyproj/transformer.py @@ -417,8 +417,9 @@ def is_network_enabled(self) -> bool: """ return self._transformer.is_network_enabled - @staticmethod + @classmethod def from_proj( + cls, proj_from: Any, proj_to: Any, skip_equivalent: bool = False, @@ -461,7 +462,7 @@ def from_proj( if not isinstance(proj_to, Proj): proj_to = Proj(proj_to) - return Transformer.from_crs( + return cls.from_crs( proj_from.crs, proj_to.crs, skip_equivalent=skip_equivalent, @@ -469,8 +470,9 @@ def from_proj( area_of_interest=area_of_interest, ) - @staticmethod + @classmethod def from_crs( + cls, crs_from: Any, crs_to: Any, skip_equivalent: bool = False, @@ -533,7 +535,7 @@ def from_crs( stacklevel=2, ) - return Transformer( + return cls( TransformerFromCRS( CRS.from_user_input(crs_from).srs, CRS.from_user_input(crs_to).srs, @@ -545,8 +547,8 @@ def from_crs( ) ) - @staticmethod - def from_pipeline(proj_pipeline: str) -> "Transformer": + @classmethod + def from_pipeline(cls, proj_pipeline: str) -> "Transformer": """Make a Transformer from a PROJ pipeline string. https://proj.org/operations/pipeline.html @@ -576,7 +578,7 @@ def from_pipeline(proj_pipeline: str) -> "Transformer": Transformer """ - return Transformer(TransformerFromPipeline(proj_pipeline)) + return cls(TransformerFromPipeline(proj_pipeline)) def transform( self,