geom~LinearRing(points)

闭合线,也称线环。相对于普通线的特别之处在于,该对象是闭合的(首尾坐标相同)。

Extends:

Summary

Methods:
fromCoordSeq

从坐标序列构建一个线环,如果坐标序列参数中的坐标若首尾坐标不同,则会将第一个点添加到坐标序列末尾以构成闭环

fromExtent

将当前地理范围转换成线环。

_angularDis

两个坐标之间的大圆弧度

_intermediate

沿两坐标点之间的大圆路径的任意比例的中间点,f为0,结果就是第一个点,f为1,结果就是第二点

addCoord

追加坐标到线环的坐标数组中。
1.如果索引值大于线的坐标数据长度,那么新坐标将被追加到线的末尾;
2.如果索引值小于0时,新坐标被添加到坐标数组的第一个位置之前。
3.如果不传入索引值,则自动追加到线的末尾。
4.如果新坐标加入到了线的末尾,该方法会自动再添加第一个点,以确保闭合。

applyTransform

给定一个函数,用来修改几何对象的坐标值。该方法可能改变原几何对象的坐标值,如果需要保留原几何对象,可以使用clone方法复制为副本。

atApproximatePoint

检测一个坐标是否在几何对象的边界范围以内。 本计算基于边界盒与坐标的相交运算,不包含高程方向的运算,一般用于近似相交判断。注意:与边界盒相交的坐标不一定在几何对象内,可能会在几何对象的边缘以外附近。
边界盒:即几何对象的地理范围构成的多边形区域。

clone

复制一个线环对象。

containsCoord

判断当前线环围成的区域内是否包含了给定地理坐标。

copyTo

复制当前几何对象对象,将得到的几何对象对象的地理范围中心变成传参的coordinate。不改变原来的geometry对象。

destroy

销毁对象。

distanceTo

计算两个地理几何对象之间的距离(X-Y平面内)。

getArea

计算线环所围成区域的面积。线环的面积代表的是多边形的面积,该多边形以该线环为多边形外环。

getBBox

计算几何对象的三维包围盒。

getBuffer

获取线环的缓冲区。缓冲区限于X-Y平面内,非三维空间中的缓冲区。(注意:缓冲距离请控制在合理范围,否则有可能导致结果和预期不符合)

getCentroid

计算线环的质心。线环的质心代表的是多边形的质心,该多边形以该线环为多边形外环。

getClosestPoint

从构成几何对象的所有点中,获取离传入坐标最近的一个点。传入坐标到多点距离都相等时,返回几何对象的第一个点。

getCoordinateAt

从几何对象开始的位置,按照比例因子匹配最接近索引的坐标。若比例因子对应的位置正好在两个点的中间,则返回后面的点。

getCoordSeq

提取几何对象的坐标序列。从起始索引开始提取,取到结束索引的前一位,即按“前闭后开”的原则进行提取坐标。
1.当startIndex小于0时则取0,当endIndex大于坐标序列长度时取坐标序列长度;
2.当endIndex未传入时,返回startIndex以后的Coordinate;
3.如果startIndex与endIndex参数为空,返回所有Coordinate。
4.当startIndex大于等于endIndex,返回空数组。

getExtent

计算线环的地理范围。该地理范围界定了X-Y平面的边界,不含高程信息。

getLength

计算线环的三维长度。每个线段长度的计算:根据每截线段在球面上投影的长度和两端点高差平方和,对其取开平方。

getType

获取几何对象类型。

getVertices

获取当前几何对象的所有节点。

intersectsExtent

检测几何对象与地理范围是否相交。

intersectsGeometry

检测与另一个几何对象是否相交。

isSelfIntersects

自相交判断。

moveByDelta

将几何对象的所有坐标按给定的参数偏移。如果参数为负,则向坐标轴负向偏移。该方法可能改变原几何对象的位置,如果需要保留原几何对象,可以使用clone方法复制为副本

removeCoord

删除线环几何对象上的一个坐标。

rotate

