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 ...
随机推荐
- 问题5:如何快速找到多个字典中的公共键(key)
方法一:for in循环 from random import randint, sample a1 = {k; randint(1, 4) for k in 'abcdefg'} a2 = {k; ...
- 事务之五:Spring @Transactional工作原理
本文将深入研究Spring的事务管理.主要介绍@Transactional在底层是如何工作的. JPA(Java Persistence API--java持久层)和事务管理 很重要的一点是JPA本身 ...
- Nmon工具的使用以及通过nmon_analyse生成分析报表
在我们监控我们的操作系统的时候如果可以把各个硬件的监控信息生成形象化的分析报表图对于我们来说是件太好的事情了,而通过ibm的nom和nmon_analyser两者的结合完全可以实现我们的要求.首先对n ...
- python version 2.7 required,which was not found in
python version 2.7 required,which was not found in 出现上面这种情况的原因我推测有两种: 1.NumPy和SciPy官方网站上只提供了32bit的文件 ...
- 使用CocoaLumberjack时,自定义的log文件名
CocoaLumberjack是一个功能丰富的第三方日志系统.其生成的log文件,默认是自动命名的,如果需要自定义文件名,重载两个函数即可. // Log.h#import "CocoaLu ...
- 机器学习--近邻成分分析(NCA)算法 和 度量学习
1.近邻成分分析(NCA)算法 以上内容转载自:http://blog.csdn.net/chlele0105/article/details/13006443 2.度量学习 在机器学习中,对高维数据 ...
- java知识点积累(二)
4.条件运算符(三元运算符): String type = score<60?"不及格":"及格"; int i = (string=="hel ...
- hdu1521(字典树模板)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意: 中文题诶~ 思路: 字典树模板 代码1: 动态内存, 比较好理解一点, 不过速度略慢, ...
- 洛谷P1378 油滴扩展
P1378 油滴扩展 题目描述 在一个长方形框子里,最多有N(0≤N≤6)个相异的点,在其中任何一个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界.必须等一个油滴扩展完 ...
- springboot jpa mongodb 多条件分页查询
public Page<Recorded> getRecordeds(Integer page, Integer size, Recorded recorded) { if (page&l ...