如何将 "POLYGON ((32.5 39.2, 32.6 39.4 .... ))" 之类的几何字符串转换为 Javascript 中的 GeoJSON
How to convert geometry string like "POLYGON ((32.5 39.2, 32.6 39.4 .... ))" to GeoJSON in Javascript
我有像
这样的字符串
POLYGON ((32.5 39.2, 32.6 39.4 .... ))
POINT (32.4 39.2)
使用 Leaflet,React 是否有办法将这些字符串转换为 GeoJSON,例如:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
在 JavaScript?
这些字符串称为 WKT (https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry)。
那里有很多解析器:
https://www.npmjs.com/search?q=wkt
"wellknown"和"wicket"可以输出GeoJSON,可能其他模块也支持这个。
请注意,WKT 仅表示 GeoJSON 中的 "geometry" 字段,"properties" 字段的内容应来自其他地方(假设这是 CSV - 来自其他 CSV 列)。
我有像
这样的字符串POLYGON ((32.5 39.2, 32.6 39.4 .... ))
POINT (32.4 39.2)
使用 Leaflet,React 是否有办法将这些字符串转换为 GeoJSON,例如:
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
在 JavaScript?
这些字符串称为 WKT (https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry)。
那里有很多解析器: https://www.npmjs.com/search?q=wkt
"wellknown"和"wicket"可以输出GeoJSON,可能其他模块也支持这个。
请注意,WKT 仅表示 GeoJSON 中的 "geometry" 字段,"properties" 字段的内容应来自其他地方(假设这是 CSV - 来自其他 CSV 列)。