绕着指定直线(旋转轴)旋转,所指定的直线穿过给定点且平行于坐标轴。旋转后的坐标可能发生变化。绕轴旋转的本质如下: 绕平行于Z轴的直线旋转即是在XY平面内旋转;绕平行于X轴的直线旋转即是在YZ平面内旋转;绕平行于Y轴的直线旋转即是在XZ平面内旋转

scale

按各坐标轴的缩放比例和指定的缩放原点进行缩放几何对象。该方法可能改变原几何对象的坐标值,如果需要保留原几何对象,可以使用clone方法复制作为副本。

simplify

简化线环。在尽可能不改变原几何对象形状的情况下,减少构成线环的坐标数量。(采用道格拉斯-普克算法,线环中应至少包含三个点,若点个数小于3,则不做任何处理)

toPolygon

将线环转化为多边形。

transform

将一个线状几何对象中点所对应的地理坐标从源坐标系转换到目标坐标系。该方法可能改变原几何对象的坐标值,如果需要保留原几何对象,可以使用clone方法复制为副本。

Constructor

new LinearRing(points)

构造一个线环。其参数坐标数组中如果首尾两点不同,则构造函数会获取第一个点,追加到数组末尾,以保证形成闭环。
传入的数组长度如果少于3,会抛出异常;如果传入的数组长度为3,且第一个点的坐标和最后一个点的坐标相同,将构造一个拓扑错误的线环。

Parameters:
Name Type Description
points Array.<module:geom~Point>

点数组

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,32,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);

Methods

static fromCoordSeq(coordSeq) → {module:geom~LinearRing}

从坐标序列构建一个线环,如果坐标序列参数中的坐标若首尾坐标不同,则会将第一个点添加到坐标序列末尾以构成闭环

Parameters:
Name Type Description
coordSeq module:basetype~CoordSeq

坐标序列

Throws:
TypeError -

当坐标序列的坐标少于3,会抛出异常

Returns:
module:geom~LinearRing -

由坐标序列构建的线环

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,32,0);
let coordSeq = new hmap.basetype.CoordSeq([coord1,coord2,coord3]);
let result = hmap.geom.LinearRing.fromCoordSeq(coordSeq);

static fromExtent(extent) → {module:geom~LinearRing}

将当前地理范围转换成线环。

Parameters:
Name Type Description
extent module:basetype~Extent

地理范围,类型不是Extent时方法返回null。

Returns:
module:geom~LinearRing -

线环

Example
let linearRing = LinearRing.fromExtent(extent);

_angularDis(tempCoor1, tempCoor2) → {Number}

两个坐标之间的大圆弧度

Parameters:
Name Type Description
tempCoor1 module:basetype~Coordinate
tempCoor2 module:basetype~Coordinate
Returns:
Number -

两个坐标之间的大圆弧度

_intermediate(tempCoor1, tempCoor2, f, 结果点)

沿两坐标点之间的大圆路径的任意比例的中间点,f为0,结果就是第一个点,f为1,结果就是第二点

Parameters:
Name Type Description
tempCoor1 module:basetype~Coordinate
tempCoor2 module:basetype~Coordinate
f Number

比例

结果点 module:basetype~Coordinate

addCoord(coord, index) → {Number}

追加坐标到线环的坐标数组中。
1.如果索引值大于线的坐标数据长度,那么新坐标将被追加到线的末尾;
2.如果索引值小于0时,新坐标被添加到坐标数组的第一个位置之前。
3.如果不传入索引值,则自动追加到线的末尾。
4.如果新坐标加入到了线的末尾,该方法会自动再添加第一个点,以确保闭合。

Parameters:
Name Type Description
coord module:basetype~Coordinate

添加的坐标

index Number

指定的索引值

Returns:
Number -

增加的坐标个数

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,32,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);
let coord4 = new hmap.basetype.Coordinate(120,30,0);
let result = linearRing.addCoord(coord4, 2);//result=0

applyTransform(callback)

给定一个函数,用来修改几何对象的坐标值。该方法可能改变原几何对象的坐标值,如果需要保留原几何对象,可以使用clone方法复制为副本。

