npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wkt-parser-helper

v4.2.0

Published

Module to help parse GeoJSONs to WKT and back

Downloads

7,178

Readme

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

Functions

convertFeatureCollection

convertFeatureCollection(featureCollection: FeatureCollection): string

Converts a GeoJSON FeatureCollection to WKT GeometryCollection

export

Parameters:

| Name | Type | Description | | :------------------ | :---------------- | :-------------------------------------- | | featureCollection | FeatureCollection | The FeatureCollection to convert to WKT |

Returns: string

The GeoJSON converted to well known representation


convertFeatureToWK

convertFeatureToWK(geojson: Feature): string

Converts GeoJSON Feature to WKT

export

Parameters:

| Name | Type | Description | | :-------- | :------ | :------------------------ | | geojson | Feature | Feature object to convert |

Returns: string

The GeoJSON converted to well known text representation


convertGeometryToWK

convertGeometryToWK(geojson: Geometry): string

Converts GeoJSON Geometry to WKT

export

Parameters:

| Name | Type | Description | | :-------- | :------- | :------------------------- | | geojson | Geometry | Geometry object to convert |

Returns: string

The GeoJSON converted to well known text representation


convertFeatureCollectionToWktCollection

convertFeatureCollectionToWktCollection<P>(geojson: FeatureCollection<Geometry, P>): P & { wkt: string }[]

Converts a GeoJSON FeatureCollection into an array of objects where each object contains a WKT (Well-Known Text) string representing the geometry and the properties from the original GeoJSON feature

Type parameters:

| Name | Description | | :--- | :--------------------------------------------- | | P | The type of properties in the GeoJSON features |

Parameters:

| Name | Type | Description | | :-------- | :-------------------------------- | :-------------------------------------------- | | geojson | FeatureCollection<Geometry, P> | The GeoJSON FeatureCollection to be converted |

Returns: P & { wkt: string }[]

)[]} An array of objects where each object contains a wkt string representing the geometry and all the properties from the original GeoJSON feature


convertToWK

convertToWK(geojson: GeoJSON): string

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

export

Parameters:

| Name | Type | Description | | :-------- | :------ | :--------------------- | | geojson | GeoJSON | The GeoJSON to convert |

Returns: string

The GeoJSON as WKT


parseFromWK

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

Parse a WKT or WKB into a GeoJSON Feature or Geometry

export

Parameters:

| Name | Type | Default value | Description | | :----------- | :---------------- | :------------ | :---------------------------- | | item | string | - | The WKT to convert to GeoJSON | | asFeature | boolean | false | - | | properties | GeoJsonProperties | - | - |

Returns: Feature | Geometry

The WKT as GeoJSON