RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
如何判断目标点是否在指定地图版块上

这篇文章主要讲解了“如何判断目标点是否在指定地图版块上”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“如何判断目标点是否在指定地图版块上”吧!

创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于成都网站制作、做网站、白银网络推广、成都微信小程序、白银网络营销、白银企业策划、白银品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联建站为所有大学生创业者提供白银建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com

场景

最近工作中,遇到一个渲染热力图的场景。在最终的技术选型中,前端使用ECharts,后台只需要提供点的经纬度坐标即可。但是中期开发过程中存在个问题,由于数据量有限,后台能够获取的原始数据只有各个省份的几个市坐标点,这样前端在渲染的时候,就无法做出如图的效果。

如何判断目标点是否在指定地图版块上

于是后台需要模拟坐标点的分布,根据已有的坐标点进行指定范围、指定数量级的随机扩散。每一个随机点需要确保在边境线内和陆地上。

于是场景演化成了另一个几何问题——怎么判断目标点在指定平面上

射线法:若从一点发出的射线穿越过平面内多边形的点的个数为偶数,则点在多边形外,若为奇数,则点在多边形内。

在Java 的 java.awt.geom包下,有一个关于几何平面的类 GeneralPath。GeneralPath类中contains()方法,当目标点在 GeneralPath 几何平面内,则返回true,否则返回false。

于是根据国内版图分布,把地图版块分成 Mainland、TaiWan、HaiNan、ChongMing四个不规则几何平面。只需要根据每个平面的边界点画出对应平面图,进行目标点判断即可。

实现

package com.tcwong.pattern.Test;

import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;

/**
 * Description
 *
 * [@author](https://my.oschina.net/arthor) tcwong
 * [@date](https://my.oschina.net/u/2504391) 2020/11/29
 * Since 1.8
 */
public class PolygonUtil {

	//定义地图版图
	private static GeneralPath generalPathMainland, generalPathTaiWan, generalPathHaiNan, generalPathChongMing;

