SQL判断经纬度在矩形内
1,将城市地图拆分等距拆分为矩形
数据结构如图:

2.查看高德JS API (点是否在多边形内)核心代码:
a=[114.069564,22.545774];
b=[
[114.067595,22.552082],
[114.077322,22.552082],
[114.077322,22.543099],
[114.067595,22.543099],
];
c=true lf: function(a, b, c) {
var d = a[0];
a = a[1];
var f = !1, g, h, k, l, m = b.length, n = 0;
for (l = m - 1; n < m; l = n,
n += 1) {
var p = !1;
g = b[n][0];
h = b[n][1];
k = b[l][0];
l = b[l][1];
if (g === d && h === a || k === d && l === a)
return c ? !0 : !1;
if (h < a === l >= a) {
g = (k - g) * (a - h) / (l - h) + g;
if (d === g)
return c ? !0 : !1;
p = d < g
}
p && (f = !f)
}
return f
}
3.将js代码解析为SQL (未考虑使用函数,因在其他平台上使用)
SELECT * FROM map_grid a
WHERE
(CASE
WHEN
(a.first_longitude = 114.069564 and a.first_latitude=22.545774) or
(a.second_longitude = 114.069564 and a.second_latitude=22.545774) or
(a.third_longitude = 114.069564 and a.third_latitude=22.545774) or
(a.fourth_longitude = 114.069564 and a.fourth_latitude=22.545774)
THEN TRUE WHEN (a.first_latitude<22.545774)=(a.fourth_latitude>=22.545774)
AND (a.fourth_longitude-a.first_longitude)*(22.545774-a.first_latitude)/(a.fourth_latitude-a.first_latitude)+ a.first_longitude = 114.069564
THEN TRUE WHEN (a.second_latitude<22.545774)=(a.first_latitude>=22.545774)
AND (a.first_longitude-a.second_longitude)*(22.545774-a.second_latitude)/(a.first_latitude-a.second_latitude)+ a.second_longitude = 114.069564
THEN TRUE WHEN (a.third_latitude<22.545774)=(a.second_latitude>=22.545774)
AND (a.second_longitude-a.third_longitude)*(22.545774-a.third_latitude)/(a.second_latitude-a.third_latitude)+ a.third_longitude = 114.069564
THEN TRUE WHEN (a.fourth_latitude<22.545774)=(a.third_latitude>=22.545774)
AND (a.third_longitude-a.fourth_longitude)*(22.545774-a.fourth_latitude)/(a.third_latitude-a.fourth_latitude)+ a.fourth_longitude = 114.069564
THEN TRUE WHEN(
(
CASE
WHEN (a.first_latitude<22.545774)=(a.fourth_latitude>=22.545774)
AND (a.fourth_longitude-a.first_longitude)*(22.545774-a.first_latitude)/(a.fourth_latitude-a.first_latitude)+ a.first_longitude > 114.069564
THEN 1
ELSE 0 END
)+(
CASE
WHEN (a.second_latitude<22.545774)=(a.first_latitude>=22.545774)
AND (a.first_longitude-a.second_longitude)*(22.545774-a.second_latitude)/(a.first_latitude-a.second_latitude)+ a.second_longitude > 114.069564
THEN 1
ELSE 0 END
)+(
CASE
WHEN (a.third_latitude<22.545774)=(a.second_latitude>=22.545774)
AND (a.second_longitude-a.third_longitude)*(22.545774-a.third_latitude)/(a.second_latitude-a.third_latitude)+ a.third_longitude > 114.069564
THEN 1
ELSE 0 END
)+(
CASE
WHEN (a.fourth_latitude<22.545774)=(a.third_latitude>=22.545774)
AND (a.third_longitude-a.fourth_longitude)*(22.545774-a.fourth_latitude)/(a.third_latitude-a.fourth_latitude)+ a.fourth_longitude > 114.069564
THEN 1
ELSE 0 END
)
) % 2=1
THEN TRUE ELSE FALSE
END
)
4.执行结果

