Summary
Methods:
| readFeature |
将一个WKT字符串转换成矢量地理要素。当参数不符合WKT标准时,返回null。 |
| readGeometry |
将WKT字符串转为地理几何体。当参数不符合WKT标准时,返回null。 |
| writeFeature |
把一个矢量地理要素编码成WKT字符串 |
| writeGeometry |
将一个地理几何体编码成WKT字符串。当geom不是一个地理几何对象或者不支持的地理几何对象,或者flag是2和3以外的值时,返回空字符串。 |
Constructor
new WKT()
Example
let wkt = new hmap.format.WKT();
Methods
-
readFeature(wktstr) → {Vector}
-
将一个WKT字符串转换成矢量地理要素。当参数不符合WKT标准时,返回null。
Parameters:
Name Type Description wktstrString WKT格式字符串。支持POINT、LINESTRING、POLYGON、MULTIPOINT、MULTILINESTRING、MULTIPOLYGON、GEOMETRYCOLLECTION
Returns:
Vector -一个地理要素
Example
let wkt = new hmap.format.WKT(); let pointWKT="POINT Z(1 2 3)"; let feature = wkt.readFeature(pointWKT); -
readGeometry(wktstr) → {module:geom~Geometry}
-
将WKT字符串转为地理几何体。当参数不符合WKT标准时,返回null。
Parameters:
Name Type Description wktstrString WKT格式字符串。支持POINT、LINESTRING、POLYGON、MULTIPOINT、MULTILINESTRING、MULTIPOLYGON、GEOMETRYCOLLECTION
Example
let wkt = new hmap.format.WKT(); let polygonWKT="POLYGON Z((1 2 0,2 3 0,2 4 0))"; let result = wkt.readGeometry(polygonWKT); -
writeFeature(vector, flag) → {String}
-
把一个矢量地理要素编码成WKT字符串
Parameters:
Name Type Default Description vectormodule:feature~Vector 矢量地理要素
flagNumber 3 默认是3,转为的wkt包含z值;如果传2,则表示wkt的每一个坐标只包含xy的值,舍弃了z轴
Throws:
当参数不是 hmap.feature.Vector实例时,抛出异常
Returns:
String -编码后的字符串
Example
let wkt = new hmap.format.WKT(); let coord = new Coordinate(120,30,0); let point = new Point(coord); let style = hmap.style.Style.getDefault(); let feature = new Vector(point,{},style); let result = wkt.writeFeature(feature, 3); -
writeGeometry(geom, flag) → {String}
-
将一个地理几何体编码成WKT字符串。当geom不是一个地理几何对象或者不支持的地理几何对象,或者flag是2和3以外的值时,返回空字符串。
Parameters:
Name Type Default Description geommodule:geom~Geometry 一个地理几何体对象,支持:Point、MultiPoint、Line、MultiLine、Polygon、MultiPolygon、Collection、Circle、Rectangle、Triangle
flagNumber 3 默认是3,转为的wkt包含z值;如果传2,则表示wkt的每一个坐标只包含xy的值,舍弃了z轴
Returns:
String -WKT字符串
Example
let wkt = new hmap.format.WKT(); let coord = new Coordinate(120,30,0); let point = new Point(coord); let result1 = wkt.writeGeometry(point,3); let result2 = wkt.writeGeometry(point,2);