	//初始化Mainland边界点
	private static List polygonMainland = new ArrayList() {{
		add(new Point2D.Double(27.32083, 88.91693));
		add(new Point2D.Double(27.54243, 88.76464));
		add(new Point2D.Double(28.00805, 88.83575));
		add(new Point2D.Double(28.1168, 88.62435));
		add(new Point2D.Double(27.86605, 88.14279));
		add(new Point2D.Double(27.82305, 87.19275));
		add(new Point2D.Double(28.11166, 86.69527));
		add(new Point2D.Double(27.90888, 86.45137));
		add(new Point2D.Double(28.15805, 86.19769));
		add(new Point2D.Double(27.88625, 86.0054));
		add(new Point2D.Double(28.27916, 85.72137));
		add(new Point2D.Double(28.30666, 85.11095));
		add(new Point2D.Double(28.59104, 85.19518));
		add(new Point2D.Double(28.54444, 84.84665));
		add(new Point2D.Double(28.73402, 84.48623));
		add(new Point2D.Double(29.26097, 84.11651));
		add(new Point2D.Double(29.18902, 83.5479));
		add(new Point2D.Double(29.63166, 83.19109));
		add(new Point2D.Double(30.06923, 82.17525));
		add(new Point2D.Double(30.33444, 82.11123));
		add(new Point2D.Double(30.385, 81.42623));
		add(new Point2D.Double(30.01194, 81.23221));
		add(new Point2D.Double(30.20435, 81.02536));
		add(new Point2D.Double(30.57552, 80.207));
		add(new Point2D.Double(30.73374, 80.25423));
		add(new Point2D.Double(30.96583, 79.86304));
		add(new Point2D.Double(30.95708, 79.55429));
		add(new Point2D.Double(31.43729, 79.08082));
		add(new Point2D.Double(31.30895, 78.76825));
		add(new Point2D.Double(31.96847, 78.77075));
		add(new Point2D.Double(32.24304, 78.47594));
		add(new Point2D.Double(32.5561, 78.40595));
		add(new Point2D.Double(32.63902, 78.74623));
		add(new Point2D.Double(32.35083, 78.9711));
		add(new Point2D.Double(32.75666, 79.52874));
		add(new Point2D.Double(33.09944, 79.37511));
		add(new Point2D.Double(33.42863, 78.93623));
		add(new Point2D.Double(33.52041, 78.81387));
		add(new Point2D.Double(34.06833, 78.73581));
		add(new Point2D.Double(34.35001, 78.98535));
		add(new Point2D.Double(34.6118, 78.33707));
		add(new Point2D.Double(35.28069, 78.02305));
		add(new Point2D.Double(35.49902, 78.0718));
		add(new Point2D.Double(35.50133, 77.82393));
		add(new Point2D.Double(35.6125, 76.89526));
		add(new Point2D.Double(35.90665, 76.55304));
		add(new Point2D.Double(35.81458, 76.18061));
		add(new Point2D.Double(36.07082, 75.92887));
		add(new Point2D.Double(36.23751, 76.04166));
		add(new Point2D.Double(36.66343, 75.85984));
		add(new Point2D.Double(36.73169, 75.45179));
		add(new Point2D.Double(36.91156, 75.39902));
		add(new Point2D.Double(36.99719, 75.14787));
		add(new Point2D.Double(37.02782, 74.56543));
		add(new Point2D.Double(37.17, 74.39089));
		add(new Point2D.Double(37.23733, 74.91574));
		add(new Point2D.Double(37.40659, 75.18748));
		add(new Point2D.Double(37.65243, 74.9036));
		add(new Point2D.Double(38.47256, 74.85442));
		add(new Point2D.Double(38.67438, 74.35471));
		add(new Point2D.Double(38.61271, 73.81401));
		add(new Point2D.Double(38.88653, 73.70818));
		add(new Point2D.Double(38.97256, 73.85235));
		add(new Point2D.Double(39.23569, 73.62005));
		add(new Point2D.Double(39.45483, 73.65569));
		add(new Point2D.Double(39.59965, 73.95471));
		add(new Point2D.Double(39.76896, 73.8429));
		add(new Point2D.Double(40.04202, 73.99096));
		add(new Point2D.Double(40.32792, 74.88089));
		add(new Point2D.Double(40.51723, 74.8588));
		add(new Point2D.Double(40.45042, 75.23394));
		add(new Point2D.Double(40.64452, 75.58284));
		add(new Point2D.Double(40.298, 75.70374));
		add(new Point2D.Double(40.35324, 76.3344));
		add(new Point2D.Double(41.01258, 76.87067));
		add(new Point2D.Double(41.04079, 78.08083));
		add(new Point2D.Double(41.39286, 78.39554));
		add(new Point2D.Double(42.03954, 80.24513));
		add(new Point2D.Double(42.19622, 80.23402));
		add(new Point2D.Double(42.63245, 80.15804));
		add(new Point2D.Double(42.81565, 80.25796));
		add(new Point2D.Double(42.88545, 80.57226));
		add(new Point2D.Double(43.02906, 80.38405));
		add(new Point2D.Double(43.1683, 80.81526));
		add(new Point2D.Double(44.11378, 80.36887));
		add(new Point2D.Double(44.6358, 80.38499));
		add(new Point2D.Double(44.73408, 80.51589));
		add(new Point2D.Double(44.90282, 79.87106));
		add(new Point2D.Double(45.3497, 81.67928));
		add(new Point2D.Double(45.15748, 81.94803));
		add(new Point2D.Double(45.13303, 82.56638));
		add(new Point2D.Double(45.43581, 82.64624));
		add(new Point2D.Double(45.5831, 82.32179));
		add(new Point2D.Double(47.20061, 83.03443));
		add(new Point2D.Double(46.97332, 83.93026));
		add(new Point2D.Double(46.99361, 84.67804));
		add(new Point2D.Double(46.8277, 84.80318));
		add(new Point2D.Double(47.0591, 85.52257));
		add(new Point2D.Double(47.26221, 85.70139));
		add(new Point2D.Double(47.93721, 85.53707));
		add(new Point2D.Double(48.39333, 85.76596));
		add(new Point2D.Double(48.54277, 86.59791));
		add(new Point2D.Double(49.1102, 86.87602));
		add(new Point2D.Double(49.09262, 87.34821));
		add(new Point2D.Double(49.17295, 87.8407));
		add(new Point2D.Double(48.98304, 87.89291));
		add(new Point2D.Double(48.88103, 87.7611));
		add(new Point2D.Double(48.73499, 88.05942));
		add(new Point2D.Double(48.56541, 87.99194));
		add(new Point2D.Double(48.40582, 88.51679));
		add(new Point2D.Double(48.21193, 88.61179));
		add(new Point2D.Double(47.99374, 89.08514));
		add(new Point2D.Double(47.88791, 90.07096));
		add(new Point2D.Double(46.95221, 90.9136));
		add(new Point2D.Double(46.57735, 91.07027));
		add(new Point2D.Double(46.29694, 90.92151));
		add(new Point2D.Double(46.01735, 91.02651));
		add(new Point2D.Double(45.57972, 90.68193));
		add(new Point2D.Double(45.25305, 90.89694));
		add(new Point2D.Double(45.07729, 91.56088));
		add(new Point2D.Double(44.95721, 93.5547));
		add(new Point2D.Double(44.35499, 94.71735));
		add(new Point2D.Double(44.29416, 95.41061));
		add(new Point2D.Double(44.01937, 95.34109));
		add(new Point2D.Double(43.99311, 95.53339));
		add(new Point2D.Double(43.28388, 95.87901));
		add(new Point2D.Double(42.73499, 96.38206));
		add(new Point2D.Double(42.79583, 97.1654));
		add(new Point2D.Double(42.57194, 99.51012));
		add(new Point2D.Double(42.67707, 100.8425));
		add(new Point2D.Double(42.50972, 101.8147));
		add(new Point2D.Double(42.23333, 102.0772));
		add(new Point2D.Double(41.88721, 103.4164));
		add(new Point2D.Double(41.87721, 104.5267));
		add(new Point2D.Double(41.67068, 104.5237));
		add(new Point2D.Double(41.58666, 105.0065));
		add(new Point2D.Double(42.46624, 107.4758));
		add(new Point2D.Double(42.42999, 109.3107));
		add(new Point2D.Double(42.64576, 110.1064));
		add(new Point2D.Double(43.31694, 110.9897));
		add(new Point2D.Double(43.69221, 111.9583));
		add(new Point2D.Double(44.37527, 111.4214));
		add(new Point2D.Double(45.04944, 111.873));
		add(new Point2D.Double(45.08055, 112.4272));
		add(new Point2D.Double(44.8461, 112.853));
		add(new Point2D.Double(44.74527, 113.638));
		add(new Point2D.Double(45.38943, 114.5453));
		add(new Point2D.Double(45.4586, 115.7019));
		add(new Point2D.Double(45.72193, 116.2104));
		add(new Point2D.Double(46.29583, 116.5855));
		add(new Point2D.Double(46.41888, 117.3755));
		add(new Point2D.Double(46.57069, 117.425));
		add(new Point2D.Double(46.53645, 117.8455));
		add(new Point2D.Double(46.73638, 118.3147));
		add(new Point2D.Double(46.59895, 119.7068));
		add(new Point2D.Double(46.71513, 119.9315));
		add(new Point2D.Double(46.90221, 119.9225));
		add(new Point2D.Double(47.66499, 119.125));
		add(new Point2D.Double(47.99475, 118.5393));
		add(new Point2D.Double(48.01125, 117.8046));
		add(new Point2D.Double(47.65741, 117.3827));
		add(new Point2D.Double(47.88805, 116.8747));
		add(new Point2D.Double(47.87819, 116.2624));
		add(new Point2D.Double(47.69186, 115.9231));
		add(new Point2D.Double(47.91749, 115.5944));
		add(new Point2D.Double(48.14353, 115.5491));
		add(new Point2D.Double(48.25249, 115.8358));
		add(new Point2D.Double(48.52055, 115.8111));
		add(new Point2D.Double(49.83047, 116.7114));
		add(new Point2D.Double(49.52058, 117.8747));
		add(new Point2D.Double(49.92263, 118.5746));
		add(new Point2D.Double(50.09631, 119.321));
		add(new Point2D.Double(50.33028, 119.36));
		add(new Point2D.Double(50.39027, 119.1386));
		add(new Point2D.Double(51.62083, 120.0641));
		add(new Point2D.Double(52.115, 120.7767));
		add(new Point2D.Double(52.34423, 120.6259));
		add(new Point2D.Double(52.54267, 120.7122));
		add(new Point2D.Double(52.58805, 120.0819));
		add(new Point2D.Double(52.76819, 120.0314));
		add(new Point2D.Double(53.26374, 120.8307));
		add(new Point2D.Double(53.54361, 123.6147));
		add(new Point2D.Double(53.18832, 124.4933));
		add(new Point2D.Double(53.05027, 125.62));
		add(new Point2D.Double(52.8752, 125.6573));
		add(new Point2D.Double(52.75722, 126.0968));
		add(new Point2D.Double(52.5761, 125.9943));
		add(new Point2D.Double(52.12694, 126.555));
		add(new Point2D.Double(51.99437, 126.4412));
		add(new Point2D.Double(51.38138, 126.9139));
		add(new Point2D.Double(51.26555, 126.8176));
		add(new Point2D.Double(51.31923, 126.9689));
		add(new Point2D.Double(51.05825, 126.9331));
		add(new Point2D.Double(50.74138, 127.2919));
		add(new Point2D.Double(50.31472, 127.334));
		add(new Point2D.Double(50.20856, 127.5861));
		add(new Point2D.Double(49.80588, 127.515));
		add(new Point2D.Double(49.58665, 127.838));
		add(new Point2D.Double(49.58443, 128.7119));
		add(new Point2D.Double(49.34676, 129.1118));
		add(new Point2D.Double(49.4158, 129.4902));
		add(new Point2D.Double(48.86464, 130.2246));
		add(new Point2D.Double(48.86041, 130.674));
		add(new Point2D.Double(48.60576, 130.5236));
		add(new Point2D.Double(48.3268, 130.824));
		add(new Point2D.Double(48.10839, 130.6598));
		add(new Point2D.Double(47.68721, 130.9922));
		add(new Point2D.Double(47.71027, 132.5211));
		add(new Point2D.Double(48.09888, 133.0827));
		add(new Point2D.Double(48.06888, 133.4843));
		add(new Point2D.Double(48.39112, 134.4153));
		add(new Point2D.Double(48.26713, 134.7408));
		add(new Point2D.Double(47.99207, 134.5576));
		add(new Point2D.Double(47.70027, 134.7608));
		add(new Point2D.Double(47.32333, 134.1825));
		add(new Point2D.Double(46.64017, 133.9977));
		add(new Point2D.Double(46.47888, 133.8472));
		add(new Point2D.Double(46.25363, 133.9016));
		add(new Point2D.Double(45.82347, 133.4761));
		add(new Point2D.Double(45.62458, 133.4702));
		add(new Point2D.Double(45.45083, 133.1491));
		add(new Point2D.Double(45.05694, 133.0253));
		add(new Point2D.Double(45.34582, 131.8684));
		add(new Point2D.Double(44.97388, 131.4691));
		add(new Point2D.Double(44.83649, 130.953));
		add(new Point2D.Double(44.05193, 131.298));
		add(new Point2D.Double(43.53624, 131.1912));
		add(new Point2D.Double(43.38958, 131.3104));
		add(new Point2D.Double(42.91645, 131.1285));
		add(new Point2D.Double(42.74485, 130.4327));
		add(new Point2D.Double(42.42186, 130.6044));
		add(new Point2D.Double(42.71416, 130.2468));
		add(new Point2D.Double(42.88794, 130.2514));
		add(new Point2D.Double(43.00457, 129.9046));
		add(new Point2D.Double(42.43582, 129.6955));
		add(new Point2D.Double(42.44624, 129.3493));
		add(new Point2D.Double(42.02736, 128.9269));
		add(new Point2D.Double(42.00124, 128.0566));
		add(new Point2D.Double(41.58284, 128.3002));
		add(new Point2D.Double(41.38124, 128.1529));
		add(new Point2D.Double(41.47249, 127.2708));
		add(new Point2D.Double(41.79222, 126.9047));
		add(new Point2D.Double(41.61176, 126.5661));
		add(new Point2D.Double(40.89694, 126.0118));
		add(new Point2D.Double(40.47037, 124.8851));
		add(new Point2D.Double(40.09362, 124.3736));
		add(new Point2D.Double(39.82777, 124.128));
		add(new Point2D.Double(39.8143, 123.2422));
		add(new Point2D.Double(39.67388, 123.2167));
		add(new Point2D.Double(38.99638, 121.648));
		add(new Point2D.Double(38.8611, 121.6982));
		add(new Point2D.Double(38.71909, 121.1873));
		add(new Point2D.Double(38.91221, 121.0887));
		add(new Point2D.Double(39.09013, 121.6794));
		add(new Point2D.Double(39.2186, 121.5994));
		add(new Point2D.Double(39.35166, 121.7511));
		add(new Point2D.Double(39.52847, 121.2283));
		add(new Point2D.Double(39.62322, 121.533));
		add(new Point2D.Double(39.81138, 121.4683));
		add(new Point2D.Double(40.00305, 121.881));
		add(new Point2D.Double(40.50562, 122.2987));
		add(new Point2D.Double(40.73874, 122.0521));
		add(new Point2D.Double(40.92194, 121.1775));
		add(new Point2D.Double(40.1961, 120.4468));
		add(new Point2D.Double(39.87242, 119.5264));
		add(new Point2D.Double(39.15693, 118.9715));
		add(new Point2D.Double(39.04083, 118.3273));
		add(new Point2D.Double(39.19846, 117.889));
		add(new Point2D.Double(38.67555, 117.5364));
		add(new Point2D.Double(38.38666, 117.6722));
		add(new Point2D.Double(38.16721, 118.0281));
		add(new Point2D.Double(38.1529, 118.8378));
		add(new Point2D.Double(37.87832, 119.0355));
		add(new Point2D.Double(37.30054, 118.9566));
		add(new Point2D.Double(37.14361, 119.2328));
		add(new Point2D.Double(37.15138, 119.7672));
		add(new Point2D.Double(37.35228, 119.8529));
		add(new Point2D.Double(37.83499, 120.7371));
		add(new Point2D.Double(37.42458, 121.58));
		add(new Point2D.Double(37.55256, 122.1282));
		add(new Point2D.Double(37.41833, 122.1814));
		add(new Point2D.Double(37.39624, 122.5586));
		add(new Point2D.Double(37.20999, 122.5972));
		add(new Point2D.Double(37.02583, 122.4005));
		add(new Point2D.Double(37.01978, 122.5392));
		add(new Point2D.Double(36.89361, 122.5047));
		add(new Point2D.Double(36.84298, 122.1923));
		add(new Point2D.Double(37.00027, 121.9566));
		add(new Point2D.Double(36.75889, 121.5944));
		add(new Point2D.Double(36.61666, 120.7764));
		add(new Point2D.Double(36.52638, 120.96));
		add(new Point2D.Double(36.37582, 120.8753));
		add(new Point2D.Double(36.42277, 120.7062));
		add(new Point2D.Double(36.14075, 120.6956));
		add(new Point2D.Double(36.0419, 120.3436));
		add(new Point2D.Double(36.26345, 120.3078));
		add(new Point2D.Double(36.19998, 120.0889));
		add(new Point2D.Double(35.95943, 120.2378));
		add(new Point2D.Double(35.57893, 119.6475));
		add(new Point2D.Double(34.88499, 119.1761));
		add(new Point2D.Double(34.31145, 120.2487));
		add(new Point2D.Double(32.97499, 120.8858));
		add(new Point2D.Double(32.63889, 120.8375));
		add(new Point2D.Double(32.42958, 121.3348));
		add(new Point2D.Double(32.11333, 121.4412));
		add(new Point2D.Double(32.02166, 121.7066));
		add(new Point2D.Double(31.67833, 121.8275));
		add(new Point2D.Double(31.86639, 120.9444));
		add(new Point2D.Double(32.09361, 120.6019));
		add(new Point2D.Double(31.94555, 120.099));
		add(new Point2D.Double(32.30638, 119.8267));
		add(new Point2D.Double(32.26277, 119.6317));
		add(new Point2D.Double(31.90388, 120.1364));
		add(new Point2D.Double(31.98833, 120.7026));
		add(new Point2D.Double(31.81944, 120.7196));
		add(new Point2D.Double(31.30889, 121.6681));
		add(new Point2D.Double(30.97986, 121.8828));
		add(new Point2D.Double(30.85305, 121.8469));
		add(new Point2D.Double(30.56889, 120.9915));
		add(new Point2D.Double(30.33555, 120.8144));
		add(new Point2D.Double(30.39298, 120.4586));
		add(new Point2D.Double(30.19694, 120.15));
		add(new Point2D.Double(30.31027, 120.5082));
		add(new Point2D.Double(30.06465, 120.7916));
		add(new Point2D.Double(30.30458, 121.2808));
		add(new Point2D.Double(29.96305, 121.6778));
		add(new Point2D.Double(29.88211, 122.1196));
		add(new Point2D.Double(29.51167, 121.4483));
		add(new Point2D.Double(29.58916, 121.9744));
		add(new Point2D.Double(29.19527, 121.9336));
		add(new Point2D.Double(29.18388, 121.8119));
		add(new Point2D.Double(29.37236, 121.7969));
		add(new Point2D.Double(29.19729, 121.7444));
		add(new Point2D.Double(29.29111, 121.5611));
		add(new Point2D.Double(29.1634, 121.4135));
		add(new Point2D.Double(29.02194, 121.6914));
		add(new Point2D.Double(28.9359, 121.4908));
		add(new Point2D.Double(28.72798, 121.6113));
		add(new Point2D.Double(28.84215, 121.1464));
		add(new Point2D.Double(28.66993, 121.4844));
		add(new Point2D.Double(28.34722, 121.6417));
		add(new Point2D.Double(28.13889, 121.3419));
		add(new Point2D.Double(28.38277, 121.1651));
		add(new Point2D.Double(27.98222, 120.9353));
		add(new Point2D.Double(28.07944, 120.5908));
		add(new Point2D.Double(27.87229, 120.84));
		add(new Point2D.Double(27.59319, 120.5812));
		add(new Point2D.Double(27.45083, 120.6655));
		add(new Point2D.Double(27.20777, 120.5075));
		add(new Point2D.Double(27.28278, 120.1896));
		add(new Point2D.Double(27.14764, 120.4211));
		add(new Point2D.Double(26.89805, 120.0332));
		add(new Point2D.Double(26.64465, 120.128));
		add(new Point2D.Double(26.51778, 119.8603));
		add(new Point2D.Double(26.78823, 120.0733));
		add(new Point2D.Double(26.64888, 119.8668));
		add(new Point2D.Double(26.79611, 119.7879));
		add(new Point2D.Double(26.75625, 119.5503));
		add(new Point2D.Double(26.44222, 119.8204));
		add(new Point2D.Double(26.47388, 119.5775));
		add(new Point2D.Double(26.33861, 119.658));
		add(new Point2D.Double(26.36777, 119.9489));
		add(new Point2D.Double(25.99694, 119.4253));
		add(new Point2D.Double(26.14041, 119.0975));
		add(new Point2D.Double(25.93788, 119.354));
		add(new Point2D.Double(25.99069, 119.7058));
		add(new Point2D.Double(25.67996, 119.5807));
		add(new Point2D.Double(25.68222, 119.4522));
		add(new Point2D.Double(25.35333, 119.6454));
		add(new Point2D.Double(25.60649, 119.3149));
		add(new Point2D.Double(25.42097, 119.1053));
		add(new Point2D.Double(25.25319, 119.3526));
		add(new Point2D.Double(25.17208, 119.2726));
		add(new Point2D.Double(25.2426, 118.8749));
		add(new Point2D.Double(24.97194, 118.9866));
		add(new Point2D.Double(24.88291, 118.5729));
		add(new Point2D.Double(24.75673, 118.7631));
		add(new Point2D.Double(24.52861, 118.5953));
		add(new Point2D.Double(24.53638, 118.2397));
		add(new Point2D.Double(24.68194, 118.1688));
		add(new Point2D.Double(24.44024, 118.0199));
		add(new Point2D.Double(24.46019, 117.7947));
		add(new Point2D.Double(24.25875, 118.1237));
		add(new Point2D.Double(23.62437, 117.1957));
		add(new Point2D.Double(23.65919, 116.9179));
		add(new Point2D.Double(23.355, 116.7603));
		add(new Point2D.Double(23.42024, 116.5322));
		add(new Point2D.Double(23.23666, 116.7871));
		add(new Point2D.Double(23.21083, 116.5139));
		add(new Point2D.Double(22.93902, 116.4817));
		add(new Point2D.Double(22.73916, 115.7978));
		add(new Point2D.Double(22.88416, 115.6403));
		add(new Point2D.Double(22.65889, 115.5367));
		add(new Point2D.Double(22.80833, 115.1614));
		add(new Point2D.Double(22.70277, 114.8889));
		add(new Point2D.Double(22.53305, 114.8722));
		add(new Point2D.Double(22.64027, 114.718));
		add(new Point2D.Double(22.81402, 114.7782));
		add(new Point2D.Double(22.69972, 114.5208));
		add(new Point2D.Double(22.50423, 114.6136));
		add(new Point2D.Double(22.55004, 114.2223));
		add(new Point2D.Double(22.42993, 114.3885));
		add(new Point2D.Double(22.26056, 114.2961));
		add(new Point2D.Double(22.36736, 113.9056));
		add(new Point2D.Double(22.50874, 114.0337));
		add(new Point2D.Double(22.47444, 113.8608));
		add(new Point2D.Double(22.83458, 113.606));
		add(new Point2D.Double(23.05027, 113.5253));
		add(new Point2D.Double(23.11724, 113.8219));
		add(new Point2D.Double(23.05083, 113.4793));
		add(new Point2D.Double(22.87986, 113.3629));
		add(new Point2D.Double(22.54944, 113.5648));
		add(new Point2D.Double(22.18701, 113.5527));
		add(new Point2D.Double(22.56701, 113.1687));
		add(new Point2D.Double(22.17965, 113.3868));
		add(new Point2D.Double(22.04069, 113.2226));
		add(new Point2D.Double(22.20485, 113.0848));
		add(new Point2D.Double(21.8693, 112.94));
		add(new Point2D.Double(21.96472, 112.824));
		add(new Point2D.Double(21.70139, 112.2819));
		add(new Point2D.Double(21.91611, 111.8921));
		add(new Point2D.Double(21.75139, 111.9669));
		add(new Point2D.Double(21.77819, 111.6762));
		add(new Point2D.Double(21.61264, 111.7832));
		add(new Point2D.Double(21.5268, 111.644));
		add(new Point2D.Double(21.52528, 111.0285));
		add(new Point2D.Double(21.21138, 110.5328));
		add(new Point2D.Double(21.37322, 110.3944));
		add(new Point2D.Double(20.84381, 110.1594));
		add(new Point2D.Double(20.84083, 110.3755));
		add(new Point2D.Double(20.64, 110.3239));
		add(new Point2D.Double(20.48618, 110.5274));
		add(new Point2D.Double(20.24611, 110.2789));
		add(new Point2D.Double(20.2336, 109.9244));
		add(new Point2D.Double(20.4318, 110.0069));
		add(new Point2D.Double(20.92416, 109.6629));
		add(new Point2D.Double(21.44694, 109.9411));
		add(new Point2D.Double(21.50569, 109.6605));
		add(new Point2D.Double(21.72333, 109.5733));
		add(new Point2D.Double(21.49499, 109.5344));
		add(new Point2D.Double(21.39666, 109.1428));
		add(new Point2D.Double(21.58305, 109.1375));
		add(new Point2D.Double(21.61611, 108.911));
		add(new Point2D.Double(21.79889, 108.8702));
		add(new Point2D.Double(21.59888, 108.7403));
		add(new Point2D.Double(21.93562, 108.4692));
		add(new Point2D.Double(21.59014, 108.5125));
		add(new Point2D.Double(21.68999, 108.3336));
		add(new Point2D.Double(21.51444, 108.2447));
		add(new Point2D.Double(21.54241, 107.99));
		add(new Point2D.Double(21.66694, 107.7831));
		add(new Point2D.Double(21.60526, 107.3627));
		add(new Point2D.Double(22.03083, 106.6933));
		add(new Point2D.Double(22.45682, 106.5517));
		add(new Point2D.Double(22.76389, 106.7875));
		add(new Point2D.Double(22.86694, 106.7029));
		add(new Point2D.Double(22.91253, 105.8771));
		add(new Point2D.Double(23.32416, 105.3587));
		add(new Point2D.Double(23.18027, 104.9075));
		add(new Point2D.Double(22.81805, 104.7319));
		add(new Point2D.Double(22.6875, 104.3747));
		add(new Point2D.Double(22.79812, 104.1113));
		add(new Point2D.Double(22.50387, 103.9687));
		add(new Point2D.Double(22.78287, 103.6538));
		add(new Point2D.Double(22.58436, 103.5224));
		add(new Point2D.Double(22.79451, 103.3337));
		add(new Point2D.Double(22.43652, 103.0304));
		add(new Point2D.Double(22.77187, 102.4744));
		add(new Point2D.Double(22.39629, 102.1407));
		add(new Point2D.Double(22.49777, 101.7415));
		add(new Point2D.Double(22.20916, 101.5744));
		add(new Point2D.Double(21.83444, 101.7653));
		add(new Point2D.Double(21.14451, 101.786));
		add(new Point2D.Double(21.17687, 101.2919));
		add(new Point2D.Double(21.57264, 101.1482));
		add(new Point2D.Double(21.76903, 101.099));
		add(new Point2D.Double(21.47694, 100.6397));
		add(new Point2D.Double(21.43546, 100.2057));
		add(new Point2D.Double(21.72555, 99.97763));
		add(new Point2D.Double(22.05018, 99.95741));
		add(new Point2D.Double(22.15592, 99.16785));
		add(new Point2D.Double(22.93659, 99.56484));
		add(new Point2D.Double(23.08204, 99.5113));
		add(new Point2D.Double(23.18916, 98.92747));
		add(new Point2D.Double(23.97076, 98.67991));
		add(new Point2D.Double(24.16007, 98.89073));
		add(new Point2D.Double(23.92999, 97.54762));
		add(new Point2D.Double(24.26055, 97.7593));
		add(new Point2D.Double(24.47666, 97.54305));
		add(new Point2D.Double(24.73992, 97.55255));
		add(new Point2D.Double(25.61527, 98.19109));
		add(new Point2D.Double(25.56944, 98.36137));
		add(new Point2D.Double(25.85597, 98.7104));
		add(new Point2D.Double(26.12527, 98.56944));
		add(new Point2D.Double(26.18472, 98.73109));
		add(new Point2D.Double(26.79166, 98.77777));
		add(new Point2D.Double(27.52972, 98.69699));
		add(new Point2D.Double(27.6725, 98.45888));
		add(new Point2D.Double(27.54014, 98.31992));
		add(new Point2D.Double(28.14889, 98.14499));
		add(new Point2D.Double(28.54652, 97.55887));
		add(new Point2D.Double(28.22277, 97.34888));
		add(new Point2D.Double(28.46749, 96.65387));
		add(new Point2D.Double(28.35111, 96.40193));
		add(new Point2D.Double(28.525, 96.34027));
		add(new Point2D.Double(28.79569, 96.61373));
		add(new Point2D.Double(29.05666, 96.47083));
		add(new Point2D.Double(28.90138, 96.17532));
		add(new Point2D.Double(29.05972, 96.14888));
		add(new Point2D.Double(29.25757, 96.39172));
		add(new Point2D.Double(29.46444, 96.08315));
		add(new Point2D.Double(29.03527, 95.38777));
		add(new Point2D.Double(29.33346, 94.64751));
		add(new Point2D.Double(29.07348, 94.23456));
		add(new Point2D.Double(28.6692, 93.96172));
		add(new Point2D.Double(28.61876, 93.35194));
		add(new Point2D.Double(28.3193, 93.22205));
		add(new Point2D.Double(28.1419, 92.71044));
		add(new Point2D.Double(27.86194, 92.54498));
		add(new Point2D.Double(27.76472, 91.65776));
		add(new Point2D.Double(27.945, 91.66277));
		add(new Point2D.Double(28.08111, 91.30138));
		add(new Point2D.Double(27.96999, 91.08693));
		add(new Point2D.Double(28.07958, 90.3765));
		add(new Point2D.Double(28.24257, 90.38898));
		add(new Point2D.Double(28.32369, 89.99819));
		add(new Point2D.Double(28.05777, 89.48749));
		add(new Point2D.Double(27.32083, 88.91693));
	}};

