Pyscopg和asyncpg辅助工具,用于处理PostGIS。
项目描述
[](https://circleci.com/gh/yohanboniface/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis) [](https://pypi.python.org/pypi/psycopg-postgis)
# python-postgis
psycopg2和asyncpg的PostGIS辅助工具。
## 安装
pip install postgis
如果您想安装编译版本,请首先安装`cython`
pip install cython
pip install postgis
## 使用
您需要注册扩展
# 使用psycopg2
> from postgis.psycopg import register
> register(connection)
# 使用asyncpg
> from postgis.asyncpg import register
> await register(connection)
然后您可以将Python几何实例传递给psycopg
> cursor.execute('INSERT INTO table (geom) VALUES (%s)', [Point(x=1, y=2, srid=4326)])
并且可以以Python几何实例的形式检索数据
> cursor.execute('SELECT geom FROM points LIMIT 1')
> geom = cursor.fetchone()[0]
> geom
<Point POINT(1.0 2.0)>
## 使用psycopg2的示例
> 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]]}'
## 使用 asyncpg 的示例
from postgis.asyncpg import register
pool = await create_pool(**DB_CONFIG, loop=loop, max_size=100,
init=register)
# python-postgis
psycopg2和asyncpg的PostGIS辅助工具。
## 安装
pip install postgis
如果您想安装编译版本,请首先安装`cython`
pip install cython
pip install postgis
## 使用
您需要注册扩展
# 使用psycopg2
> from postgis.psycopg import register
> register(connection)
# 使用asyncpg
> from postgis.asyncpg import register
> await register(connection)
然后您可以将Python几何实例传递给psycopg
> cursor.execute('INSERT INTO table (geom) VALUES (%s)', [Point(x=1, y=2, srid=4326)])
并且可以以Python几何实例的形式检索数据
> cursor.execute('SELECT geom FROM points LIMIT 1')
> geom = cursor.fetchone()[0]
> geom
<Point POINT(1.0 2.0)>
## 使用psycopg2的示例
> 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]]}'
## 使用 asyncpg 的示例
from postgis.asyncpg import register
pool = await create_pool(**DB_CONFIG, loop=loop, max_size=100,
init=register)
项目详细信息
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分发
postgis-1.0.4.tar.gz (52.0 kB 查看散列)
构建分发
postgis-1.0.4-py3-none-any.whl (63.7 kB 查看散列)
关闭
postgis-1.0.4.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 3d41f087e249a2a8b6720931e6f8f22b7747801f250265a8b8ac5f9d48221e63 |
|
MD5 | 65032305681b451f3d1a41f143a6f66c |
|
BLAKE2b-256 | 93096edfb7bda8b6645de68c232709aaf11ac2a945ced37ebb69e513d9dc01e5 |
关闭
postgis-1.0.4-py3-none-any.whl 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 1dfa62d33c585d68a54bdd47c21bdcb9302f9cbb0ef5aec360e64d2c3e0e1a93 |
|
MD5 | 9dc9853d186ec83ebd975b641d058ac4 |
|
BLAKE2b-256 | fee1522b5e0f9c0edf8bf864ce80a060d7c3a87d88070bfb2640a70eb0b006b0 |