Giter VIP home page Giter VIP logo

wkt-parser-helper's Introduction

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

Defined in: index.ts:34


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

Defined in: index.ts:24


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

Defined in: index.ts:13


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

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:

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

Defined in: index.ts:71

wkt-parser-helper's People

Contributors

alrico88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

qq1530667

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.