geom~Line(points)

线状几何对象,由两个或两个以上的点组成。

Summary

Methods:
fromCoordSeq

将一个坐标序列转化成线对象。

fromExtent

将地理范围转换成线状对象。

_angularDis

两个坐标之间的大圆弧度

_intermediate

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

addCoord

把传入的坐标追加到线的坐标数组中。
1.如果index大于线的坐标数组长度,新坐标将被追加到线的坐标数组末尾;
2.如果index小于0,新坐标将被添加到坐标数组的起始位置;
3.如果index不传,则将新坐标自动追加到线的坐标数组末尾。

applyTransform

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

atApproximatePoint

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

clone

复制一个线对象。

copyTo

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

destroy

销毁对象。

distanceTo

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

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

计算线段的三维长度。每个线段长度的计算:假设线在球面上投影的长度dL和两端点高差dH,则线段长度为Math.sqrt(dLdl+dHdH)。

getType

获取几何对象类型。

getVertices

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

intersectsExtent

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

intersectsGeometry

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

isSelfIntersects

自相交判断。

moveByDelta

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

removeCoord

从线中删除与指定坐标地理位置相同的点。注意:删除后,如果剩余的点数量为1,那么将把仅剩的点复制一次,与复制前的坐标一起组成线。

rotate

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

scale

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

simplify

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

transform

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

Constructor

new Line(points)

构造一条线,构成一条线需要至少两个{module:geom~Point}对象。

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

点对象组成的数组

Example
let coord = new hmap.basetype.Coordinate(120,30,0);
let point1 = new hmap.geom.Point(coord);
let point2 = new hmap.geom.Point(coord);
let line = new hmap.geom.Line([point1,point2]);

Methods

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

将一个坐标序列转化成线对象。

Parameters:
Name Type Description
coordSeq module:basetype~CoordSeq

坐标序列

Returns:
module:geom~Line -

生成的线对象

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

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

将地理范围转换成线状对象。

Parameters:
Name Type Description
extent module:basetype~Extent

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

Returns:
module:geom~Line -

线状几何体

Example
let line = Line.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)

把传入的坐标追加到线的坐标数组中。
1.如果index大于线的坐标数组长度,新坐标将被追加到线的坐标数组末尾;
2.如果index小于0,新坐标将被添加到坐标数组的起始位置;
3.如果index不传,则将新坐标自动追加到线的坐标数组末尾。

Parameters:
Name Type Description
coord module:basetype~Coordinate

新的坐标,此坐标将被加入到线的坐标数组中

index Number

在坐标数组中的索引

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let line = new hmap.geom.Line([point1,point2]);
let coord = new hmap.basetype.Coordinate(122,32,0);
line.addCoord(coord,2);
let result = line.getCoordSeq();

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~Line}

复制一个线对象。

Returns:
module:geom~Line -

新的线。

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

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

Parameters:
Name Type Description
coordinate module:basetype~Coordinate

地理坐标

Returns:
module:geom~Geometry -

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

destroy()

销毁对象。

Example
let coord = new hmap.basetype.Coordinate(120,30,0);
let point1 = new hmap.geom.Point(coord);
let point2 = new hmap.geom.Point(coord);
let line = new hmap.geom.Line([point1,point2]);
line.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

getBBox() → {module:basetype~BBox}

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

Returns:
module:basetype~BBox -

返回三维包围盒

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

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

Parameters:
Name Type Default Description
dist Number

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

endCap String ROUND

端点类型。"ROUND":圆角."FLAT":平角。默认"ROUND"

sideSign Number 0

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

Returns:
module:geom~Polygon -

返回一个面状几何对象

getCentroid() → {module:basetype~Coordinate}

获取线的质心坐标。

Returns:
module:basetype~Coordinate -

线的质心坐标

Example
let point1 = new hmap.geom.Point(new hmap.basetype.Coordinate(120,30,0));
let point2 = new hmap.geom.Point(new hmap.basetype.Coordinate(121,31,2));
let line = new hmap.geom.Line([point1,point2]);
line.getCentroid();

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 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 line = new hmap.geom.Line([point1,point2]);
let result = line.getCoordinateAt(0.4);//result=new hmap.basetype.Coordinate(120,30,0)

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 coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,0);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let line = new hmap.geom.Line([point1,point2]);
let result = line.getCoordSeq(0,1);

getExtent() → {module:basetype~Extent}

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

Returns:
module:basetype~Extent -

返回几何对象的地理范围

Example
let extent = line.getExtent();

getLength(srid) → {Number}

计算线段的三维长度。每个线段长度的计算:假设线在球面上投影的长度dL和两端点高差dH,则线段长度为Math.sqrt(dLdl+dHdH)。

Parameters:
Name Type Description
srid String

坐标系类型

Returns:
Number -

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

Example
let coord1 = new hmap.basetype.Coordinate(120,30,0);
let coord2 = new hmap.basetype.Coordinate(121,31,2);
let point1 = new hmap.geom.Point(coord1);
let point2 = new hmap.geom.Point(coord2);
let line = new hmap.geom.Line([point1,point2]);
let result = line.getLength(4326);

getType() → {String}

获取几何对象类型。

Returns:
String -

几何对象类型

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~Line}

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

Parameters:
Name Type Default Description
deltaX Number 0

X坐标轴方向的平移量

deltaY Number 0

Y坐标轴方向的平移量

deltaZ Number 0

Z坐标轴方向的平移量

Returns:
module:geom~Line -

移动后的几何对象

removeCoord(coord) → {Number}

从线中删除与指定坐标地理位置相同的点。注意:删除后,如果剩余的点数量为1,那么将把仅剩的点复制一次,与复制前的坐标一起组成线。

Parameters:
Name Type Description
coord module:basetype~Coordinate

地理坐标

Returns:
Number -

删除点的个数。传入参数异常则返回-1

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,2);
let point2 = new hmap.geom.Point(coord2);
let line = new hmap.geom.Line([point1,point2]);
let result = line.removeCoord(coord1);

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

绕着指定直线(旋转轴)旋转,所指定的直线穿过给定点且平行于坐标轴。旋转后的坐标可能发生变化。绕轴旋转的本质如下: 绕平行于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~Line -

旋转后的几何对象。

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

按缩放比例和缩放原点缩放几何对象。该方法可能改变原几何对象的坐标值,如果需要保留原几何对象,可以使用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~Line -

返回缩放后的几何对象

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

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

Parameters:
Name Type Description
tolerance Number

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

Returns:
module:geom~Line -

返回简化后的几何对象

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

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

Parameters:
Name Type Description
source String

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

destination String

目标坐标系。

Returns:
module:geom~Line -

坐标转换后的几何对象。