You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用gv.Path或hvplot(geo=True)绘制PostGIS线串提示缺失经纬度维度

问题解决方案

报错原因

  • SQL查询将坐标转换结果用Geography()包裹返回为PostGIS地理类型,GeoPandas读取该列后虽能识别为LineString对象,但未正确关联EPSG:4326的坐标系属性
  • 开启geo=True时hvplot默认会先校验点要素必备的经纬度维度,你使用的是LineString线要素,需要明确指定绘图类型为路径,避免hvplot按点要素逻辑校验字段

解决步骤

1. 修正SQL查询

去掉Geography()包裹,直接返回Geometry类型的4326坐标结果:

sqla="Select ST_transform(traja,4326) as traja, namea,nameb,mmsia,mmsib,p_dist,cpa_id from filtered where nm_a is not null and geometrytype(traja)='LINESTRING' limit 10"

2. 读取后确认坐标系

读取数据后明确指定GeoDataFrame的坐标系属性:

gdf = gpd.read_postgis(sqla, con, geom_col='traja')
gdf.crs = "EPSG:4326"

3. 调整可视化调用参数

明确指定kind='paths'声明绘制线要素,同时指定geometry列:

gdf.hvplot(geo=True, kind='paths', geometry='traja')

如果使用gv.Path直接绘制,写法如下:

import geoviews as gv
gv.Path(gdf, crs=4326)

内容的提问来源于stack exchange,提问作者Alan Suc

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 09:30:01