数学计算库 最后更新时间: 2021年01月22日
AMap.GeometryUtil
GeometryUtil为一组空间数据计算的函数库,v1.4.2新增。支持点线面的空间关系计算、长度、面积计算等等,包含的函数如下:
函数名 | 返回值 | 说明 |
---|---|---|
|
| 计算两个经纬度点之间的实际距离。单位:米 |
|
| 计算一个经纬度路径围成区域的实际面积。单位:平米 |
|
| 判断一个经纬度路径是否为顺时针 |
|
| 计算一个经纬度路径的实际长度。单位:米 |
|
| 计算两个经纬度面的交叉区域。只适用于凸多边形,单位:平米 |
|
| 判断两个经纬度面是否交叉 |
|
| 判断经纬度路径和经纬度面是否交叉 |
|
| 判断两个经纬度路径是否相交 |
|
| 判断线段和多个环是否相交 |
|
| 判断线段和一个环是否相交 |
|
| 判断线段和一个路径是否相交 |
|
| 判断两个线段是否相交 |
|
| 判断点是否在环内 |
|
| 判断环是否在另一个环内 |
|
| 判断点是否在多个环组成区域内 |
|
| 将一个路径变为顺时针 |
|
| 将一个路径变为逆时针 |
|
| 计算P2P3上距离P1最近的点 |
|
| 计算line上距离P最近的点 |
|
| 计算P2P3到P1的距离。单位:米 |
|
| 计算P到line的距离。单位:米 |
|
| 判断P1是否在P2P3上,tolerance为误差范围 |
|
| 判断P是否在line上,tolerance为误差范围 |
|
| 判断P是否在ring的边上,tolerance为误差范围 |
|
| 判断P是否在多个ring的边上,tolerance为误差范围 |
这些方法使用时,可以使用经纬度对,也可以使用LngLat对象,参考如下:
var point = [116.566298, 40.014179];
var ring = [
[116.169465,39.932670],
[116.160260,39.924492],
[116.186138,39.879817],
[116.150625,39.710019],
[116.183198,39.709920],
[116.226950,39.777616],
[116.421078,39.810771],
[116.442621,39.799892],
[116.463478,39.790066],
[116.588276,39.809551],
[116.536091,39.808859],
[116.573856,39.839643],
[116.706380,39.916740],
[116.657285,39.934545],
[116.600293,39.937770],
[116.540039,39.937968],
[116.514805,39.982375],
[116.499935,40.013710],
[116.546520,40.030443],
[116.687668,40.129961],
[116.539697,40.080659],
[116.503390,40.058474],
[116.468800,40.052578]
];
var isPointInRing = AMap.GeometryUtil.isPointInRing(point,ring);
var point = new AMap.LngLat(116.566298, 40.014179)
var ring = [
new AMap.LngLat(116.169465,39.932670),
new AMap.LngLat(116.160260,39.924492),
new AMap.LngLat(116.186138,39.879817),
new AMap.LngLat(116.150625,39.710019),
new AMap.LngLat(116.183198,39.709920),
new AMap.LngLat(116.226950,39.777616),
new AMap.LngLat(116.421078,39.810771),
new AMap.LngLat(116.442621,39.799892),
new AMap.LngLat(116.463478,39.790066),
new AMap.LngLat(116.588276,39.809551),
new AMap.LngLat(116.536091,39.808859),
new AMap.LngLat(116.573856,39.839643),
new AMap.LngLat(116.706380,39.916740),
new AMap.LngLat(116.657285,39.934545),
new AMap.LngLat(116.600293,39.937770),
new AMap.LngLat(116.540039,39.937968),
new AMap.LngLat(116.514805,39.982375),
new AMap.LngLat(116.499935,40.013710),
new AMap.LngLat(116.546520,40.030443),
new AMap.LngLat(116.687668,40.129961),
new AMap.LngLat(116.539697,40.080659),
new AMap.LngLat(116.503390,40.058474),
new AMap.LngLat(116.468800,40.052578)
];
var isPointInRing = AMap.GeometryUtil.isPointInRing(point,ring);