Parameters:
Name Type Description
callback function

用于处理坐标值的回调函数,回调函数的参数为坐标对象,该回调函数会作用在几何对象的每个坐标上

atApproximatePoint(coord) → {Boolean}

检测一个坐标是否在几何对象的边界范围以内。 本计算基于边界盒与坐标的相交运算,不包含高程方向的运算,一般用于近似相交判断。注意:与边界盒相交的坐标不一定在几何对象内,可能会在几何对象的边缘以外附近。
边界盒:即几何对象的地理范围构成的多边形区域。

Parameters:
Name Type Description
coord module:basetype~Coordinate

地理坐标

Returns:
Boolean -

返回true表示在几何对象的边界盒范围以内;返回false表示不在几何对象的边界盒范围以内

clone() → {module:geom~LinearRing}

复制一个线环对象。

Returns:
module:geom~LinearRing -

新的线环对象

Example
let newLinearRing = linearRing.clone();

containsCoord(coord) → {Boolean}

判断当前线环围成的区域内是否包含了给定地理坐标。

Parameters:
Name Type Description
coord module:basetype~Coordinate

地理坐标

Returns:
Boolean -

true表示包含,false表示不包含

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,32,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);
let coord4 = new hmap.basetype.Coordinate(120,30,0);
let result = linearRing.containsCoord(coord4);//result=true

copyTo(coordinate) → {module:geom~Geometry}

复制当前几何对象对象,将得到的几何对象对象的地理范围中心变成传参的coordinate。不改变原来的geometry对象。

Parameters:
Name Type Description
coordinate module:basetype~Coordinate

地理坐标

Returns:
module:geom~Geometry -

新的geometry对象,geometry类型和调用该方法的对象的类型一致。

destroy()

销毁对象。

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,30,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);
linearRing.destroy();

distanceTo(geometry, options) → {Number|Object}

计算两个地理几何对象之间的距离(X-Y平面内)。

Parameters:
Name Type Description
geometry module:geom~Geometry

地理几何对象,继承module:geom~Geometry的任意几何对象

options Object

距离计算时的可选配置项

Name Type Description
details Boolean

指定返回结果的格式,默认为false
若为true,则返回一个对象:{"distance":xxx,"x0":xxx,"y0":xxx,"x1":xxx,"y1":xxx}。其中 distance 表示几何对象到目标几何对象的距离;x0 和 y0 属性表示当前几何对象上最靠近目标几何对象的坐标;x1 和 y1 表示目标几何上最靠近当前几何对象的坐标。
但当edge为false且两个几何对象相交,则计算距离的详细交点信息的:x0,y0,x1,y1 无参考意义!
若为false,则返回几何对象到目标几何对象的距离值,距离的单位与几何对象的坐标相同。

edge Boolean

是否计算一个几何图形到目标几何图形边缘的最近距离,默认为true。 如果为true, 一个几何图形完全包含在目标几何图形中时,计算距离为负数;如果为false,两个几何图形相交情况下 计算距离为0。

Returns:
Number | Object -

两个几何之间的距离。details为true 返回Object 否则返回 Number

getArea() → {Number}

计算线环所围成区域的面积。线环的面积代表的是多边形的面积,该多边形以该线环为多边形外环。

Returns:
Number -

线环围成的面积

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,30,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);
let result = linearRing.getArea();//result=1

getBBox() → {module:basetype~BBox}

计算几何对象的三维包围盒。

Returns:
module:basetype~BBox -

返回三维包围盒

getBuffer(dist, sideSign) → {module:geom~Polygon}

获取线环的缓冲区。缓冲区限于X-Y平面内,非三维空间中的缓冲区。(注意:缓冲距离请控制在合理范围,否则有可能导致结果和预期不符合)

Parameters:
Name Type Default Description
dist Number

缓冲距离,一个正数,单位和地图单位相同。注意,缓冲半径过大可能出现重叠或岛洞

sideSign String 0

