Socket
Socket
Sign inDemoInstall

wkt-parser-helper

Package Overview
Dependencies
11
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    wkt-parser-helper

Module to help parse GeoJSONs to WKT and back


Version published
Weekly downloads
1.8K
increased by36.59%
Maintainers
1
Install size
368 kB
Created
Weekly downloads
 

Readme

Source

wkt-parser-helper

Convert and parse between Well-Known-Text (WKT) and GeoJSON

Installation

Using npm npm i wkt-parser-helper

Using yarn yarn add wkt-parser-helper

Usage

In CommonJS env

const { parseFromWK } = require('wkt-parser-helper');

const geojson = parseFromWK(
  'POLYGON ((-3.706512451171875 40.420074462890625, -3.70513916015625 40.420074462890625, -3.70513916015625 40.42144775390625, -3.706512451171875 40.42144775390625, -3.706512451171875 40.420074462890625))'
);

// geojson is a Polygon Geometry

Using imports

import { convertToWK } from 'wkt-parser-helper';

const myFeature: Feature = {
  type: 'Feature',
  properties: {},
  geometry: {
    type: 'Polygon',
    coordinates: [
      [
        [-3.706512451171875, 40.420074462890625],
        [-3.70513916015625, 40.420074462890625],
        [-3.70513916015625, 40.42144775390625],
        [-3.706512451171875, 40.42144775390625],
        [-3.706512451171875, 40.420074462890625],
      ],
    ],
  },
};

const myFeatureAsWKT = convertToWK(myFeature);

// myFeatureAsWKT is 'POLYGON ((-3.706512451171875 40.420074462890625, -3.70513916015625 40.420074462890625, -3.70513916015625 40.42144775390625, -3.706512451171875 40.42144775390625, -3.706512451171875 40.420074462890625))'

Breaking changes

From v4.0.0 onwards, support for converting GeoJSON to WKB is dropped.

Table of contents

Functions

  • convertFeatureCollection
  • convertFeatureToWK
  • convertGeometryToWK
  • convertToWK
  • parseFromWK

Functions

convertFeatureCollection

convertFeatureCollection(featureCollection: FeatureCollection): string

Converts a GeoJSON FeatureCollection to WKT GeometryCollection

export

Parameters:
NameTypeDescription
featureCollectionFeatureCollectionThe FeatureCollection to convert to WKT

Returns: string

The GeoJSON converted to well known representation

Defined in: index.ts:34


convertFeatureToWK

convertFeatureToWK(geojson: Feature): string

Converts GeoJSON Feature to WKT

export

Parameters:
NameTypeDescription
geojsonFeatureFeature object to convert

Returns: string

The GeoJSON converted to well known text representation

Defined in: index.ts:24


convertGeometryToWK

convertGeometryToWK(geojson: Geometry): string

Converts GeoJSON Geometry to WKT

export

Parameters:
NameTypeDescription
geojsonGeometryGeometry object to convert

Returns: string

The GeoJSON converted to well known text representation

Defined in: index.ts:13


convertToWK

convertToWK(geojson: GeoJSON): string

Shorthand to convert GeoJSON Features, Geometries or FeatureCollections to WKT or WKB

export

Parameters:
NameTypeDescription
geojsonGeoJSONThe GeoJSON to convert

Returns: string

The GeoJSON as WKT

Defined in: index.ts:51


parseFromWK

parseFromWK(item: string, asFeature?: boolean, properties?: GeoJsonProperties): Feature | Geometry

Parse a WKT or WKB into a GeoJSON Feature or Geometry

export

Parameters:
NameTypeDefault valueDescription
itemstring-The WKT to convert to GeoJSON
asFeaturebooleanfalse-
propertiesGeoJsonProperties--

Returns: Feature | Geometry

The WKT as GeoJSON

Defined in: index.ts:71

Keywords

FAQs

Last updated on 11 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc