GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tilery/python-postgis: PostGIS helpers for psycopg2 and asyncpg

BranchesTags
Open more actions menu

Latest commit

 

History

38 Commits
38 Commits

Folders and files

NameName
Last commit message
Last commit date
postgis
postgis
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
MANIFEST.in
MANIFEST.in
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
circle.yml
circle.yml
 
 
pytest.ini
pytest.ini
 
 
setup.py
setup.py
 
 

Repository files navigation

Circle CI PyPI PyPI PyPI PyPI

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 with psycopg2

> import psycopg2
> from postgis import LineString
> from postgis.psycopg import register
> db = psycopg2.connect(dbname="test")
> register(db)
> cursor = db.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]]}'

Example with asyncpg

from postgis.asyncpg import register
pool = await create_pool(**DB_CONFIG, loop=loop, max_size=100,
                         init=register)

About

PostGIS helpers for psycopg2 and asyncpg

Topics

asyncpgpostgispsycopg2python

Resources

Readme
Activity
Custom properties

Stars

69 stars

Watchers

2 watching

Forks

10 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.