Skip to main content

Pyscopg 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)

# psycopg-postgis

PostGIS helpers for psycopg2.

## Install

pip install psycopg-postgis

If you want a compiled version, first install cython:

pip install cython pip install psycopg-postgis

## Usage

You need to register the extension:

> import postgis > postgis.register(mydatabase.get_cursor())

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 register, LineString > db = psycopg2.connect(dbname=”test”) > cursor = db.cursor() > register(cursor) > 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

psycopg-postgis-0.1.2.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

psycopg_postgis-0.1.2-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file psycopg-postgis-0.1.2.tar.gz.

File metadata

File hashes

Hashes for psycopg-postgis-0.1.2.tar.gz
Algorithm Hash digest
SHA256 cd7c1e289f71d86805ccddd20437cfa6bf4086b3372bb688a6ebbf7980094313
MD5 09d9a867f44994d6562ea2db59fb4b0b
BLAKE2b-256 f8c2fc0bc7c4afbbf938af3985d0eb5f9ab2bd992b9df2d7a02b958ee4d36408

See more details on using hashes here.

File details

Details for the file psycopg_postgis-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for psycopg_postgis-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9018ad239c0e4ea6dbd2dacb911a887aa0d32e3c82b97ba4154ea848a7e4a6f8
MD5 7cedb4bd6fbdd2b6a54c52af04760710
BLAKE2b-256 a1e9b4d27311f191b7c7bd8b9ac59feb6f86b84c7493b105f423ddb13a2fee12

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