SQL/POSTGIS 使用函数实现ST_Intersects
2016-05-08 21:28
585 查看
create or replace function ST_LineIntersects(x1 float, y1 float, x2 float, y2 float, x3 float, y3 float, x4 float, y4 float) returns boolean as $$ declare a1 float; a2 float; b1 float; b2 float; c1 float; c2 float; begin a1 = y2 - y1; b1 = x1 - x2; c1 = a1*x1 + b1*y1; a2 = y4 - y3; b2 = x3 - x4; c2 = a2*x3 + b2*y3; if (a1*x3 + b1*y3) = c1 and (a1*x4 + b1*y4) = c1 then begin if (min(x1,x2)<=min(x3,x4) and min(x3,x4)<=max(x1,x2)) or (min(x1,x2)>=min(x3,x4) and max(x3,x4)>=min(x1,x2)) then return true; else return false; end if; end; elsif ((a1*x3+b1*y3-c1)*(a1*x4+b1*y4-c1)<=0) and ((a2*x1+b2*y1-c2)*(a2*x2+b2*y2-c2)<=0) then return true; end if; return false; end; $$ language plpgsql;
算法思路,相交线段必然是一条线段的两点分在另一条线段的两侧,则另L1的两端点在L2的两侧,L2的两端点在L1的两侧,则相交成立。
相关文章推荐
- 转发:[MySQL] 实现树形的遍历(关于多级菜单栏以及多级上下部门的查询问题)
- mysql数据库表清空后id如何从1开始自增
- 可配置多级指标投票打分应用设计(3)
- 20150323--memcache-02
- 20150323--memcache-01
- oracle免安装客户端设置
- Redis HyperLogLog
- 清除SQL server2008 记住的用户名和密码
- mysql解压版安装教程
- sqlplus常用命令
- Oracle如何实现多个字段去重
- 数据库
- JdbcTemplate下访问Oracle数据库插入数据时返回序列增长的主键
- 一个简单的实现不同权限的用户登录后看到不同的菜单设计的数据库表清单
- 安装oracle和plsql时的一点感想
- 数据库设计三大范式
- mybatis在sqlserver中报类型转化的错误
- ssh导出数据库的数据到Excel表格
- Windows下MySQL安装、卸载、数据路径配置
- MySQL学习笔记-查看表,修改表,删除表