缓冲模式。1:左缓冲,-1:右缓冲,0:双向缓冲。默认为0

Returns:
module:geom~Polygon -

返回一个面状几何对象

getCentroid() → {module:basetype~Coordinate}

计算线环的质心。线环的质心代表的是多边形的质心,该多边形以该线环为多边形外环。

Returns:
module:basetype~Coordinate -

质心的地理坐标

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,30,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);
let result = linearRing.getCentroid();//result=new hmap.basetype.Coordinate(121,30.333333,0)

getClosestPoint(coord) → {module:geom~Point}

从构成几何对象的所有点中,获取离传入坐标最近的一个点。传入坐标到多点距离都相等时,返回几何对象的第一个点。

Parameters:
Name Type Description
coord module:basetype~Coordinate

地理坐标实例

Returns:
module:geom~Point -

几何对象上的一个点

getCoordinateAt(fraction) → {module:basetype~Coordinate}

从几何对象开始的位置,按照比例因子匹配最接近索引的坐标。若比例因子对应的位置正好在两个点的中间,则返回后面的点。

Parameters:
Name Type Description
fraction Number

比例因子,范围为[0,1]。0表示起点,1表示终点

Returns:
module:basetype~Coordinate -

匹配到的坐标

Example
let result = linearRing.getCoordinateAt(0.4);

getCoordSeq(startIndex, endIndex) → {module:basetype~CoordSeq}

提取几何对象的坐标序列。从起始索引开始提取,取到结束索引的前一位,即按“前闭后开”的原则进行提取坐标。
1.当startIndex小于0时则取0,当endIndex大于坐标序列长度时取坐标序列长度;
2.当endIndex未传入时,返回startIndex以后的Coordinate;
3.如果startIndex与endIndex参数为空,返回所有Coordinate。
4.当startIndex大于等于endIndex,返回空数组。

Parameters:
Name Type Default Description
startIndex Number 0

起始索引。如果不传,默认是0

endIndex Number

结束索引。如果不传,默认是坐标序列长度值

Returns:
module:basetype~CoordSeq -

坐标序列

Example
let result = linearRing.getCoordSeq(0,1);

getExtent() → {module:basetype~Extent}

计算线环的地理范围。该地理范围界定了X-Y平面的边界,不含高程信息。

Returns:
module:basetype~Extent -

返回线环的地理范围

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let point1 = new hmap.geom.Point(coord1);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let point2 = new hmap.geom.Point(coord2);
let coord3 = new hmap.basetype.Coordinate(122,30,0);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);
let extent = linearRing.getExtent();

getLength(srid) → {Number}

计算线环的三维长度。每个线段长度的计算:根据每截线段在球面上投影的长度和两端点高差平方和,对其取开平方。

Parameters:
Name Type Description
srid String

坐标系SRID。默认4326(坐标系为WGS84)

Returns:
Number -

线环的三维长度,单位是米

Example
let result = linearRing.getLength(4326);

getType() → {String}

获取几何对象类型。

Returns:
String -

几何对象类型

Example
let type = linearRing.getType();

getVertices() → {Array.<module:geom~Point>}

获取当前几何对象的所有节点。

Returns:
Array.<module:geom~Point> -

节点数组

intersectsExtent(extent) → {Boolean}

检测几何对象与地理范围是否相交。

Parameters:
Name Type Description
extent module:basetype~Extent

地理范围

Returns:
Boolean -

为true时表示相交,为false时表示不相交

intersectsGeometry(geom) → {Boolean}

检测与另一个几何对象是否相交。

Parameters:
Name Type Description
geom module:geom~Geometry

另一个几何对象

Returns:
Boolean -

返回true表示相交;返回false表示不相交

isSelfIntersects() → {Boolean}

自相交判断。

Returns:
Boolean -

true表示自相交,false表示不自相交

moveByDelta(deltaX, deltaY, deltaZ) → {module:geom~LinearRing}

将几何对象的所有坐标按给定的参数偏移。如果参数为负,则向坐标轴负向偏移。该方法可能改变原几何对象的位置,如果需要保留原几何对象,可以使用clone方法复制为副本

