简体   繁体   中英

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:

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

in JavaScript?

These strings are called 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

"wellknown" and "wicket" can output GeoJSON, probably there are other modules that support this too.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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