UNKNOWN
Project description
[![Circle CI](https://circleci.com/gh/yohanboniface/psycopg-postgis.svg?style=svg)](https://circleci.com/gh/yohanboniface/psycopg-postgis)
# psycopg-postgis
PostGIS helpers for psycopg2.
## Install
Not pypi release yet:
pip install git+https://github.com/yohanboniface/psycopg-postgis
You can first install cython to have a compiled version:
pip install cython
## 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
File details
Details for the file psycopg-postgis-0.1.0.tar.gz
.
File metadata
- Download URL: psycopg-postgis-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf346166c46ddac1918ff032ca7ea98ee7f1e0a66d23e9b9eafd9798a54e434f |
|
MD5 | 3bb5de418933496b33eacff137f852f9 |
|
BLAKE2b-256 | 948ea03c195442722d574cc78d4cc831f99199c9abd97fc93555b4c505219930 |