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

Project details


Release history Release notifications

This version
History Node

0.1.0

History Node

0.0.3

History Node

0.0.2

History Node

0.0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
plpygis-0.1.0.tar.gz (30.3 kB) Copy SHA256 hash SHA256 Source None Feb 14, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page