	//初始化TaiWan边界点
	private static List polygonTaiWan = new ArrayList() {{
		add(new Point2D.Double(25.13474, 121.4441));
		add(new Point2D.Double(25.28361, 121.5632));
		add(new Point2D.Double(25.00722, 122.0004));
		add(new Point2D.Double(24.85028, 121.8182));
		add(new Point2D.Double(24.47638, 121.8397));
		add(new Point2D.Double(23.0875, 121.3556));
		add(new Point2D.Double(21.92791, 120.7196));
		add(new Point2D.Double(22.31277, 120.6103));
		add(new Point2D.Double(22.54044, 120.3071));
		add(new Point2D.Double(23.04437, 120.0539));
		add(new Point2D.Double(23.61708, 120.1112));
		add(new Point2D.Double(25.00166, 121.0017));
		add(new Point2D.Double(25.13474, 121.4441));
	}};

	//初始化HaiNan边界点
	private static List polygonHaiNan = new ArrayList() {{
		add(new Point2D.Double(19.52888, 110.855));
		add(new Point2D.Double(19.16761, 110.4832));
		add(new Point2D.Double(18.80083, 110.5255));
		add(new Point2D.Double(18.3852, 110.0503));
		add(new Point2D.Double(18.39152, 109.7594));
		add(new Point2D.Double(18.19777, 109.7036));
		add(new Point2D.Double(18.50562, 108.6871));
		add(new Point2D.Double(19.28028, 108.6283));
		add(new Point2D.Double(19.76, 109.2939));
		add(new Point2D.Double(19.7236, 109.1653));
		add(new Point2D.Double(19.89972, 109.2572));
		add(new Point2D.Double(19.82861, 109.4658));
		add(new Point2D.Double(19.99389, 109.6108));
		add(new Point2D.Double(20.13361, 110.6655));
		add(new Point2D.Double(19.97861, 110.9425));
		add(new Point2D.Double(19.63829, 111.0215));
		add(new Point2D.Double(19.52888, 110.855));
	}};

