### Install pyproj from GitHub with pip Source: https://pyproj4.github.io/pyproj/stable/_sources/installation.rst.txt Install the latest pyproj directly from the GitHub repository using pip. ```bash pip install git+https://github.com/pyproj4/pyproj.git ``` -------------------------------- ### Install pyproj from PyPI with --no-binary Source: https://pyproj4.github.io/pyproj/stable/_sources/installation.rst.txt Install pyproj from PyPI, forcing a source build with --no-binary. Requires Cython or pip>=10.0.1; may need administrative privileges or --user. ```bash pip install pyproj --no-binary pyproj ``` -------------------------------- ### Install pyproj in editable mode from cloned repo Source: https://pyproj4.github.io/pyproj/stable/_sources/installation.rst.txt Install pyproj in editable mode from a cloned repository for development. ```bash pip install -e . ``` -------------------------------- ### Example cf_grid_mapping output Source: https://pyproj4.github.io/pyproj/stable/build_crs_cf.html Example contents of the cf_grid_mapping dictionary returned by crs.to_cf() for EPSG:4326. ```python {'crs_wkt': 'GEOGCRS["WGS 84",DATUM["World Geodetic System ' ....,ID["EPSG",4326]]', 'geographic_crs_name': 'WGS 84', 'grid_mapping_name': 'latitude_longitude', 'inverse_flattening': 298.257223563, 'longitude_of_prime_meridian': 0.0, 'prime_meridian_name': 'Greenwich', 'reference_ellipsoid_name': 'WGS 84', 'semi_major_axis': 6378137.0, 'semi_minor_axis': 6356752.314245179} ``` -------------------------------- ### Example cf_coordinate_system output Source: https://pyproj4.github.io/pyproj/stable/build_crs_cf.html Example contents of the cf_coordinate_system list returned by crs.cs_to_cf() for EPSG:4326. ```python [{'long_name': 'geodetic latitude coordinate', 'standard_name': 'latitude', 'units': 'degrees_north', 'axis': 'Y'}, {'long_name': 'geodetic longitude coordinate', 'standard_name': 'longitude', 'units': 'degrees_east', 'axis': 'X'}] ``` -------------------------------- ### TransformerGroup example with EPSG:4326 to EPSG:2964 Source: https://pyproj4.github.io/pyproj/stable/advanced_examples.html Demonstrates using TransformerGroup to inspect available and unavailable transformations. The example shows the group's best_available status, the number of transformers, and how to access and use the first three transformers. It also shows how to check for missing grids and their download URLs. ```python >>> from pyproj.transformer import TransformerGroup >>> trans_group = TransformerGroup("EPSG:4326","EPSG:2964") >>> trans_group - transformers: 8 - unavailable_operations: 1 >>> trans_group.best_available True >>> trans_group.transformers[0].transform(66, -153) (149661.2825058747, 5849322.174897663) >>> trans_group.transformers[1].transform(66, -153) (149672.928811047, 5849311.372239139) >>> trans_group.transformers[2].transform(66, -153) (149748.32734832275, 5849274.621409136) ``` -------------------------------- ### Install nightly pyproj wheels Source: https://pyproj4.github.io/pyproj/stable/_sources/installation.rst.txt Installs nightly wheels of pyproj from the scientific-python-nightly-wheels anaconda channel. ```python python -m pip install pyproj --pre --extra-index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple ``` -------------------------------- ### Proj class usage examples Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/proj.html Examples of using the Proj class to transform coordinates between geographic and projected coordinate systems. Demonstrates forward and inverse transformations, handling of tuples, and different projection definitions. ```python >>> 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' ``` ```python >>> 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' ``` ```python >>> 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)' ``` ```python >>> p = Proj("EPSG:32667") >>> 'x=%12.3f y=%12.3f (feet)' % p(-114.057222, 51.045) 'x=-5851386.754 y=20320914.191 (feet)' ``` ```python >>> # test data with radian inputs >>> p1 = Proj("EPSG:4215") >>> 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' ``` -------------------------------- ### Install pyproj with pip Source: https://pyproj4.github.io/pyproj/stable/_sources/installation.rst.txt Installs pyproj from PyPI using pip. Requires pip 19.3+ for Linux manylinux2014 wheels. Note that pyproj 3+ wheels do not include transformation grids. ```bash python -m pip install pyproj ``` -------------------------------- ### Transform with Transformer.transform: CRS, pipeline, geocentric, and equivalent examples Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/transformer.html Shows the complete transform usage from the docstring example: converting EPSG:4326 to EPSG:3857, using a pipeline, geocentric CRS with always_xy, and an equivalent CRS (same EPSG). Demonstrates the default radians=False behavior and the formatted output strings. ```python >>> from pyproj import Transformer >>> transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857") >>> x3, y3 = transformer.transform(33, 98) >>> f"{x3:.3f} {y3:.3f}" '10909310.098 3895303.963' >>> pipeline_str = ( ... "+proj=pipeline +step +proj=longlat +ellps=WGS84 " ... "+step +proj=unitconvert +xy_in=rad +xy_out=deg" ... ) >>> pipe_trans = Transformer.from_pipeline(pipeline_str) >>> xt, yt = pipe_trans.transform(2.1, 0.001) >>> f"{xt:.3f} {yt:.3f}" '2.100 0.001' >>> transproj = Transformer.from_crs( ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, ... "EPSG:4326", ... always_xy=True, ... ) >>> xpj, ypj, zpj = transproj.transform( ... -2704026.010, ... -4253051.810, ... 3895878.820, ... radians=True, ... ) >>> f"{xpj:.3f} {ypj:.3f} {zpj:.3f}" '-2.137 0.661 -20.531' >>> transprojr = Transformer.from_crs( ... "EPSG:4326", ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, ... always_xy=True, ... ) >>> xpjr, ypjr, zpjr = transprojr.transform(xpj, ypj, zpj, radians=True) >>> f"{xpjr:.3f} {ypjr:.3f} {zpjr:.3f}" '-2704026.010 -4253051.810 3895878.820' >>> transformer = Transformer.from_crs("EPSG:4326", 4326) >>> xeq, yeq = transformer.transform(33, 98) >>> f"{xeq:.0f} {yeq:.0f}" '33 98' ``` -------------------------------- ### Example usage of pyproj.itransform with Proj objects Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/transformer.html Shows how to transform multiple points between two projections defined by EPSG codes using pyproj.itransform. The example uses always_xy=True to accept longitude/latitude order and prints the transformed coordinates. ```python >>> from pyproj import Proj, itransform >>> # projection 1: WGS84 >>> # (defined by epsg code 4326) >>> p1 = Proj('epsg:4326', preserve_units=False) >>> # projection 2: GGRS87 / Greek Grid >>> p2 = Proj('epsg:2100', preserve_units=False) >>> # Three points with coordinates lon, lat in p1 >>> points = [(22.95, 40.63), (22.81, 40.53), (23.51, 40.86)] >>> # transform this point to projection 2 coordinates. >>> for pt in itransform(p1,p2,points, always_xy=True): '%6.3f %7.3f' % pt '411050.470 4497928.574' '399060.236 4486978.710' '458553.243 4523045.485' ``` ```python >>> for pt in itransform(4326, 4326, [(30, 60)]): ... '{:.0f} {:.0f}'.format(*pt) '30 60' ``` -------------------------------- ### Get EPSG code with CRS.to_epsg() Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/crs/crs.html Shows how to get the EPSG code for a CRS using to_epsg(). The example uses CRS("EPSG:4328") and returns 4328. ```python >>> from pyproj import CRS >>> ccs = CRS("EPSG:4328") >>> ccs.to_epsg() 4328 ``` -------------------------------- ### Get authority with CRS.to_authority() Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/crs/crs.html Shows how to get the authority name and code for a CRS using to_authority(). The example uses CRS("EPSG:4328") and returns ('EPSG', '4328'). ```python >>> from pyproj import CRS >>> ccs = CRS("EPSG:4328") >>> ccs.to_authority() ('EPSG', '4328') ``` -------------------------------- ### Transformer.transform examples with from_crs and from_pipeline Source: https://pyproj4.github.io/pyproj/stable/api/proj.html Interactive Python session showing various Transformer usage: from_crs with EPSG codes, from_pipeline with a pipeline string, and from_crs with dict-based CRS definitions including always_xy and radians options. Demonstrates forward and reverse transforms with formatted output. ```python >>> from pyproj import Transformer >>> transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857") >>> x3, y3 = transformer.transform(33, 98) >>> f"{x3:.3f} {y3:.3f}" '10909310.098 3895303.963' >>> pipeline_str = ( ... "+proj=pipeline +step +proj=longlat +ellps=WGS84 " ... "+step +proj=unitconvert +xy_in=rad +xy_out=deg" ... ) >>> pipe_trans = Transformer.from_pipeline(pipeline_str) >>> xt, yt = pipe_trans.transform(2.1, 0.001) >>> f"{xt:.3f} {yt:.3f}" '2.100 0.001' >>> transproj = Transformer.from_crs( ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, ... "EPSG:4326", ... always_xy=True, ... ) >>> xpj, ypj, zpj = transproj.transform( ... -2704026.010, ... -4253051.810, ... 3895878.820, ... radians=True, ... ) >>> f"{xpj:.3f} {ypj:.3f} {zpj:.3f}" '-2.137 0.661 -20.531' >>> transprojr = Transformer.from_crs( ... "EPSG:4326", ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, ... always_xy=True, ... ) >>> xpjr, ypjr, zpjr = transprojr.transform(xpj, ypj, zpj, radians=True) >>> f"{xpjr:.3f} {ypjr:.3f} {zpjr:.3f}" '-2704026.010 -4253051.810 3895878.820' >>> transformer = Transformer.from_crs("EPSG:4326", 4326) >>> xeq, yeq = transformer.transform(33, 98) >>> f"{xeq:.0f} {yeq:.0f}" '33 98' ``` -------------------------------- ### Get authority from source CRS with to_authority() Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/crs/crs.html Shows how to get an authority from the source CRS when the CRS is bound. The example uses a geocentric CRS and shows that to_authority() returns None for the bound CRS, while source_crs.to_authority() returns ('EPSG', '4978'). Also shows that the bound CRS is not equal to CRS.from_authorty('EPSG', '4978'). ```python >>> from pyproj import CRS >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0") >>> ccs.to_authority() >>> ccs.source_crs.to_authority() ('EPSG', '4978') >>> ccs == CRS.from_authorty('EPSG', '4978') False ``` -------------------------------- ### Get EPSG code from source CRS with to_epsg() Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/crs/crs.html Shows how to get an EPSG code from the source CRS when the CRS is bound. The example uses a geocentric CRS and shows that to_epsg() returns None for the bound CRS, while source_crs.to_epsg() returns 4978. Also shows that the bound CRS is not equal to CRS.from_epsg(4978). ```python >>> from pyproj import CRS >>> ccs = CRS("+proj=geocent +datum=WGS84 +towgs84=0,0,0") >>> ccs.to_epsg() >>> ccs.source_crs.to_epsg() 4978 >>> ccs == CRS.from_epsg(4978) False ``` -------------------------------- ### Download PROJ grids with PROJ_DOWNLOAD_DIR and aws/wget Source: https://pyproj4.github.io/pyproj/stable/_sources/transformation_grids.rst.txt Sets the PROJ_DOWNLOAD_DIR environment variable to the user-writable or main PROJ data directory, then downloads the grid data using either AWS S3 sync or wget mirroring. Requires PROJ 7.1+ for the user-writable directory option. ```bash export PROJ_DOWNLOAD_DIR=$(python -c "import pyproj; print(pyproj.datadir.get_user_data_dir())") ``` ```bash export PROJ_DOWNLOAD_DIR=$(python -c "import pyproj; print(pyproj.datadir.get_data_dir())") ``` ```bash aws s3 sync s3://cdn.proj.org ${PROJ_DOWNLOAD_DIR} ``` ```bash wget --mirror https://cdn.proj.org/ -P ${PROJ_DOWNLOAD_DIR} ``` -------------------------------- ### Get projection definition string with Proj.definition_string() Source: https://pyproj4.github.io/pyproj/stable/api/proj.html Returns the formal PROJ definition string for a given projection. The example shows the output for EPSG:4326, which is 'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0'. ```python >>> Proj("EPSG:4326").definition_string() 'proj=longlat datum=WGS84 no_defs ellps=WGS84 towgs84=0,0,0' ``` -------------------------------- ### Modify CRS with coordinate system in US_Survey_Foot (cf_units) Source: https://pyproj4.github.io/pyproj/stable/_sources/build_crs_cf.rst.txt Shows CF variable definitions with units in US_Survey_Foot (incomplete, with ellipsis) and the required imports to handle unit conversion. When the CF coordinate system uses US_Survey_Foot, you need to get the unit conversion factor (e.g., via the cf-units library) before converting to a CRS. The variable definitions are the same as the previous example except for the units. ```text variables: double x(x) ; x:standard_name = "projection_x_coordinate" ; x:long_name = "Easting" ; x:units = "US_Survey_Foot" ; double y(y) ; y:standard_name = "projection_y_coordinate" ; y:long_name = "Northing" ; y:units = "US_Survey_Foot" ; ... ``` ```python from cf_units import Unit from pyproj import CRS ``` -------------------------------- ### Create and inspect a CRS with pyproj.crs.CRS Source: https://pyproj4.github.io/pyproj/stable/api/crs/crs.html Shows how to create a CRS from an EPSG code and from PROJ parameters, then inspect its properties (area of use, ellipsoid, prime meridian, datum, coordinate system, coordinate operation) and convert to WKT. The output includes the WKT representation and the computed geodetic parameters. ```python >>> from pyproj import CRS >>> crs_utm = CRS.from_user_input(26915) >>> crs_utm Name: NAD83 / UTM zone 15N Axis Info [cartesian]: - E[east]: Easting (metre) - N[north]: Northing (metre) Area of Use: - name: North America - 96°W to 90°W and NAD83 by country - bounds: (-96.0, 25.61, -90.0, 84.0) Coordinate Operation: - name: UTM zone 15N - method: Transverse Mercator Datum: North American Datum 1983 - Ellipsoid: GRS 1980 - Prime Meridian: Greenwich >>> crs_utm.area_of_use.bounds (-96.0, 25.61, -90.0, 84.0) >>> crs_utm.ellipsoid ELLIPSOID["GRS 1980",6378137,298.257222101, LENGTHUNIT["metre",1], ID["EPSG",7019]] >>> crs_utm.ellipsoid.inverse_flattening 298.257222101 >>> crs_utm.ellipsoid.semi_major_metre 6378137.0 >>> crs_utm.ellipsoid.semi_minor_metre 6356752.314140356 >>> crs_utm.prime_meridian PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8901]] >>> crs_utm.prime_meridian.unit_name 'degree' >>> crs_utm.prime_meridian.unit_conversion_factor 0.017453292519943295 >>> crs_utm.prime_meridian.longitude 0.0 >>> crs_utm.datum DATUM["North American Datum 1983", ELLIPSOID["GRS 1980",6378137,298.257222101, LENGTHUNIT["metre",1]], ID["EPSG",6269]] >>> crs_utm.coordinate_system CS[Cartesian,2], AXIS["(E)",east, ORDER[1], LENGTHUNIT["metre",1, ID["EPSG",9001]]], AXIS["(N)",north, ORDER[2], LENGTHUNIT["metre",1, ID["EPSG",9001]]] >>> print(crs_utm.coordinate_operation.to_wkt(pretty=True)) CONVERSION["UTM zone 15N", METHOD["Transverse Mercator", ID["EPSG",9807]], PARAMETER["Latitude of natural origin",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8801]], PARAMETER["Longitude of natural origin",-93, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8802]], PARAMETER["Scale factor at natural origin",0.9996, SCALEUNIT["unity",1], ID["EPSG",8805]], PARAMETER["False easting",500000, LENGTHUNIT["metre",1], ID["EPSG",8806]], PARAMETER["False northing",0, LENGTHUNIT["metre",1], ID["EPSG",8807]], ID["EPSG",16015]] >>> crs = CRS(proj='utm', zone=10, ellps='WGS84') >>> print(crs.to_wkt(pretty=True)) PROJCRS["unknown", BASEGEOGCRS["unknown", DATUM["Unknown based on WGS84 ellipsoid", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1], ID["EPSG",7030]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8901]]], CONVERSION["UTM zone 10N", METHOD["Transverse Mercator", ID["EPSG",9807]], PARAMETER["Latitude of natural origin",0, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8801]], PARAMETER["Longitude of natural origin",-123, ANGLEUNIT["degree",0.0174532925199433], ID["EPSG",8802]], PARAMETER["Scale factor at natural origin",0.9996, SCALEUNIT["unity",1], ID["EPSG",8805]], PARAMETER["False easting",500000, LENGTHUNIT["metre",1], ID["EPSG",8806]], PARAMETER["False northing",0, LENGTHUNIT["metre",1], ID["EPSG",8807]], ID["EPSG",16010]], CS[Cartesian,2], AXIS["(E)",east, ORDER[1], LENGTHUNIT["metre",1, ID["EPSG",9001]]], AXIS["(N)",north, ORDER[2], LENGTHUNIT["metre",1, ID["EPSG",9001]]]] >>> geod = crs.get_geod() >>> f"+a={geod.a:.0f} +f={geod.f:.8f}" '+a=6378137 +f=0.00335281' >>> crs.is_projected True >>> crs.is_geographic False ``` -------------------------------- ### Install pyproj with conda Source: https://pyproj4.github.io/pyproj/stable/_sources/installation.rst.txt Installs pyproj in a new conda environment using the conda-forge channel. Recommended to avoid using pip install inside a conda environment. ```bash conda config --prepend channels conda-forge conda config --set channel_priority strict conda create -n pyproj_env pyproj conda activate pyproj_env ``` -------------------------------- ### Geod ellipsoid initialization and inverse/forward azimuth computations Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/geod.html Shows how to initialize a Geod instance with the Clarke 1866 ellipsoid, compute forward/back azimuths and distances between cities, and verify results with formatted output. Also demonstrates the proj4-style initialization string '+ellps=clrk66' and passing lists of coordinates to g.inv(). ```doctest >>> from pyproj import Geod >>> g = Geod(ellps='clrk66') # Use Clarke 1866 ellipsoid. >>> # specify the lat/lons of some cities. >>> boston_lat = 42.+(15./60.); boston_lon = -71.-(7./60.) >>> portland_lat = 45.+(31./60.); portland_lon = -123.-(41./60.) >>> newyork_lat = 40.+(47./60.); newyork_lon = -73.-(58./60.) >>> london_lat = 51.+(32./60.); london_lon = -(5./60.) >>> # compute forward and back azimuths, plus distance >>> # between Boston and Portland. >>> az12,az21,dist = g.inv(boston_lon,boston_lat,portland_lon,portland_lat) >>> f"{az12:.3f} {az21:.3f} {dist:.3f}" '-66.531 75.654 4164192.708' >>> # compute latitude, longitude and back azimuth of Portland, >>> # given Boston lat/lon, forward azimuth and distance to Portland. >>> endlon, endlat, backaz = g.fwd(boston_lon, boston_lat, az12, dist) >>> f"{endlat:.3f} {endlon:.3f} {backaz:.3f}" '45.517 -123.683 75.654' >>> # compute the azimuths, distances from New York to several >>> # cities (pass a list) >>> lons1 = 3*[newyork_lon]; lats1 = 3*[newyork_lat] >>> lons2 = [boston_lon, portland_lon, london_lon] >>> lats2 = [boston_lat, portland_lat, london_lat] >>> az12,az21,dist = g.inv(lons1,lats1,lons2,lats2) >>> for faz, baz, d in list(zip(az12,az21,dist)): ... f"{faz:7.3f} {baz:8.3f} {d:12.3f}" ' 54.663 -123.448 288303.720' '-65.463 79.342 4013037.318' ' 51.254 -71.576 5579916.651' >>> g2 = Geod('+ellps=clrk66') # use proj4 style initialization string >>> az12,az21,dist = g2.inv(boston_lon,boston_lat,portland_lon,portland_lat) >>> f"{az12:.3f} {az21:.3f} {dist:.3f}" '-66.531 75.654 4164192.708' ``` -------------------------------- ### pyproj sync command usage Source: https://pyproj4.github.io/pyproj/stable/cli.html Shows the full command-line usage for the pyproj sync subcommand, which synchronizes PROJ datum and transformation support data. Options include --bbox, --spatial-test, --source-id, --area-of-use, --file, --exclude-world-coverage, --include-already-downloaded, --list-files, --all, --system-directory, --target-directory, and -v/--verbose. ```text pyproj sync [-h] [--bbox BBOX] [--spatial-test {intersects,contains}] [--source-id SOURCE_ID] [--area-of-use AREA_OF_USE] [--file FILE] [--exclude-world-coverage] [--include-already-downloaded] [--list-files] [--all] [--system-directory] [--target-directory TARGET_DIRECTORY] [-v] ``` -------------------------------- ### Initialize CRS from various inputs Source: https://pyproj4.github.io/pyproj/stable/_sources/examples.rst.txt Shows multiple ways to initialize a CRS object: from EPSG code, string, PROJ string, or user input. The last call demonstrates passing an integer directly. ```python >>> from pyproj import CRS >>> crs = CRS.from_epsg(4326) >>> crs = CRS.from_string("EPSG:4326") >>> crs = CRS.from_proj4("+proj=latlon") >>> crs = CRS.from_user_input(4326) ``` -------------------------------- ### Compare CRS initialized with init= vs direct EPSG Source: https://pyproj4.github.io/pyproj/stable/_sources/gotchas.rst.txt Shows that initializing a CRS with the deprecated 'init=' key (e.g., 'epsg:4544') produces a different object than using the direct authority string (e.g., 'EPSG:4544'), and they are not equal. ```python >>> from pyproj import CRS >>> crs_deprecated = CRS(init="epsg:4544") >>> crs = CRS("EPSG:4544") >>> crs == crs_deprecated False ``` -------------------------------- ### Install proj-data with conda Source: https://pyproj4.github.io/pyproj/stable/_sources/transformation_grids.rst.txt Installs the proj-data package from conda-forge, which includes transformation grids for PROJ 7+. ```bash conda install -c conda-forge proj-data ``` -------------------------------- ### GeographicCRS.__init__ Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/crs/crs.html Constructor for building a Geographic CRS. ```APIDOC ## GeographicCRS.__init__ ### Description Constructs a Geographic CRS with specified name, datum, and ellipsoidal coordinate system. ### Method - **__init__(name: str = "undefined", datum: Any = "urn:ogc:def:ensemble:EPSG::6326", ellipsoidal_cs: Any | None = None) -> None** ### Parameters - **name** (str, default="undefined") - Name of the CRS. - **datum** (Any, default="urn:ogc:def:ensemble:EPSG::6326") - Anything accepted by `pyproj.crs.Datum.from_user_input` or a `pyproj.crs.datum.CustomDatum`. - **ellipsoidal_cs** (Any, optional) - Input to create an Ellipsoidal Coordinate System. Anything accepted by `pyproj.crs.CoordinateSystem.from_user_input` or an Ellipsoidal Coordinate System created from `coordinate_system`. ``` -------------------------------- ### Run pyproj.show_versions() from command line Source: https://pyproj4.github.io/pyproj/stable/api/show_versions.html Use this command to print debugging information about the pyproj installation. The function was added in version 2.2.1. ```shell python -c "import pyproj; pyproj.show_versions()" ``` -------------------------------- ### Install proj-datumgrid packages with conda Source: https://pyproj4.github.io/pyproj/stable/_sources/transformation_grids.rst.txt Installs the proj-datumgrid packages for Europe, North America, Oceania, and world from conda-forge, for PROJ 6 and earlier. ```bash conda install -c conda-forge proj-datumgrid-europe proj-datumgrid-north-america proj-datumgrid-oceania proj-datumgrid-world ``` -------------------------------- ### Get projected CRS bounds with transform_bounds Source: https://pyproj4.github.io/pyproj/stable/_sources/advanced_examples.rst.txt Calculates the projected bounds of a CRS by transforming its area of use bounds from the geodetic CRS. This is the recommended method for getting projected bounds. ```python >>> from pyproj import CRS, Transformer >>> crs = CRS("EPSG:3857") >>> transformer = Transformer.from_crs(crs.geodetic_crs, crs, always_xy=True) >>> transformer.transform_bounds(*crs.area_of_use.bounds) (-20037508.342789244, -20048966.104014594, 20037508.342789244, 20048966.104014594) ``` -------------------------------- ### Proj.__init__ Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/proj.html Initializes a Proj instance with PROJ projection parameters. Accepts a PROJ string, dictionary, EPSG integer, or CRS object, along with keyword arguments for projection parameters. ```APIDOC ## Proj.__init__ ### Description Initializes a Proj instance for cartographic transformations. Converts between longitude/latitude and native map projection coordinates using PROJ. ### Method Constructor ### Signature ```python Proj(projparams: Any | None = None, preserve_units: bool = True, **kwargs) -> None ``` ### Parameters - **projparams** (int, str, dict, pyproj.CRS) - Optional - A PROJ or WKT string, PROJ dict, EPSG integer, or a pyproj.CRS instance. - **preserve_units** (bool) - Optional - If false, will ensure +units=m. - **\*\*kwargs** - PROJ projection parameters. ### Example Usage ```python # Example usage (from source) ``` ### Attributes - **srs** (str) - The string form of the user input used to create the Proj. - **crs** (pyproj.crs.CRS) - The CRS object associated with the Proj. ``` -------------------------------- ### Transformer.itransform() usage examples Source: https://pyproj4.github.io/pyproj/stable/_modules/pyproj/transformer.html Examples from the docstring of pyproj.transformer showing how to use Transformer.itransform() with different CRS definitions and options. The first example transforms a list of points from EPSG:4326 to EPSG:2100. The second uses a pipeline string. The third and fourth use a geocentric CRS dictionary with always_xy=True and radians=True. The fifth uses an equivalent CRS string with always_xy=True. ```python >>> from pyproj import Transformer >>> transformer = Transformer.from_crs(4326, 2100) >>> points = [(22.95, 40.63), (22.81, 40.53), (23.51, 40.86)] >>> for pt in transformer.itransform(points): '{:.3f} {:.3f}'.format(*pt) '2221638.801 2637034.372' '2212924.125 2619851.898' '2238294.779 2703763.736' ``` ```python >>> pipeline_str = ( ... "+proj=pipeline +step +proj=longlat +ellps=WGS84 " ... "+step +proj=unitconvert +xy_in=rad +xy_out=deg" ... ) >>> pipe_trans = Transformer.from_pipeline(pipeline_str) >>> for pt in pipe_trans.itransform([(2.1, 0.001)]): ... '{:.3f} {:.3f}'.format(*pt) '2.100 0.001' ``` ```python >>> transproj = Transformer.from_crs( ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, ... "EPSG:4326", ... always_xy=True, ... ) >>> for pt in transproj.itransform( ... [(-2704026.010, -4253051.810, 3895878.820)], ... radians=True, ... ): ... '{:.3f} {:.3f} {:.3f}'.format(*pt) '-2.137 0.661 -20.531' ``` ```python >>> transprojr = Transformer.from_crs( ... "EPSG:4326", ... {"proj":'geocent', "ellps":'WGS84', "datum":'WGS84'}, ... always_xy=True, ... ) >>> for pt in transprojr.itransform( ... [(-2.137, 0.661, -20.531)], ... radians=True ... ): ... '{:.3f} {:.3f} {:.3f}'.format(*pt) '-2704214.394 -4254414.478 3894270.731' ``` ```python >>> transproj_eq = Transformer.from_crs( ... 'EPSG:4326', ... '+proj=longlat +datum=WGS84 +no_defs +type=crs', ... always_xy=True, ... ) >>> for pt in transproj_eq.itransform([(-2.137, 0.661)]): ... '{:.3f} {:.3f}'.format(*pt) '-2.137 0.661' ``` -------------------------------- ### TransformerGroup with missing grid warning Source: https://pyproj4.github.io/pyproj/stable/advanced_examples.html Shows how to create a TransformerGroup with a custom CRS and handle a missing grid warning. The example demonstrates accessing the unavailable operations and their grid URLs, which is useful for checking if the best transformation is available and how to obtain missing grids. ```python >>> from pyproj.transformer import TransformerGroup >>> tg = TransformerGroup("EPSG:4326", "+proj=aea +lat_0=50 +lon_0=-154 +lat_1=55 +lat_2=65 +x_0=0 +y_0=0 +datum=NAD27 +no_defs +type=crs +units=m", always_xy=True) UserWarning: Best transformation is not available due to missing Grid(short_name=ntv2_0.gsb, full_name=, package_name=proj-datumgrid-north-america, url=https://download.osgeo.org/proj/proj-datumgrid-north-america-latest.zip, direct_download=True, open_license=True, available=False) f"{operation.grids[0]!r}" >>> tg - transformers: 37 - unavailable_operations: 41 >>> tg.transformers[0].description 'axis order change (2D) + Inverse of NAD27 to WGS 84 (3) + axis order change (2D) + unknown' >>> tg.unavailable_operations[0].name 'Inverse of NAD27 to WGS 84 (33) + axis order change (2D) + unknown' >>> tg.unavailable_operations[0].grids[0].url 'https://download.osgeo.org/proj/proj-datumgrid-north-america-latest.zip' ```