{"id":18762633,"url":"https://github.com/rasterio/affine","last_synced_at":"2025-12-11T21:03:42.632Z","repository":{"id":17344178,"uuid":"20115554","full_name":"rasterio/affine","owner":"rasterio","description":"Affine transformation matrices","archived":false,"fork":false,"pushed_at":"2025-02-25T15:59:42.000Z","size":202,"stargazers_count":168,"open_issues_count":2,"forks_count":25,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-05-15T03:04:42.038Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://affine.readthedocs.io/en/latest/index.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rasterio.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.txt","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.txt","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2014-05-23T22:07:29.000Z","updated_at":"2025-04-21T20:46:04.000Z","dependencies_parsed_at":"2024-06-18T13:53:19.687Z","dependency_job_id":"e1855fb9-0532-41a6-8c2e-a8e6df419b3f","html_url":"https://github.com/rasterio/affine","commit_stats":{"total_commits":121,"total_committers":15,"mean_commits":8.066666666666666,"dds":0.7355371900826446,"last_synced_commit":"d790bdd6e2044bf76f7309cca6c63814f186e3e7"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rasterio%2Faffine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rasterio%2Faffine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rasterio%2Faffine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rasterio%2Faffine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rasterio","download_url":"https://codeload.github.com/rasterio/affine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264765,"owners_count":22041793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T18:22:28.948Z","updated_at":"2025-12-11T21:03:37.258Z","avatar_url":"https://github.com/rasterio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Affine\n======\n\nMatrices describing 2D affine transformation of the plane.\n\n.. image:: https://github.com/rasterio/affine/actions/workflows/ci.yml/badge.svg?branch=main\n    :target: https://github.com/rasterio/affine/actions/workflows/ci.yml\n\n.. image:: https://codecov.io/gh/rasterio/affine/branch/main/graph/badge.svg\n    :target: https://codecov.io/gh/rasterio/affine\n\n.. image:: https://readthedocs.org/projects/affine/badge/?version=latest\n       :target: https://affine.readthedocs.io/en/latest/?badge=latest\n       :alt: Documentation Status\n\nThe Affine package is derived from Casey Duncan's Planar package. Please see\nthe copyright statement in `src/affine.py \u003csrc/affine.py\u003e`__.\n\nUsage\n-----\n\nThe 3x3 augmented affine transformation matrix for transformations in two\ndimensions is illustrated below.\n\n::\n\n  | x' |   | a  b  c | | x |\n  | y' | = | d  e  f | | y |\n  | 1  |   | 0  0  1 | | 1 |\n\nMatrices can be created by passing the values ``a, b, c, d, e, f`` to the\n``affine.Affine`` constructor or by using its ``identity()``,\n``translation()``, ``scale()``, ``shear()``, and ``rotation()`` class methods.\n\n.. code-block:: pycon\n\n  \u003e\u003e\u003e from affine import Affine\n  \u003e\u003e\u003e Affine.identity()\n  Affine(1.0, 0.0, 0.0,\n         0.0, 1.0, 0.0)\n  \u003e\u003e\u003e Affine.translation(1.0, 5.0)\n  Affine(1.0, 0.0, 1.0,\n         0.0, 1.0, 5.0)\n  \u003e\u003e\u003e Affine.scale(2.0)\n  Affine(2.0, 0.0, 0.0,\n         0.0, 2.0, 0.0)\n  \u003e\u003e\u003e Affine.shear(45.0, 45.0)  # decimal degrees\n  Affine(1.0, 0.9999999999999999, 0.0,\n         0.9999999999999999, 1.0, 0.0)\n  \u003e\u003e\u003e Affine.rotation(45.0)     # decimal degrees\n  Affine(0.7071067811865476, -0.7071067811865475, 0.0,\n         0.7071067811865475, 0.7071067811865476, 0.0)\n\nThese matrices can be applied to ``(x, y)`` tuples using the\n``*`` operator (or the ``@`` matrix multiplier operator for\nfuture releases) to obtain transformed coordinates ``(x', y')``.\n\n.. code-block:: pycon\n\n  \u003e\u003e\u003e Affine.translation(1.0, 5.0) * (1.0, 1.0)\n  (2.0, 6.0)\n  \u003e\u003e\u003e Affine.rotation(45.0) * (1.0, 1.0)\n  (1.1102230246251565e-16, 1.414213562373095)\n\nThey may also be multiplied together to combine transformations.\n\n.. code-block:: pycon\n\n  \u003e\u003e\u003e Affine.translation(1.0, 5.0) * Affine.rotation(45.0)\n  Affine(0.7071067811865476, -0.7071067811865475, 1.0,\n         0.7071067811865475, 0.7071067811865476, 5.0)\n\nUsage with GIS data packages\n----------------------------\n\nGeoreferenced raster datasets use affine transformations to map from image\ncoordinates to world coordinates. The ``affine.Affine.from_gdal()`` class\nmethod helps convert `GDAL GeoTransform\n\u003chttps://gdal.org/user/raster_data_model.html#affine-geotransform\u003e`__,\nsequences of 6 numbers in which the first and fourth are the x and y offsets\nand the second and sixth are the x and y pixel sizes.\n\nUsing a GDAL dataset transformation matrix, the world coordinates ``(x, y)``\ncorresponding to the top left corner of the pixel 100 rows down from the\norigin can be easily computed.\n\n.. code-block:: pycon\n\n  \u003e\u003e\u003e geotransform = (-237481.5, 425.0, 0.0, 237536.4, 0.0, -425.0)\n  \u003e\u003e\u003e fwd = Affine.from_gdal(*geotransform)\n  \u003e\u003e\u003e col, row = 0, 100\n  \u003e\u003e\u003e fwd * (col, row)\n  (-237481.5, 195036.4)\n\nThe reverse transformation is obtained using the ``~`` inverse operator.\n\n.. code-block:: pycon\n\n  \u003e\u003e\u003e rev = ~fwd\n  \u003e\u003e\u003e rev * fwd * (col, row)\n  (0.0, 99.99999999999999)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frasterio%2Faffine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frasterio%2Faffine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frasterio%2Faffine/lists"}