def __call__(self) -> _Transformer: """ Returns ------- _Transformer """ return _Transformer.from_crs( cstrencode(self.crs_from), cstrencode(self.crs_to), always_xy=self.always_xy, area_of_interest=self.area_of_interest, authority=self.authority, accuracy=self.accuracy, allow_ballpark=self.allow_ballpark, )
def __call__(self) -> _Transformer: """ Returns ------- _Transformer """ return _Transformer.from_pipeline(cstrencode(self.proj_pipeline))
def from_pipeline(proj_pipeline: str, network: Optional[bool] = None) -> "Transformer": """Make a Transformer from a PROJ pipeline string. https://proj.org/operations/pipeline.html .. versionadded:: 3.0.0 network Parameters ---------- proj_pipeline: str Projection pipeline string. 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. Returns ------- Transformer """ return Transformer( _Transformer.from_pipeline(cstrencode(proj_pipeline), network=network))
def from_pipeline(proj_pipeline: str) -> "Transformer": """Make a Transformer from a PROJ pipeline string. https://proj.org/operations/pipeline.html Parameters ---------- proj_pipeline: str Projection pipeline string. Returns ------- Transformer """ return Transformer(_Transformer.from_pipeline(cstrencode(proj_pipeline)))
def from_pipeline(proj_pipeline): """Make a Transformer from a PROJ pipeline string. https://proj4.org/operations/pipeline.html Parameters ---------- proj_pipeline: str Projection pipeline string. Returns ------- :obj:`pyproj.Transformer` """ transformer = Transformer() transformer._transformer = _Transformer.from_pipeline(cstrencode(proj_pipeline)) return transformer
def __init__(self, projparams=None, preserve_units=True, **kwargs): """ initialize a Proj class instance. See the PROJ documentation (https://proj.org) for more information about projection parameters. Parameters ---------- projparams: int, str, dict, pyproj.CRS A PROJ or WKT string, PROJ dict, EPSG integer, or a pyproj.CRS instnace. preserve_units: bool If false, will ensure +units=m. **kwargs: PROJ projection parameters. Example usage: >>> from pyproj import Proj >>> p = Proj(proj='utm',zone=10,ellps='WGS84', preserve_units=False) >>> x,y = p(-120.108, 34.36116666) >>> 'x=%9.3f y=%11.3f' % (x,y) 'x=765975.641 y=3805993.134' >>> 'lon=%8.3f lat=%5.3f' % p(x,y,inverse=True) 'lon=-120.108 lat=34.361' >>> # do 3 cities at a time in a tuple (Fresno, LA, SF) >>> lons = (-119.72,-118.40,-122.38) >>> lats = (36.77, 33.93, 37.62 ) >>> x,y = p(lons, lats) >>> 'x: %9.3f %9.3f %9.3f' % x 'x: 792763.863 925321.537 554714.301' >>> 'y: %9.3f %9.3f %9.3f' % y 'y: 4074377.617 3763936.941 4163835.303' >>> lons, lats = p(x, y, inverse=True) # inverse transform >>> 'lons: %8.3f %8.3f %8.3f' % lons 'lons: -119.720 -118.400 -122.380' >>> 'lats: %8.3f %8.3f %8.3f' % lats 'lats: 36.770 33.930 37.620' >>> p2 = Proj('+proj=utm +zone=10 +ellps=WGS84', preserve_units=False) >>> x,y = p2(-120.108, 34.36116666) >>> 'x=%9.3f y=%11.3f' % (x,y) 'x=765975.641 y=3805993.134' >>> p = Proj(init="epsg:32667", preserve_units=False) >>> 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045) 'x=-1783506.250 y= 6193827.033 (meters)' >>> p = Proj("+init=epsg:32667") >>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045) 'x=-5851386.754 y=20320914.191 (feet)' >>> # test data with radian inputs >>> p1 = Proj(init="epsg:4214") >>> x1, y1 = p1(116.366, 39.867) >>> '{:.3f} {:.3f}'.format(x1, y1) '2.031 0.696' >>> x2, y2 = p1(x1, y1, inverse=True) >>> '{:.3f} {:.3f}'.format(x2, y2) '116.366 39.867' """ self.crs = CRS.from_user_input( projparams if projparams is not None else kwargs) # make sure units are meters if preserve_units is False. if not preserve_units and "foot" in self.crs.axis_info[0].unit_name: projstring = self.crs.to_proj4(4) projstring = re.sub(r"\s\+units=[\w-]+", "", projstring) projstring += " +units=m" self.crs = CRS(projstring) projstring = self.crs.to_proj4() or self.crs.srs projstring = re.sub(r"\s\+?type=crs", "", projstring) super(Proj, self).__init__(cstrencode(projstring.strip()))
def __init__( self, projparams: Any = None, preserve_units: bool = True, network=None, **kwargs, ) -> None: """ A Proj class instance is initialized with proj map projection control parameter key/value pairs. The key/value pairs can either be passed in a dictionary, or as keyword arguments, or as a PROJ string (compatible with the proj command). See 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. Example usage: >>> from pyproj import Proj >>> p = Proj(proj='utm',zone=10,ellps='WGS84', preserve_units=False) >>> x,y = p(-120.108, 34.36116666) >>> 'x=%9.3f y=%11.3f' % (x,y) 'x=765975.641 y=3805993.134' >>> 'lon=%8.3f lat=%5.3f' % p(x,y,inverse=True) 'lon=-120.108 lat=34.361' >>> # do 3 cities at a time in a tuple (Fresno, LA, SF) >>> lons = (-119.72,-118.40,-122.38) >>> lats = (36.77, 33.93, 37.62 ) >>> x,y = p(lons, lats) >>> 'x: %9.3f %9.3f %9.3f' % x 'x: 792763.863 925321.537 554714.301' >>> 'y: %9.3f %9.3f %9.3f' % y 'y: 4074377.617 3763936.941 4163835.303' >>> lons, lats = p(x, y, inverse=True) # inverse transform >>> 'lons: %8.3f %8.3f %8.3f' % lons 'lons: -119.720 -118.400 -122.380' >>> 'lats: %8.3f %8.3f %8.3f' % lats 'lats: 36.770 33.930 37.620' >>> p2 = Proj('+proj=utm +zone=10 +ellps=WGS84', preserve_units=False) >>> x,y = p2(-120.108, 34.36116666) >>> 'x=%9.3f y=%11.3f' % (x,y) 'x=765975.641 y=3805993.134' >>> p = Proj("epsg:32667", preserve_units=False) >>> 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045) 'x=-1783506.250 y= 6193827.033 (meters)' >>> p = Proj("epsg:32667") >>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045) 'x=-5851386.754 y=20320914.191 (feet)' >>> # test data with radian inputs >>> p1 = Proj("epsg:4214") >>> x1, y1 = p1(116.366, 39.867) >>> f'{x1:.3f} {y1:.3f}' '116.366 39.867' >>> x2, y2 = p1(x1, y1, inverse=True) >>> f'{x2:.3f} {y2:.3f}' '116.366 39.867' """ self.crs = CRS.from_user_input(projparams, **kwargs) # make sure units are meters if preserve_units is False. if not preserve_units and "foot" in self.crs.axis_info[0].unit_name: # ignore export to PROJ string deprecation warning with warnings.catch_warnings(): warnings.filterwarnings( "ignore", "You will likely lose important projection information", UserWarning, ) projstring = self.crs.to_proj4(4) projstring = re.sub(r"\s\+units=[\w-]+", "", projstring) projstring += " +units=m" self.crs = CRS(projstring) # ignore export to PROJ string deprecation warning with warnings.catch_warnings(): warnings.filterwarnings( "ignore", "You will likely lose important projection information", UserWarning, ) 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) )
def __init__(self, projparams=None, preserve_units=True, **kwargs): """ initialize a Proj class instance. See the proj documentation (https://github.com/OSGeo/proj.4/wiki) for more information about projection parameters. Parameters ---------- projparams: int, str, dict, pyproj.CRS A proj.4 or WKT string, proj.4 dict, EPSG integer, or a pyproj.CRS instnace. preserve_units: bool If false, will ensure +units=m. **kwargs: proj.4 projection parameters. Example usage: >>> from pyproj import Proj >>> p = Proj(proj='utm',zone=10,ellps='WGS84', preserve_units=False) # use kwargs >>> x,y = p(-120.108, 34.36116666) >>> 'x=%9.3f y=%11.3f' % (x,y) 'x=765975.641 y=3805993.134' >>> 'lon=%8.3f lat=%5.3f' % p(x,y,inverse=True) 'lon=-120.108 lat=34.361' >>> # do 3 cities at a time in a tuple (Fresno, LA, SF) >>> lons = (-119.72,-118.40,-122.38) >>> lats = (36.77, 33.93, 37.62 ) >>> x,y = p(lons, lats) >>> 'x: %9.3f %9.3f %9.3f' % x 'x: 792763.863 925321.537 554714.301' >>> 'y: %9.3f %9.3f %9.3f' % y 'y: 4074377.617 3763936.941 4163835.303' >>> lons, lats = p(x, y, inverse=True) # inverse transform >>> 'lons: %8.3f %8.3f %8.3f' % lons 'lons: -119.720 -118.400 -122.380' >>> 'lats: %8.3f %8.3f %8.3f' % lats 'lats: 36.770 33.930 37.620' >>> p2 = Proj('+proj=utm +zone=10 +ellps=WGS84', preserve_units=False) # use proj4 string >>> x,y = p2(-120.108, 34.36116666) >>> 'x=%9.3f y=%11.3f' % (x,y) 'x=765975.641 y=3805993.134' >>> p = Proj(init="epsg:32667", preserve_units=False) >>> 'x=%12.3f y=%12.3f (meters)' % p(-114.057222, 51.045) 'x=-1783506.250 y= 6193827.033 (meters)' >>> p = Proj("+init=epsg:32667") >>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045) 'x=-5851386.754 y=20320914.191 (feet)' >>> # test data with radian inputs >>> p1 = Proj(init="epsg:4214") >>> x1, y1 = p1(116.366, 39.867) >>> '{:.3f} {:.3f}'.format(x1, y1) '2.031 0.696' >>> x2, y2 = p1(x1, y1, inverse=True) >>> '{:.3f} {:.3f}'.format(x2, y2) '116.366 39.867' """ self.crs = CRS.from_user_input(projparams if projparams is not None else kwargs) # make sure units are meters if preserve_units is False. if not preserve_units and "foot" in self.crs.axis_info[0].unit_name: projstring = self.crs.to_proj4(4) projstring = re.sub(r"\s\+units=[\w-]+", "", projstring) projstring += " +units=m" self.crs = CRS(projstring) super(Proj, self).__init__( cstrencode( (self.crs.to_proj4() or self.crs.srs).replace("+type=crs", "").strip() ) )