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
Built Distribution
File details
Details for the file psycopg-postgis-0.1.3.tar.gz
.
File metadata
- Download URL: psycopg-postgis-0.1.3.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8956902dbfe8c72ffa7b72c5ec4d956c9f910661158d659f57ae45724f5ed024 |
|
MD5 | 534b72d6e3daba09ce17418c9a85420e |
|
BLAKE2b-256 | f98c43e6dc466bcc4758f68eeb05a9e8c7082cbb203c35ef8f752b5c450604eb |
File details
Details for the file psycopg_postgis-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: psycopg_postgis-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 098dbb19de1f25d1a37606a441d09653c2f02829050ac638fc3ed571a1e623e7 |
|
MD5 | e4d4b9f46f0598ad93d81f332349c0a3 |
|
BLAKE2b-256 | cff3f83c606e8d876c79f44b42070c5dcc0ece5bffe06c8db5160deded4aa9a8 |