Summary
Methods:
| readFeature |
将一个WKT字符串转换成矢量地理要素。当参数不符合WKT标准时,返回null。 |
| readGeometry |
将WKT字符串转为地理几何体。当参数不符合WKT标准时,返回null。 |
| writeFeature |
把一个矢量地理要素编码成WKT字符串。 |
| writeGeometry |
将一个地理几何体编码成WKT字符串。 |
Constructor
new WKT()
Example
let wkt = new hmap.format.WKT();
Methods
-
readFeature(wktstr) → {module:feature~Vector|null}
-
将一个WKT字符串转换成矢量地理要素。当参数不符合WKT标准时,返回null。
Parameters:
Name Type Description wktstrString WKT格式的字符串。支持POINT、LINESTRING、POLYGON、MULTIPOINT、MULTILINESTRING、MULTIPOLYGON、GEOMETRYCOLLECTION
Example
let wkt = new hmap.format.WKT(); let pointWKT="POINT Z(1 2 3)"; let feature = wkt.readFeature(pointWKT); -
readGeometry(wktstr) → {module:geom~Geometry|null}
-
将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里的每一个坐标只包含x、y值,舍弃了z值。
Throws:
当参数不是 hmap.feature.Vector实例时,抛出异常
Returns:
String -WKT格式的字符串。
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字符串。
下面3种情况将返回空字符串:
1.传入的geom不是一个地理几何对象;
2.传入的geom为不支持的地理几何对象;
3.传入的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里的每一个坐标只包含x、y值,舍弃了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);