简体   繁体   English

如何在 Javascript 中将几何字符串如“POLYGON ((32.5 39.2, 32.6 39.4 ... ))”转换为 GeoJSON

[英]How to convert geometry string like “POLYGON ((32.5 39.2, 32.6 39.4 … ))” to GeoJSON in Javascript

I have strings like我有像这样的字符串

POLYGON ((32.5 39.2, 32.6 39.4 .... ))
POINT (32.4 39.2)

using Leaflet, React is there a way to convert these string to GeoJSON like:使用 Leaflet,React 有没有办法将这些字符串转换为 GeoJSON,如:

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

in JavaScript?在 JavaScript 中?

These strings are called WKT ( https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry ).这些字符串称为 WKT ( https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry )。

There are quite a few parsers out there: https://www.npmjs.com/search?q=wkt那里有很多解析器: https://www.npmjs.com/search?q=wkt

"wellknown" and "wicket" can output GeoJSON, probably there are other modules that support this too. “wellknown” 和 “wicket” 可以 output GeoJSON,可能还有其他模块也支持这个。

Note that WKT represents just "geometry" field in GeoJSON, content of "properties" field should come from somewhere else (say if this was CSV - from other CSV columns).请注意,WKT 仅代表 GeoJSON 中的“几何”字段,“属性”字段的内容应该来自其他地方(例如,如果这是 CSV - 来自其他 CSV 列)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM