Skip to main content

PostGIS Python tools

Project description

plpygis is a Python conveter to and from the PostGIS geometry type, WKB, EWKB, GeoJSON and Shapely geometries and additionally supports __geo_interface__. plpygis is intended for use in PL/Python 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 Postigs 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.

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 plpythonu;

Documentation

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

Documentation Status Continuous Integration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plpygis-0.2.0.tar.gz (45.2 kB view details)

Uploaded Source

File details

Details for the file plpygis-0.2.0.tar.gz.

File metadata

  • Download URL: plpygis-0.2.0.tar.gz
  • Upload date:
  • Size: 45.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.36.1 CPython/3.8.1

File hashes

Hashes for plpygis-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f9d1bb3913970b6c40c67188be3716f9fa490c1441e6c0d915221c8291826079
MD5 e4d5c086548ce18edf80faf538192e36
BLAKE2b-256 8514ec826b1c0409e9342405a210a14ca4cfdbd014fadfd865dc33c960ff81c4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page