affine


Nameaffine JSON
Version 2.4.0 PyPI version JSON
download
home_page
SummaryMatrices describing affine transformation of the plane
upload_time2023-01-19 23:44:30
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords affine transformation matrix
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Affine
======

Matrices describing 2D affine transformation of the plane.

.. image:: https://github.com/rasterio/affine/actions/workflows/ci.yml/badge.svg?branch=main
    :target: https://github.com/rasterio/affine/actions/workflows/ci.yml

.. image:: https://codecov.io/gh/rasterio/affine/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/rasterio/affine

The Affine package is derived from Casey Duncan's Planar package. Please see
the copyright statement in `affine/__init__.py <affine/__init__.py>`__.

Usage
-----

The 3x3 augmented affine transformation matrix for transformations in two
dimensions is illustrated below.

::

  | x' |   | a  b  c | | x |
  | y' | = | d  e  f | | y |
  | 1  |   | 0  0  1 | | 1 |

Matrices can be created by passing the values ``a, b, c, d, e, f`` to the
``affine.Affine`` constructor or by using its ``identity()``,
``translation()``, ``scale()``, ``shear()``, and ``rotation()`` class methods.

.. code-block:: pycon

  >>> from affine import Affine
  >>> Affine.identity()
  Affine(1.0, 0.0, 0.0,
         0.0, 1.0, 0.0)
  >>> Affine.translation(1.0, 5.0)
  Affine(1.0, 0.0, 1.0,
         0.0, 1.0, 5.0)
  >>> Affine.scale(2.0)
  Affine(2.0, 0.0, 0.0,
         0.0, 2.0, 0.0)
  >>> Affine.shear(45.0, 45.0)  # decimal degrees
  Affine(1.0, 0.9999999999999999, 0.0,
         0.9999999999999999, 1.0, 0.0)
  >>> Affine.rotation(45.0)     # decimal degrees
  Affine(0.7071067811865476, -0.7071067811865475, 0.0,
         0.7071067811865475, 0.7071067811865476, 0.0)

These matrices can be applied to ``(x, y)`` tuples to obtain transformed
coordinates ``(x', y')``.

.. code-block:: pycon

  >>> Affine.translation(1.0, 5.0) * (1.0, 1.0)
  (2.0, 6.0)
  >>> Affine.rotation(45.0) * (1.0, 1.0)
  (1.1102230246251565e-16, 1.414213562373095)

They may also be multiplied together to combine transformations.

.. code-block:: pycon

  >>> Affine.translation(1.0, 5.0) * Affine.rotation(45.0)
  Affine(0.7071067811865476, -0.7071067811865475, 1.0,
         0.7071067811865475, 0.7071067811865476, 5.0)

Usage with GIS data packages
----------------------------

Georeferenced raster datasets use affine transformations to map from image
coordinates to world coordinates. The ``affine.Affine.from_gdal()`` class
method helps convert `GDAL GeoTransform
<https://gdal.org/user/raster_data_model.html#affine-geotransform>`__,
sequences of 6 numbers in which the first and fourth are the x and y offsets
and the second and sixth are the x and y pixel sizes.

Using a GDAL dataset transformation matrix, the world coordinates ``(x, y)``
corresponding to the top left corner of the pixel 100 rows down from the
origin can be easily computed.

.. code-block:: pycon

  >>> geotransform = (-237481.5, 425.0, 0.0, 237536.4, 0.0, -425.0)
  >>> fwd = Affine.from_gdal(*geotransform)
  >>> col, row = 0, 100
  >>> fwd * (col, row)
  (-237481.5, 195036.4)

The reverse transformation is obtained using the ``~`` operator.

.. code-block:: pycon

  >>> rev = ~fwd
  >>> rev * fwd * (col, row)
  (0.0, 99.99999999999999)



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "affine",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "affine,transformation,matrix",
    "author": "",
    "author_email": "Sean Gillies <sean.gillies@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/69/98/d2f0bb06385069e799fc7d2870d9e078cfa0fa396dc8a2b81227d0da08b9/affine-2.4.0.tar.gz",
    "platform": null,
    "description": "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\nThe Affine package is derived from Casey Duncan's Planar package. Please see\nthe copyright statement in `affine/__init__.py <affine/__init__.py>`__.\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  >>> from affine import Affine\n  >>> Affine.identity()\n  Affine(1.0, 0.0, 0.0,\n         0.0, 1.0, 0.0)\n  >>> Affine.translation(1.0, 5.0)\n  Affine(1.0, 0.0, 1.0,\n         0.0, 1.0, 5.0)\n  >>> Affine.scale(2.0)\n  Affine(2.0, 0.0, 0.0,\n         0.0, 2.0, 0.0)\n  >>> Affine.shear(45.0, 45.0)  # decimal degrees\n  Affine(1.0, 0.9999999999999999, 0.0,\n         0.9999999999999999, 1.0, 0.0)\n  >>> 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 to obtain transformed\ncoordinates ``(x', y')``.\n\n.. code-block:: pycon\n\n  >>> Affine.translation(1.0, 5.0) * (1.0, 1.0)\n  (2.0, 6.0)\n  >>> 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  >>> 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<https://gdal.org/user/raster_data_model.html#affine-geotransform>`__,\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  >>> geotransform = (-237481.5, 425.0, 0.0, 237536.4, 0.0, -425.0)\n  >>> fwd = Affine.from_gdal(*geotransform)\n  >>> col, row = 0, 100\n  >>> fwd * (col, row)\n  (-237481.5, 195036.4)\n\nThe reverse transformation is obtained using the ``~`` operator.\n\n.. code-block:: pycon\n\n  >>> rev = ~fwd\n  >>> rev * fwd * (col, row)\n  (0.0, 99.99999999999999)\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Matrices describing affine transformation of the plane",
    "version": "2.4.0",
    "split_keywords": [
        "affine",
        "transformation",
        "matrix"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0bf785273299ab57117850cc0a936c64151171fac4da49bc6fba0dad984a7c5f",
                "md5": "8626f021f29631950dfad7b4c6435fc4",
                "sha256": "8a3df80e2b2378aef598a83c1392efd47967afec4242021a0b06b4c7cbc61a92"
            },
            "downloads": -1,
            "filename": "affine-2.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8626f021f29631950dfad7b4c6435fc4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 15662,
            "upload_time": "2023-01-19T23:44:28",
            "upload_time_iso_8601": "2023-01-19T23:44:28.833863Z",
            "url": "https://files.pythonhosted.org/packages/0b/f7/85273299ab57117850cc0a936c64151171fac4da49bc6fba0dad984a7c5f/affine-2.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6998d2f0bb06385069e799fc7d2870d9e078cfa0fa396dc8a2b81227d0da08b9",
                "md5": "bc92555b48556f7439664cec13cf31f8",
                "sha256": "a24d818d6a836c131976d22f8c27b8d3ca32d0af64c1d8d29deb7bafa4da1eea"
            },
            "downloads": -1,
            "filename": "affine-2.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "bc92555b48556f7439664cec13cf31f8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 17132,
            "upload_time": "2023-01-19T23:44:30",
            "upload_time_iso_8601": "2023-01-19T23:44:30.696009Z",
            "url": "https://files.pythonhosted.org/packages/69/98/d2f0bb06385069e799fc7d2870d9e078cfa0fa396dc8a2b81227d0da08b9/affine-2.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-19 23:44:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "affine"
}
        
Elapsed time: 0.03027s