	//初始化ChongMing岛边界点
	private static List polygonChongMing = new ArrayList() {{
		add(new Point2D.Double(31.80054, 121.2039));
		add(new Point2D.Double(31.49972, 121.8736));
		add(new Point2D.Double(31.53111, 121.5464));
		add(new Point2D.Double(31.80054, 121.2039));
	}};

	static {
		generalPathMainland = getGeneralPath(polygonMainland);
		generalPathTaiWan = getGeneralPath(polygonTaiWan);
		generalPathHaiNan = getGeneralPath(polygonHaiNan);
		generalPathChongMing = getGeneralPath(polygonChongMing);
	}

	/**
	 * Description 生成地图不规则多边形
	 *
	 * [@param](https://my.oschina.net/u/2303379) polygonPoint 边界点集合
	 * [@return](https://my.oschina.net/u/556800)
	 * [@author](https://my.oschina.net/arthor) tcwong
	 * @date 2020/11/29
	 */
	private static GeneralPath getGeneralPath(List polygonPoint) {
		GeneralPath generalPath = new GeneralPath();
		Point2D.Double startPoint = polygonPoint.get(0);
		generalPath.moveTo(startPoint.getX(), startPoint.getY());
		polygonPoint.remove(0);
		polygonPoint.forEach(point -> {
			generalPath.lineTo(point.getX(), point.getY());
		});
		generalPath.lineTo(startPoint.getX(), startPoint.getY());
		generalPath.closePath();
		return generalPath;
	}

