huanghongfa
2021-06-07 71949fe2af29b044d2d584e48df30a3f28fd2024
判断一个点是否在一组经纬度包围圈内工具类
2个文件已添加
50 ■■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/grid/LatLngVO.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/LngLatUtils.java 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/vos/grid/LatLngVO.java
New file
@@ -0,0 +1,11 @@
package com.panzhihua.common.model.vos.grid;
import lombok.Data;
@Data
public class LatLngVO {
    private Double lng;
    private Double lat;
}
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/LngLatUtils.java
New file
@@ -0,0 +1,39 @@
package com.panzhihua.common.utlis;
import com.panzhihua.common.model.vos.grid.LatLngVO;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
public class LngLatUtils {
    public static boolean check(Point2D.Double _point, List<Point2D.Double> polygon)
    {
        java.awt.geom.GeneralPath peneralPath = new java.awt.geom.GeneralPath();
        Point2D.Double first = polygon.get(0);
        peneralPath.moveTo(first.x, first.y);
        polygon.remove(0);
        for(Point2D.Double d : polygon)
        {
            peneralPath.lineTo(d.x, d.y);
        }
        peneralPath.lineTo(first.x, first.y);
        peneralPath.closePath();
        return peneralPath.contains(_point);
    }
    public static  boolean isInPolygon(List<LatLngVO> bound, double pointlng, double pointLat)
    {
        Point2D.Double point = new Point2D.Double(pointlng, pointLat);
        List<Point2D.Double> pointList = new ArrayList<>();
        for (int i = 0; i < bound.size(); i++) {
            pointList.add(new Point2D.Double(bound.get(i).getLng(), bound.get(i).getLat()));
        }
        return check(point, pointList);
    }
}