一、JTS使用的maven pom
<!-- 幾何形狀關係判斷 -->
<dependency>
<groupId>com.vividsolutions</groupId>
<artifactId>jts</artifactId>
<version>1.13</version>
</dependency>
二、JTS提供了以下的空間數據類型
Point
MultiPoint
LineString
LinearRing 封閉的線條
MultiLineString 多條線
Polygon 多邊形
MultiPolygon maven
GeometryCollection 包括點,線,面
三、計算點到面的距離
WKTReader reader = new WKTReader();
Geometry point = reader.read(String.format(WKTPOINT, lng, lat));
for (String areaId : borderlineMap.keySet()) {
Geometry polygon = borderlineMap.get(areaId);
if (polygon.distance(point) == 0) {
return areaId;
}
}spa
這裏的距離polygon.distance(point)與百度的距離米大概須要乘以100000
四、針對百度地圖,更新緩慢的問題,解決區域邊界劃分,例如合肥市和巢湖市,巢湖市已經歸合肥市管轄
可是百度地圖區域範圍一直沒更新
Geometry polygon1 = reader.read("POLYGON((" + points1 + "))");
String points2 = min.replace(",", "").replace(";", ",");
Geometry polygon2 = reader.read("POLYGON((" + points2 + "))");
Geometry a = polygon1.union(polygon2);
說白了就是合併區域和從大區域扣掉小的區域
使用union和difference解決問題orm