	/**
	 * Description 判断目标点在不在版图内
	 *
	 * @param longitude 经度
	 * @param latitude  纬度
	 * @return
	 * @author tcwong
	 * @date 2020/11/29
	 */
	public static Boolean isInPolygon(double longitude, double latitude) {
		Point2D.Double targetPoint = new Point2D.Double(latitude, longitude);
		return generalPathMainland.contains(targetPoint)
				|| generalPathTaiWan.contains(targetPoint)
				|| generalPathHaiNan.contains(targetPoint)
				|| generalPathChongMing.contains(targetPoint);
	}

}

测试 Test

public class Test {

public static void main(String[] args) {
    //北京
    System.out.println("北京"+PolygonUtil.isInPolygon(116.23128, 40.22077));
    //哈尔滨
    System.out.println("哈尔滨"+PolygonUtil.isInPolygon(126.95717, 45.54774));
    //西安
    System.out.println("西安"+PolygonUtil.isInPolygon(108.93425, 34.23053));
    //南京
    System.out.println("南京"+PolygonUtil.isInPolygon(118.8921, 31.32751));
    //深圳
    System.out.println("深圳"+PolygonUtil.isInPolygon(113.88308, 22.55329));
    //澳门
    System.out.println("澳门"+PolygonUtil.isInPolygon(113.54913, 22.19875));
    //台北
    System.out.println("台北"+PolygonUtil.isInPolygon(121.520076, 25.030724));
    //东京
    System.out.println("东京"+PolygonUtil.isInPolygon(139.44, 35.41));
    //平壤
    System.out.println("平壤"+PolygonUtil.isInPolygon(125.30, 39.0));
    }
}

如何判断目标点是否在指定地图版块上

感谢各位的阅读,以上就是“如何判断目标点是否在指定地图版块上”的内容了,经过本文的学习后,相信大家对如何判断目标点是否在指定地图版块上这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!


当前名称:如何判断目标点是否在指定地图版块上
当前网址:http://lswzjz.com/article/gdoiic.html