Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/polygon-to-linestring

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/polygon-to-linestring - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

17

index.d.ts
/// <reference types="geojson" />
type Polygon = GeoJSON.Feature<GeoJSON.Polygon | GeoJSON.MultiPolygon>;
type Lines = GeoJSON.FeatureCollection<GeoJSON.LineString | GeoJSON.MultiLineString>;
type Polygon = GeoJSON.Feature<GeoJSON.Polygon> | GeoJSON.Polygon;
type MultiPolygon = GeoJSON.Feature<GeoJSON.MultiPolygon> | GeoJSON.MultiPolygon;
type Feature = GeoJSON.Feature<GeoJSON.LineString | GeoJSON.MultiLineString>;
type FeatureCollection = GeoJSON.FeatureCollection<GeoJSON.LineString | GeoJSON.MultiLineString>;
declare function polygonToLineString(polygon: Polygon): Lines;
declare namespace polygonToLineString {}
interface PolygonToLineString {
/**
* http://turfjs.org/docs/#polygontolinestring
*/
(polygon: Polygon): Feature;
(polygon: MultiPolygon): FeatureCollection;
}
declare const polygonToLineString: PolygonToLineString
export = polygonToLineString;

@@ -8,24 +8,27 @@ var getCoords = require('@turf/invariant').getCoords;

/**
* Converts a {@link Polygon} or {@link MultiPolygon} to a {@link FeatureCollection} of {@link LineString} or {@link MultiLineString}.
* Converts a {@link Polygon} to {@link LineString|(Multi)LineString} or {@link MultiPolygon} to a {@link FeatureCollection} of {@link LineString|(Multi)LineString}.
*
* @name polygonToLineString
* @param {Feature<Polygon|MultiPolygon>} polygon Feature to convert
* @returns {FeatureCollection<LineString|MultiLinestring>} converted Feature to Lines
* @param {Object} [properties] translates GeoJSON properties to Feature
* @returns {FeatureCollection|Feature<LineString|MultiLinestring>} converted (Multi)Polygon to (Multi)LineString
* @example
* var poly = {
* 'type': 'Feature',
* 'properties': {},
* 'geometry': {
* 'type': 'Polygon',
* 'coordinates': [[[125, -30], [145, -30], [145, -20], [125, -20], [125, -30]]]
* "type": "Feature",
* "properties": {},
* "geometry": {
* "type": "Polygon",
* "coordinates": [[[125, -30], [145, -30], [145, -20], [125, -20], [125, -30]]]
* }
* }
* var lines = turf.polygonToLineString(poly);
* var line = turf.polygonToLineString(poly);
*
* //addToMap
* var addToMap = [lines]
* var addToMap = [line];
*/
module.exports = function (polygon) {
module.exports = function (polygon, properties) {
var geom = getGeomType(polygon);
var coords = getCoords(polygon);
var properties = polygon.properties;
properties = properties || polygon.properties || {};
if (!coords.length) throw new Error('polygon must contain coordinates');

@@ -35,3 +38,3 @@

case 'Polygon':
return featureCollection([coordsToLine(coords, properties)]);
return coordsToLine(coords, properties);
case 'MultiPolygon':

@@ -38,0 +41,0 @@ var lines = [];

{
"name": "@turf/polygon-to-linestring",
"version": "4.1.0",
"version": "4.2.0",
"description": "turf polygon-to-linestring module",

@@ -36,5 +36,5 @@ "main": "index.js",

"dependencies": {
"@turf/helpers": "^4.1.0",
"@turf/invariant": "^4.1.0"
"@turf/helpers": "^4.2.0",
"@turf/invariant": "^4.2.0"
}
}

@@ -5,3 +5,3 @@ # @turf/polygon-to-linestring

Converts a [Polygon](http://geojson.org/geojson-spec.html#polygon) or [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon) to a [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) of [LineString](http://geojson.org/geojson-spec.html#linestring) or [MultiLineString](http://geojson.org/geojson-spec.html#multilinestring).
Converts a [Polygon](http://geojson.org/geojson-spec.html#polygon) to [(Multi)LineString](http://geojson.org/geojson-spec.html#linestring) or [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon) to a [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) of [(Multi)LineString](http://geojson.org/geojson-spec.html#linestring).

@@ -11,2 +11,3 @@ **Parameters**

- `polygon` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))>** Feature to convert
- `properties` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** translates GeoJSON properties to Feature

@@ -17,15 +18,16 @@ **Examples**

var poly = {
'type': 'Feature',
'properties': {},
'geometry': {
'type': 'Polygon',
'coordinates': [[[125, -30], [145, -30], [145, -20], [125, -20], [125, -30]]]
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[125, -30], [145, -30], [145, -20], [125, -20], [125, -30]]]
}
}
var lines = turf.polygonToLineString(poly);
var line = turf.polygonToLineString(poly);
//addToMap
var addToMap = [lines]
var addToMap = [line];
```
Returns **[FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects)&lt;([LineString](http://geojson.org/geojson-spec.html#linestring) | MultiLinestring)>** converted Feature to Lines
Returns **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)&lt;([LineString](http://geojson.org/geojson-spec.html#linestring) | MultiLinestring)>)** converted (Multi)Polygon to (Multi)LineString

@@ -32,0 +34,0 @@ <!-- This file is automatically generated. Please don't edit it directly:

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc