Geopandas PostGIS连接 [英] Geopandas PostGIS connection

查看:181
本文介绍了Geopandas PostGIS连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在python中使用Geopandas进行一些空间工作,对此感到非常满意-我目前正在尝试阅读PostGIS功能,但不太了解如何对数据库连接进行参数化,但是并没有做到这一点.在文档中似乎不太清楚:

I recently started using Geopandas in python for some of my spatial work and am very pleased with it - I'm currently trying to read in PostGIS features and don't quite understand how to parameterize the database connection, and it didn't seem clear in the documentation:

GeoDataFrame.from_postgis(sql, con, geom_col='geom', crs=None, index_col=None, 
    coerce_float=True, params=None)

这可能是一个非常简单的问题,我只想知道'con'中需要做些什么-我假设一个包含数据库连接信息的字符串?但是以什么格式?设置"sql"似乎很简单.非常感谢任何帮助-谢谢!

This is likely a very simple question, all I wanted to know is what needs to go in 'con' - I assume a string with database connection information? But in what format? Setting 'sql' seems straightforward. Any help greatly appreciated - thanks!

推荐答案

示例:

import geopandas as gpd

import psycopg2  # (if it is postgres/postgis)

con = psycopg2.connect(database="your database", user="user", password="password",
    host="your host")

sql = "select geom, x,y,z from your_table"

df = gpd.GeoDataFrame.from_postgis(sql, con, geom_col='geom' )

这篇关于Geopandas PostGIS连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