Skip to main content

Pyscopg and asyncpg helpers to work with PostGIS.

Project description

[![Circle CI](https://img.shields.io/circleci/project/yohanboniface/psycopg-postgis.svg)](https://circleci.com/gh/yohanboniface/psycopg-postgis) [![PyPI](https://img.shields.io/pypi/v/psycopg-postgis.svg)](https://pypi-hypernode.com/pypi/psycopg-postgis) [![PyPI](https://img.shields.io/pypi/pyversions/psycopg-postgis.svg)](https://pypi-hypernode.com/pypi/psycopg-postgis) [![PyPI](https://img.shields.io/pypi/implementation/psycopg-postgis.svg)](https://pypi-hypernode.com/pypi/psycopg-postgis) [![PyPI](https://img.shields.io/pypi/status/psycopg-postgis.svg)](https://pypi-hypernode.com/pypi/psycopg-postgis)

# python-postgis

PostGIS helpers for psycopg2 and asyncpg.

## Install

pip install postgis

If you want a compiled version, first install cython:

pip install cython pip install postgis

## Usage

You need to register the extension:

# With psycopg2 > from postgis.psycopg import register > register(connection)

# With asyncpg > from postgis.asyncpg import register > await register(connection)

Then you can pass python geometries instance to psycopg:

> cursor.execute(‘INSERT INTO table (geom) VALUES (%s)’, [Point(x=1, y=2, srid=4326)])

And retrieve data as python geometries instances:

> cursor.execute(‘SELECT geom FROM points LIMIT 1’) > geom = cursor.fetchone()[0] > geom <Point POINT(1.0 2.0)>

## Example

> import psycopg2 > from postgis import LineString > from postgis.psycopg import register > db = psycopg2.connect(dbname=”test”) > register(db) > cursor.execute(‘CREATE TABLE IF NOT EXISTS mytable (“geom” geometry(LineString) NOT NULL)’) > cursor.execute(‘INSERT INTO mytable (geom) VALUES (%s)’, [LineString([(1, 2), (3, 4)], srid=4326)]) > cursor.execute(‘SELECT geom FROM mytable LIMIT 1’) > geom = cursor.fetchone()[0] > geom <LineString LINESTRING(1.0 2.0, 3.0 4.0)> > geom[0] <Point POINT(1.0 2.0)> > geom.coords ((1.0, 2.0), (3.0, 4.0)) > geom.geojson {‘coordinates’: ((1.0, 2.0), (3.0, 4.0)), ‘type’: ‘LineString’} > str(geom.geojson) ‘{“type”: “LineString”, “coordinates”: [[1, 2], [3, 4]]}’

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

postgis-1.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

postgis-1.0.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file postgis-1.0.0.tar.gz.

File metadata

  • Download URL: postgis-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for postgis-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0d33299d6fd948872a46258e8ba0e97e6667c2570a8865d1658fde5080ddc907
MD5 955ca26f2ac3d367d62786a2c8296f34
BLAKE2b-256 8f85a4c39f5512ba088ece05b8053ae5746c1ac27955a3aebcefffb3684e4fa2

See more details on using hashes here.

File details

Details for the file postgis-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for postgis-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee9294cab6447c139e1276b503a9bfcd18df09a837df57e4de098f3282f0d0c9
MD5 ce122662f3d8a393e9ad2e2748c2ed86
BLAKE2b-256 5a2191f9c8bebd58bbd3ad8f21724b90c852c5ebb325b0f560b9358885cf6522

See more details on using hashes here.

Supported by

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