【发布时间】:2022-10-30 22:19:43
【问题描述】:
我有一个启用空间的 PostGIS 数据库。
engine = create_engine(f'postgresql://user:password@localhost:5432/{dbname}')
我有一个有效的 geopandas 数据框(即,如果我导出为 .shp 或 .gpkg,我可以毫无错误地加载到 GIS 应用程序中),其中包含一个名为“geometry”的几何列。我将这些数据写入数据库:
gdf.to_postgis('table_name', con=engine, if_exists='append', index_label='id')
如果我从该表中读取所有记录:
gpd.read_postgis('table_name', con=engine, geom_col='geometry')
我收到以下警告:
SAWarning: Did not recognize type 'geometry' of column 'geometry' pandas_sql.meta.reflect(only=[sql])
如果我尝试执行 postgresql 语句,例如:
gpd.read_postgis('SELECT DISTINCT(st_cnty_fips) FROM table_name', con=self.engine, geom_col='geometry')
我收到一个错误:
line 65, in _df_to_geodf
raise ValueError("Query missing geometry column '{}'".format(geom_col))
ValueError: Query missing geometry column 'geometry'
使用 PGAdmin4 我可以看到该列存在。我究竟做错了什么?
【问题讨论】: