python画几何图_使用Python直接从PostGIS绘制几何图形

我尝试使用Python直接从PostGIS绘制shapefile。我的shapefile已经存储在PostgreSQL中。我知道如何将Python与PostgreSQL连接起来,但我找不到任何有助于我将数据绘制成地图的工具。我在某个地方读到应该连接到PostgreSQL,查询shapefile表,选择geom属性,将其存储到geodataframe中,然后绘制它。在

这是我使用的代码。有什么想法吗??在import psycopg2

import geopandas as gpd

import matplotlib.pyplot as plt

try:

conn = psycopg2.connect("dbname='strokes' user='postgres' host='localhost' password='admin'")

except:

print "I am unable to connect to the database"

cur = conn.cursor()

cur.execute("CREATE INDEX bassin_index ON bassin USING GIST(geom)")

cur.execute("SELECT st_astext(geom) AS wkt, fid_limite, codebassin FROM bassin")

rows = cur.fetchall()

rows_list=[]

for geom,fid_limite,codebassin in cursor:

data={'codebassin':codeb,'fid_limite':fidlim,'geom':geo}

rows_list.append(data)

gdf=gpd.GeoDataFrame(rows_list).set_index('codebassin')

gdf.head()

gdf.plot(column='fid_limite', scheme='QUANTILES', k=5, colormap='gray')

conn.commit()

conn.close()

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值