Skip to main content

PostGIS Python tools

Project description

plpygis is a Python conveter to and from the PostGIS geometry type, WKT, EWKT, WKB, EWKB, GeoJSON and Shapely geometries, or using __geo_interface__. plpygis is intended for use in PL/Python functions.

Basic usage

The Geometry class 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 direclty 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;

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.0.1.tar.gz (24.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: plpygis-0.0.1.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for plpygis-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ae4ed356cf6f4e05167b03836160fe12529717a96eaa0c8d0d98dd8b77079ab8
MD5 889c4c81783741577c6deb54aff193c8
BLAKE2b-256 ca7d5f5261a5aedda657af14af771120f60b620dbd555e9ad3e2fc3428112061

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