SQL判断经纬度在矩形内的更多相关文章
- POJ 1410 Intersection(判断线段交和点在矩形内)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9996 Accepted: 2632 Desc ...
- R树判断点在多边形内-Java版本
1.什么是RTree 待补充 2.RTree java依赖 rtree的java开源版本在GitHub上:https://github.com/davidmoten/rtree 上面有详细的使用说明 ...
- lightOJ 1366 Pair of Touching Circles(统计矩形内相切圆对)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1366 题意:给出一个矩形,在内部画两个圆A和B使得AB都完全在矩形内且AB相切且AB的 ...
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- 判断点在多边形内算法的C++实现
目录 1. 算法思路 2. 具体实现 3. 改进空间 1. 算法思路 判断平面内点是否在多边形内有多种算法,其中射线法是其中比较好理解的一种,而且能够支持凹多边形的情况.该算法的思路很简单,就是从目标 ...
- canvas路径剪切和判断是否在路径内
1.剪切路径 clip() var ctx=mycanvas.getContext('2d'); ctx.beginPath(); // 建一个矩形路径 ctx.moveTo(20,10) ctx.l ...
- mybatis动态sql中的两个内置参数(_parameter和_databaseId)
mybatis动态sql中的两个内置参数(_parameter和_databaseId) <!-- mybatis动态sql的两个内置参数 不只是方法传递过来的参数可以被 ...
- 以log(n)的时间求矩形内的点
设想这么一个简单的问题,在一个平面上有n个点,给定一个矩形,问位于矩形内的点有哪些. 这个问题的简单思路非常简单,每次遍历所有点,看其是否在给定的矩形中.时间复杂度呢?单次查询的时间就是一次遍历的时间 ...
- POJ 1410--Intersection(判断线段和矩形相交)
Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16322 Accepted: 4213 Des ...
随机推荐
- hashCode之二--Java:重写equals()和hashCode()
以下内容总结自<Effective Java>. 1.何时需要重写equals() 当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念). 2.设计equals() [1]使用in ...
- nmp部署(Nginx Mariadb Php-fpm)
#主机:192.168.2.129(mini2) 既是php主机,也是数据库主机#yum install -y php php-fpm php-mysql mariadb-server[root@~ ...
- Java enum(枚举)使用详解之一
enum 的全称为 enumeration, 是 JDK 1.5 中引入的新特性,存放在 java.lang 包中. 下面是我在使用 enum 过程中的一些经验和总结,主要包括如下内容: 1. 原始 ...
- Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: Cannot open connection
Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceE ...
- [poj3250]单调栈 Bad Hair Day
解题关键:将每头牛看到的牛头数总和转化为每头牛被看到的次数,然后用单调栈求解,其实做这道题的目的只是熟悉下单调栈 此题为递减栈 #include<cstdio> #include<c ...
- C++中const型数据的小结
由于与对象又管的const型数据种类较多,形式又有些相似,往往难记,容易混淆,因此总结一下相关用法,具体用法可查看下方链接 C++中对象的常引用 C++中指向对象的常指针和指向常对象的指针 C++中的 ...
- 27.【转载】挖洞技巧:如何绕过URL限制
大家对URL任意跳转都肯定了解,也知道他的危害,这里我就不细说了,过~ 大家遇到的肯定都是很多基于这样的跳转格式:http://www.xxx.xxx/xxx?xxx=http://www.xxx.x ...
- 21. CTF综合靶机渗透(十四)
靶机说明: I created this machine to help others learn some basic CTF hacking strategies and some tools. ...
- hdu1061
#include <iostream>#include <cstdio>using namespace std;int mod_exp(int a, int b, int c) ...
- 定时处理组件---Quartz.net
1.认识任务调度 所谓任务调度,就是以将业务区块任务化(即抽象成每一个独立的任务,执行每个任务便完成某种业务的需求).比如,我们有一个订单系统,现在有这样的一个需求,就是需要在某一时间点去扫描数据库, ...