plpygis


Nameplpygis JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/bosth/plpygis
SummaryPostGIS Python tools
upload_time2023-03-11 10:05:23
maintainer
docs_urlNone
authorBenjamin Trigona-Harany
requires_python
licenseGNU GPLv3
keywords gis geospatial postgis postgresql plpython
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =======
plpygis
=======

``plpygis`` is a Python tool that can convert a `PostGIS <https://postgis.net/>`_ ``geometry`` into an equivalent WKB, EWKB, GeoJSON or Shapely geometry. ``plpygis`` is intended for use in PostgreSQL `PL/Python <https://www.postgresql.org/docs/current/plpython.html>`_ functions.

Basic usage
===========

The ``Geometry`` class and its subclasses can be used to convert to and from PostGIS geometries. The following example will take a PostGIS multipolygon geometry named ``geom`` and find its largest component polygon.

``Geometry()`` can convert a PostGIS ``geometry`` that has been passed as a parameter to a PL/Python function. A ``Geometry`` that is returned from the PL/Python function will automatically be converted back to a PostGIS ``geometry``.

.. code-block:: postgres
 
    CREATE OR REPLACE FUNCTION largest_poly(geom geometry)
      RETURNS geometry 
    AS $$
      from plpygis import Geometry
      polygons = Geometry(geom)
      if polygons.type == "Polygon":
          return polygons
      elif polygons.type == "MultiPolygon":
          largest = max(polygons.shapely, key=lambda polygon: polygon.area)
          return Geometry.from_shapely(largest)
      else:
          return None
    $$ LANGUAGE plpython3u;

This can then be called as part of an SQL query:

.. code-block:: postgres

    SELECT largest_poly(geom) FROM countries;

Documentation
=============

Full ``plpygis`` documentation is available at http://plpygis.readthedocs.io/.

.. image:: https://readthedocs.org/projects/plpygis/badge/?version=latest
    :target: http://plpygis.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status
    
.. image:: https://github.com/bosth/plpygis/workflows/tests/badge.svg
    :target: https://github.com/bosth/plpygis/actions?query=workflow%3A%22tests%22
    :alt: Continuous Integration

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/bosth/plpygis",
    "name": "plpygis",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "gis geospatial postgis postgresql plpython",
    "author": "Benjamin Trigona-Harany",
    "author_email": "bosth@alumni.sfu.ca",
    "download_url": "https://files.pythonhosted.org/packages/1d/88/d268adf8b7592d070679ee4f72061ae77c3c8368c97b8f220efd00dbb4ce/plpygis-0.2.1.tar.gz",
    "platform": "any",
    "description": "=======\nplpygis\n=======\n\n``plpygis`` is a Python tool that can convert a `PostGIS <https://postgis.net/>`_ ``geometry`` into an equivalent WKB, EWKB, GeoJSON or Shapely geometry. ``plpygis`` is intended for use in PostgreSQL `PL/Python <https://www.postgresql.org/docs/current/plpython.html>`_ functions.\n\nBasic usage\n===========\n\nThe ``Geometry`` class and its subclasses can be used to convert to and from PostGIS geometries. The following example will take a PostGIS multipolygon geometry named ``geom`` and find its largest component polygon.\n\n``Geometry()`` can convert a PostGIS ``geometry`` that has been passed as a parameter to a PL/Python function. A ``Geometry`` that is returned from the PL/Python function will automatically be converted back to a PostGIS ``geometry``.\n\n.. code-block:: postgres\n \n    CREATE OR REPLACE FUNCTION largest_poly(geom geometry)\n      RETURNS geometry \n    AS $$\n      from plpygis import Geometry\n      polygons = Geometry(geom)\n      if polygons.type == \"Polygon\":\n          return polygons\n      elif polygons.type == \"MultiPolygon\":\n          largest = max(polygons.shapely, key=lambda polygon: polygon.area)\n          return Geometry.from_shapely(largest)\n      else:\n          return None\n    $$ LANGUAGE plpython3u;\n\nThis can then be called as part of an SQL query:\n\n.. code-block:: postgres\n\n    SELECT largest_poly(geom) FROM countries;\n\nDocumentation\n=============\n\nFull ``plpygis`` documentation is available at http://plpygis.readthedocs.io/.\n\n.. image:: https://readthedocs.org/projects/plpygis/badge/?version=latest\n    :target: http://plpygis.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n    \n.. image:: https://github.com/bosth/plpygis/workflows/tests/badge.svg\n    :target: https://github.com/bosth/plpygis/actions?query=workflow%3A%22tests%22\n    :alt: Continuous Integration\n",
    "bugtrack_url": null,
    "license": "GNU GPLv3",
    "summary": "PostGIS Python tools",
    "version": "0.2.1",
    "split_keywords": [
        "gis",
        "geospatial",
        "postgis",
        "postgresql",
        "plpython"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "14626998f561ee8b06085e356d205839c4e15fc9139cc5d1af5fa20f679bbc43",
                "md5": "44ceed2505b20429a7cb155e2235eaff",
                "sha256": "d1504cc08a032aa6585914b84d1c714a91d07c2fc5bce278c122f9457d575f2d"
            },
            "downloads": -1,
            "filename": "plpygis-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "44ceed2505b20429a7cb155e2235eaff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21767,
            "upload_time": "2023-03-11T10:05:21",
            "upload_time_iso_8601": "2023-03-11T10:05:21.470895Z",
            "url": "https://files.pythonhosted.org/packages/14/62/6998f561ee8b06085e356d205839c4e15fc9139cc5d1af5fa20f679bbc43/plpygis-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1d88d268adf8b7592d070679ee4f72061ae77c3c8368c97b8f220efd00dbb4ce",
                "md5": "04a2516920eb954082604aa406985541",
                "sha256": "62b3ef9ee81293e4f8ca423066cea5940542521cd16c4a08852bf73305da33c8"
            },
            "downloads": -1,
            "filename": "plpygis-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "04a2516920eb954082604aa406985541",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 22471,
            "upload_time": "2023-03-11T10:05:23",
            "upload_time_iso_8601": "2023-03-11T10:05:23.670401Z",
            "url": "https://files.pythonhosted.org/packages/1d/88/d268adf8b7592d070679ee4f72061ae77c3c8368c97b8f220efd00dbb4ce/plpygis-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-11 10:05:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "bosth",
    "github_project": "plpygis",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "plpygis"
}
        
Elapsed time: 0.05823s