plpygis


Nameplpygis JSON
Version 0.4.1 PyPI version JSON
download
home_pageNone
SummaryPython tools for PostGIS
upload_time2024-04-30 06:22:17
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseGPL-3.0-only
keywords gis geospatial postgis postgresql pl/python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # plpygis

`plpygis` is a pure Python module with no dependencies that can convert geometries between [Well-known binary](https://en.wikipedia.org/wiki/Well-known_binary) (WKB), Extended Well-known Binary (EWKB) and GeoJSON representations. `plpygis` is mainly intended for use in PostgreSQL [PL/Python](https://www.postgresql.org/docs/current/plpython.html) functions to augment [PostGIS](https://postgis.net/)'s native capabilities.

## Basic usage

`plpygis` implements several subclasses of the `Geometry` class, such as `Point`, `LineString`, `MultiPolygon` and so on:

```python
>>> from plpygis import Point
>>> p = Point((-124.005, 49.005), srid=4326)
>>> print(p.wkb)
0101000020e6100000b81e85eb51005fc0713d0ad7a3804840
>>> print(p.geojson)
{'type': 'Point', 'coordinates': [-124.005, 49.005]}
```

## Usage with PostGIS

`plpygis` is designed to provide an easy way to implement PL/Python functions that accept `geometry` arguments or return `geometry` results. The following example will take a PostGIS `geometry(Point)` and use an external service to create a `geometry(PointZ)`.

``` postgres
CREATE OR REPLACE FUNCTION add_elevation(geom geometry(POINT))
  RETURNS geometry(POINTZ)
AS $$
  from plpygis import Geometry, Point
  from requests import get
  point = Geometry(geom)

  response = get(f'https://api.open-meteo.com/v1/elevation?longitude={point.x}&latitude={point.y}')
  if response.status_code == 200:
      content = response.json()
      point.z = content['elevation'][0]
      return point
  else:
      return None
$$ LANGUAGE plpython3u;
```

The `Geometry()` constructor will convert a PostGIS `geometry` that has been passed as a parameter to the PL/Python function into one of its `plpygis` subclasses. A `Geometry` that is returned from the PL/Python function will automatically be converted back to a PostGIS `geometry`.

The function above can be called as part of an SQL query:

``` postgres
SELECT name, ST_AsText(add_elevation(geom)) FROM city;
```

## Documentation

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

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "plpygis",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "gis, geospatial, postgis, postgresql, pl/python",
    "author": null,
    "author_email": "Benjamin Trigona-Harany <plpygis@jaxartes.net>",
    "download_url": "https://files.pythonhosted.org/packages/1e/d6/7cbbc8d0bd6f4344c7036229fbf283cd942194eb2bb743ecdb6a12a66321/plpygis-0.4.1.tar.gz",
    "platform": null,
    "description": "# plpygis\n\n`plpygis` is a pure Python module with no dependencies that can convert geometries between [Well-known binary](https://en.wikipedia.org/wiki/Well-known_binary) (WKB), Extended Well-known Binary (EWKB) and GeoJSON representations. `plpygis` is mainly intended for use in PostgreSQL [PL/Python](https://www.postgresql.org/docs/current/plpython.html) functions to augment [PostGIS](https://postgis.net/)'s native capabilities.\n\n## Basic usage\n\n`plpygis` implements several subclasses of the `Geometry` class, such as `Point`, `LineString`, `MultiPolygon` and so on:\n\n```python\n>>> from plpygis import Point\n>>> p = Point((-124.005, 49.005), srid=4326)\n>>> print(p.wkb)\n0101000020e6100000b81e85eb51005fc0713d0ad7a3804840\n>>> print(p.geojson)\n{'type': 'Point', 'coordinates': [-124.005, 49.005]}\n```\n\n## Usage with PostGIS\n\n`plpygis` is designed to provide an easy way to implement PL/Python functions that accept `geometry` arguments or return `geometry` results. The following example will take a PostGIS `geometry(Point)` and use an external service to create a `geometry(PointZ)`.\n\n``` postgres\nCREATE OR REPLACE FUNCTION add_elevation(geom geometry(POINT))\n  RETURNS geometry(POINTZ)\nAS $$\n  from plpygis import Geometry, Point\n  from requests import get\n  point = Geometry(geom)\n\n  response = get(f'https://api.open-meteo.com/v1/elevation?longitude={point.x}&latitude={point.y}')\n  if response.status_code == 200:\n      content = response.json()\n      point.z = content['elevation'][0]\n      return point\n  else:\n      return None\n$$ LANGUAGE plpython3u;\n```\n\nThe `Geometry()` constructor will convert a PostGIS `geometry` that has been passed as a parameter to the PL/Python function into one of its `plpygis` subclasses. A `Geometry` that is returned from the PL/Python function will automatically be converted back to a PostGIS `geometry`.\n\nThe function above can be called as part of an SQL query:\n\n``` postgres\nSELECT name, ST_AsText(add_elevation(geom)) FROM city;\n```\n\n## Documentation\n\nFull `plpygis` documentation is available at <http://plpygis.readthedocs.io/>.\n\n[![Continuous Integration](https://github.com/bosth/plpygis/workflows/tests/badge.svg)](https://github.com/bosth/plpygis/actions?query=workflow%3A%22tests%22) [![Documentation Status](https://readthedocs.org/projects/plpygis/badge/?version=latest)](http://plpygis.readthedocs.io/en/latest/?badge=latest)\n",
    "bugtrack_url": null,
    "license": "GPL-3.0-only",
    "summary": "Python tools for PostGIS",
    "version": "0.4.1",
    "project_urls": {
        "Documentation": "https://plpygis.readthedocs.io/",
        "Homepage": "https://github.com/bosth/plpygis",
        "Issues": "https://github.com/bosth/plpygis/issues"
    },
    "split_keywords": [
        "gis",
        " geospatial",
        " postgis",
        " postgresql",
        " pl/python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "144789af87fd932b6e3cfbfb2b75de64eaa46a1f5ac9745fe29a553eb045879c",
                "md5": "697cca82c449cb503fe64f366713ef8c",
                "sha256": "f3f7f7822a4cdf064d8cb1a727d4327e7d77f0002a9e9f57eee20ef94eca1adc"
            },
            "downloads": -1,
            "filename": "plpygis-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "697cca82c449cb503fe64f366713ef8c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 22681,
            "upload_time": "2024-04-30T06:22:16",
            "upload_time_iso_8601": "2024-04-30T06:22:16.065116Z",
            "url": "https://files.pythonhosted.org/packages/14/47/89af87fd932b6e3cfbfb2b75de64eaa46a1f5ac9745fe29a553eb045879c/plpygis-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1ed67cbbc8d0bd6f4344c7036229fbf283cd942194eb2bb743ecdb6a12a66321",
                "md5": "9cb19cda07c6c6469727ab2facb09475",
                "sha256": "9dfea7556a17f9ac0895882b294402d77275035782c1d2ed87f38272545200b8"
            },
            "downloads": -1,
            "filename": "plpygis-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9cb19cda07c6c6469727ab2facb09475",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 28268,
            "upload_time": "2024-04-30T06:22:17",
            "upload_time_iso_8601": "2024-04-30T06:22:17.604196Z",
            "url": "https://files.pythonhosted.org/packages/1e/d6/7cbbc8d0bd6f4344c7036229fbf283cd942194eb2bb743ecdb6a12a66321/plpygis-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-30 06:22:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bosth",
    "github_project": "plpygis",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "plpygis"
}
        
Elapsed time: 0.23436s