{"id":15019648,"url":"https://github.com/bosth/plpygis","last_synced_at":"2025-10-24T14:31:33.040Z","repository":{"id":57453658,"uuid":"98851200","full_name":"bosth/plpygis","owner":"bosth","description":"PL/Python for PostGIS","archived":false,"fork":false,"pushed_at":"2024-04-30T06:20:55.000Z","size":140,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-30T01:06:00.226Z","etag":null,"topics":["geospatial","plpython","postgresql"],"latest_commit_sha":null,"homepage":"https://vimeo.com/248099711","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bosth.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-31T05:28:15.000Z","updated_at":"2024-07-21T08:20:10.856Z","dependencies_parsed_at":"2024-03-12T20:48:13.351Z","dependency_job_id":"e2e7339d-1284-464c-847d-6c070b461b47","html_url":"https://github.com/bosth/plpygis","commit_stats":{"total_commits":45,"total_committers":6,"mean_commits":7.5,"dds":0.4222222222222223,"last_synced_commit":"9b2cb32b84491a386a732e2ee11adef8185c3622"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bosth%2Fplpygis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bosth%2Fplpygis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bosth%2Fplpygis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bosth%2Fplpygis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bosth","download_url":"https://codeload.github.com/bosth/plpygis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237982399,"owners_count":19397252,"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":["geospatial","plpython","postgresql"],"created_at":"2024-09-24T19:53:50.379Z","updated_at":"2025-10-24T14:31:23.645Z","avatar_url":"https://github.com/bosth.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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/EWKB), [Well-known Text](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry) (WKT/EWKT) 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\u003e\u003e\u003e from plpygis import Point\n\u003e\u003e\u003e p = Point((-124.005, 49.005), srid=4326)\n\u003e\u003e\u003e print(p.ewkb)\n0101000020e6100000b81e85eb51005fc0713d0ad7a3804840\n\u003e\u003e\u003e print(p.geojson)\n{'type': 'Point', 'coordinates': [-124.005, 49.005]}\n\u003e\u003e\u003e p.z = 1\n\u003e\u003e\u003e print(p.wkt)\nPOINT Z (-124.005 49.005 1)\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```pgsql\nCREATE OR REPLACE FUNCTION add_elevation(geom geometry(POINT))\n  RETURNS geometry(POINTZ)\nAS $$\n  from plpygis import Geometry\n  from requests import get\n  p = Geometry(geom)\n\n  response = get(f'https://api.open-meteo.com/v1/elevation?longitude={p.x}\u0026latitude={p.y}')\n  if response.status_code == 200:\n      content = response.json()\n      p.z = content['elevation'][0]\n      return p\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```pgsql\nSELECT\n    name,\n    add_elevation(geom)\nFROM\n    city;\n```\n\n## Documentation\n\nFull `plpygis` documentation is available at \u003chttp://plpygis.readthedocs.io/\u003e.\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbosth%2Fplpygis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbosth%2Fplpygis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbosth%2Fplpygis/lists"}