geojs
geojs copied to clipboard
Add support for parsing Well Known Text (WKT) Geometry
WKT projection strings are supported in https://github.com/proj4js/wkt-parser but geometry are not.
This (seemingly no longer maintained) project has support for converting WKT geometry to GeoJSON: https://github.com/mapbox/wellknown.
I see a few potential ways to use this existing tool to support WKT in GeoJS:
- Since
mapbox/wellknown
appears to be an old project and has a permissive license, we could adopt some of the code to create our own WKT reader directly in GeoJS. - We could fork the project, update it, and use this maintained version as a dependency for a new WKT reader in GeoJS.
- We could fork the project, update it, and use it in downstream apps to convert WKT to GeoJSON as needed and then read that with the existing
geojsonReader
in GeoJS (not affecting the GeoJS code base at all)
Thoughts on a path forward for supporting WKT? I understand introducing a new dependency is something to approach with caution.
Example data:
SRID=4326;POLYGON ((-128.5300591082298 51.77034988853305, -65.39464888719978 51.77034988853305, -65.39464888719978 22.47939186951065, -128.5300591082298 22.47939186951065, -128.5300591082298 51.77034988853305))
I don't know the merits of the different wkt libraries, but a quick look also shows https://github.com/Esri/terraformer-wkt-parser. That project has been more active recently and appears to have more use.
I think the right way to do this is probably to create a wktReader
analog to the geojsonReader
. We also want to make sure there are convenience functions exposed for converting between the two so that using them with, for instance, annotations would be something like geojson_to_wkt(annotationLayer.geojson())
or annotationLayer.geojson(wkt_to_geojson(wkt))
(or whatever the functions are called).
terraformer could be another good one, I have looked into it as well. Having some capabilities in geojs to read wkt would be nice even if it call a third party library to do the job so perhaps option 2 or 3 might be optimal