如何通过坐标与方位角在PostGIS中创建扇形(Pie Wedge)?
PostGIS自定义扇形生成函数(蜂窝网络拓扑可视化)
找不到合适的现成方案,于是我在PostGIS中编写了一个返回geometry类型多边形的自定义函数,可用于在地图上可视化蜂窝网络拓扑。
函数参数说明
- lon:经度(float类型)
- lat:纬度(float类型)
- azimuth:方位角(float类型)
- distance:扇形长度(integer类型)
- width:扇形宽度(integer类型)
函数代码
create or replace function sector_3(lon float, lat float, azimuth float, distance integer, width integer) returns geometry language plpgsql as $$ declare sector geometry; begin sector = ST_MakePolygon(ST_MakeLine(ARRAY[ST_SetSRID(ST_MakePoint(lon,lat),4326), ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth-(width/2))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth-(width/2-1*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth-(width/2-2*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth-(width/2-3*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth-(width/2-4*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth)/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth+(width/2-4*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth+(width/2-3*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth+(width/2-2*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth+(width/2-1*(width/2/5)))/180.0)::geometry, ST_Project(ST_SetSRID(ST_MakePoint(lon,lat),4326)::geography, distance, pi()*(azimuth+(width/2))/180.0)::geometry, ST_SetSRID(ST_MakePoint(lon,lat),4326) ])); return sector; end; $$;
效果说明
执行该函数后,会生成一个以指定经纬度点(lon, lat)为起点,具备指定长度与宽度的扇形。

内容的提问来源于stack exchange,提问作者Nikita Andronnikov
相关产品推荐
相关产品推荐