Parameters:
Name Type Default Description
deltaX Number 0

X坐标轴方向的平移量

deltaY Number 0

Y坐标轴方向的平移量

deltaZ Number 0

Z坐标轴方向的平移量

Returns:
module:geom~LinearRing -

移动后的线环几何对象

removeCoord(coord) → {Number}

删除线环几何对象上的一个坐标。

Parameters:
Name Type Description
coord module:basetype~Coordinate

地理坐标

Throws:
TypeError -

当入参coord不是一个地理坐标时,抛出对象类型异常

Returns:
Number -

删除个数。因构成线环的点数不能少于3,即删除后线环点数小于3,则删除失败,删除个数为0

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let coord3 = new hmap.basetype.Coordinate(122,30,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let point3 = new hmap.geom.Point(coord3);
let linearRing = new hmap.geom.LinearRing([point1,point2,point3]);
let coord4 = new hmap.basetype.Coordinate(120,30,0);
let result = linearRing.removeCoord(coord4);//result=0

rotate(axis, angle, center) → {module:geom~LinearRing}

绕着指定直线(旋转轴)旋转,所指定的直线穿过给定点且平行于坐标轴。旋转后的坐标可能发生变化。绕轴旋转的本质如下: 绕平行于Z轴的直线旋转即是在XY平面内旋转;绕平行于X轴的直线旋转即是在YZ平面内旋转;绕平行于Y轴的直线旋转即是在XZ平面内旋转

Parameters:
Name Type Description
axis String

坐标轴,旋转轴平行于该坐标轴并与坐标轴同向。可选值为"X","Y","Z",默认值为Z

angle Number

旋转的角度,超过360度时,取angle/360的余数。逆时针旋转为正,顺时针旋转为负

center module:basetype~Coordinate

旋转轴所穿过的点,可选项。该参数为空时,绕坐标轴旋转

Returns:
module:geom~LinearRing -

旋转后的几何对象。

scale(xFactor, yFactor, zFactor, origin) → {module:geom~LinearRing}

按各坐标轴的缩放比例和指定的缩放原点进行缩放几何对象。该方法可能改变原几何对象的坐标值,如果需要保留原几何对象,可以使用clone方法复制作为副本。

Parameters:
Name Type Default Description
xFactor Number

X坐标值缩放比例,必须大于0

yFactor Number

Y坐标值缩放比例,必须大于0

zFactor Number 1

Z坐标值缩放比例,在2D中默认为1。无法改变

origin module:basetype~Coordinate

缩放原点,以该点为参考点进行缩放。默认以几何对象地理范围的中心点进行缩放

Throws:
  • RangeError -

    当xFactor, yFactor值不为正时

  • TypeError -

    origin类型错误时

Returns:
module:geom~LinearRing -

返回缩放后的几何对象

simplify(tolerance) → {module:geom~LinearRing}

简化线环。在尽可能不改变原几何对象形状的情况下,减少构成线环的坐标数量。(采用道格拉斯-普克算法,线环中应至少包含三个点,若点个数小于3,则不做任何处理)

Parameters:
Name Type Description
tolerance Number

容差值,大于等于0,单位和地图单位一致。容差值越大,构成几何对象的坐标数量越少。

Returns:
module:geom~LinearRing -

返回简化后的线环

toPolygon() → {module:geom~Polygon}

将线环转化为多边形。

Returns:
module:geom~Polygon -

多边形

transform(source, destination) → {module:geom~Line}

将一个线状几何对象中点所对应的地理坐标从源坐标系转换到目标坐标系。该方法可能改变原几何对象的坐标值,如果需要保留原几何对象,可以使用clone方法复制为副本。

Parameters:
Name Type Description
source String

源坐标系。考虑到实际转换时,数据量可能较大,故传入CRS的SRID,而非CRS实例,以减少CRS实例数量,进而降低内存成本

destination String

目标坐标系。

Returns:
module:geom~Line -

坐标转换后的几何对象。