【问题标题】:Geopandas PostGIS connectionGeopandas PostGIS 连接
【发布时间】:2016-04-20 01:05:56
【问题描述】:

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

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

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

【问题讨论】:

标签: python postgis geopandas


【解决方案1】:

例子:

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' )

【讨论】:

  • psycopg2 特定于 postgres,sqlalchemy.create_engine() 是通用的,可以处理与大多数 DBMS 的连接
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-23
  • 1970-01-01
  • 2015-07-18
  • 1970-01-01
  • 1970-01-01
  • 2018-08-03
相关资源
最近更新 更多