在aengus示例中使用ST_Azimuth函数会产生错误,因为您不能将两个generate_series用作单个函数的参数。如果在另一个子查询中使用ep
/ sp值,则不会有任何麻烦。
这是我的解决方案:
-- 3.- Create segments from points and calculate azimuth for each line.-- two calls of generate_series for a single function wont work (azimuth).select id, name, polygon_num, point_order as vertex, -- case when point_order = 1 then last_value(ST_Astext(ST_Makeline(sp,ep))) over (partition by id, polygon_num) else lag(ST_Astext(ST_Makeline(sp,ep)),1) over (partition by id, polygon_num order by point_order) end ||' - '||ST_Astext(ST_Makeline(sp,ep)) as lines, -- abs(abs( case when point_order = 1 then last_value(degrees(ST_Azimuth(sp,ep))) over (partition by id, polygon_num) else lag(degrees(ST_Azimuth(sp,ep)),1) over (partition by id, polygon_num order by point_order) end - degrees(ST_Azimuth(sp,ep))) -180 ) as angfrom (-- 2.- extract the endpoints for every 2-point line segment for each linestring -- Group polygons from multipolygon select id, name, coalesce(path[1],0) as polygon_num, generate_series(1, ST_Npoints(geom)-1) as point_order, ST_Pointn(geom, generate_series(1, ST_Npoints(geom)-1)) as sp, ST_Pointn(geom, generate_series(2, ST_Npoints(geom) )) as ep from ( -- 1.- Extract the individual linestrings and the Polygon number for later identification select id, name, (ST_Dump(ST_Boundary(the_geom))).geom as geom, (ST_Dump(ST_Boundary(the_geom))).path as path -- To identify the polygon from poly_and_multipoly ) as pointlist ) as segments;
我增加了一些复杂性,因为我想标识每个多边形以避免混合用于角度计算的线。
由于sqlfiddle没有对PostGIS的支持,我上传这个例子与一些辅助代码github上这里
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)