@turf/flip
Advanced tools
Comparing version 4.1.0 to 4.2.0
/// <reference types="geojson" /> | ||
type Points = GeoJSON.FeatureCollection<GeoJSON.Point>; | ||
type Point = GeoJSON.Feature<GeoJSON.Point>; | ||
type MultiPoints = GeoJSON.FeatureCollection<GeoJSON.MultiPoint>; | ||
type MultiPoint = GeoJSON.Feature<GeoJSON.MultiPoint>; | ||
type LineStrings = GeoJSON.FeatureCollection<GeoJSON.LineString>; | ||
type LineString = GeoJSON.Feature<GeoJSON.LineString>; | ||
type MultiLineStrings = GeoJSON.FeatureCollection<GeoJSON.MultiLineString>; | ||
type MultiLineString = GeoJSON.Feature<GeoJSON.MultiLineString>; | ||
type Polygons = GeoJSON.FeatureCollection<GeoJSON.Polygon>; | ||
type Polygon = GeoJSON.Feature<GeoJSON.Polygon>; | ||
type MultiPolygons = GeoJSON.FeatureCollection<GeoJSON.MultiPolygon>; | ||
type MultiPolygon = GeoJSON.Feature<GeoJSON.MultiPolygon>; | ||
type Feature = GeoJSON.Feature<any>; | ||
type Features = GeoJSON.FeatureCollection<any>; | ||
type Feature = GeoJSON.Feature<any>; | ||
type Geometry = GeoJSON.GeometryObject; | ||
type Geometries = GeoJSON.GeometryCollection; | ||
interface FlipStatic { | ||
/** | ||
* http://turfjs.org/docs/#flip | ||
*/ | ||
(features: Point): Point; | ||
(features: Points): Points; | ||
(features: MultiPoint): MultiPoint; | ||
(features: MultiPoints): MultiPoints; | ||
(features: LineString): LineString; | ||
(features: LineStrings): LineStrings; | ||
(features: MultiLineString): MultiLineString; | ||
(features: MultiLineStrings): MultiLineStrings; | ||
(features: Polygon): Polygon; | ||
(features: Polygons): Polygons; | ||
(features: MultiPolygon): MultiPolygon; | ||
(features: MultiPolygons): MultiPolygons; | ||
(features: Feature): Feature; | ||
(features: Features): Features; | ||
} | ||
declare const flip: FlipStatic; | ||
declare function flip<T extends Features|Feature|Geometry|Geometries>(geojson: T, mutate?: boolean): T | ||
declare namespace flip { } | ||
export = flip; |
27
index.js
var coordEach = require('@turf/meta').coordEach; | ||
/** | ||
* Takes input features and flips all of their coordinates | ||
* from `[x, y]` to `[y, x]`. | ||
* Takes input features and flips all of their coordinates from `[x, y]` to `[y, x]`. | ||
* | ||
* @name flip | ||
* @param {(Feature|FeatureCollection)} input input features | ||
* @returns {(Feature|FeatureCollection)} a feature or set of features of the same type as `input` with flipped coordinates | ||
* @param {FeatureCollection|Feature<any>} geojson input features | ||
* @param {boolean} [mutate=false] allows GeoJSON input to be mutated (significant performance increase if true) | ||
* @returns {FeatureCollection|Feature<any>} a feature or set of features of the same type as `input` with flipped coordinates | ||
* @example | ||
@@ -20,18 +20,21 @@ * var serbia = { | ||
* | ||
* //=serbia | ||
* | ||
* var saudiArabia = turf.flip(serbia); | ||
* | ||
* //=saudiArabia | ||
* //addToMap | ||
* var addToMap = [serbia, saudiArabia] | ||
*/ | ||
module.exports = function flip(input) { | ||
module.exports = function (geojson, mutate) { | ||
if (!geojson) throw new Error('geojson is required'); | ||
// ensure that we don't modify features in-place and changes to the | ||
// output do not change the previous feature, including changes to nested | ||
// properties. | ||
input = JSON.parse(JSON.stringify(input)); | ||
if (mutate === false || mutate === undefined) geojson = JSON.parse(JSON.stringify(geojson)); | ||
coordEach(input, function (coord) { | ||
coord.reverse(); | ||
coordEach(geojson, function (coord) { | ||
var x = coord[0]; | ||
var y = coord[1]; | ||
coord[0] = y; | ||
coord[1] = x; | ||
}); | ||
return input; | ||
return geojson; | ||
}; |
{ | ||
"name": "@turf/flip", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "turf flip module", | ||
@@ -32,9 +32,11 @@ "main": "index.js", | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"tape": "^3.5.0", | ||
"@turf/helpers": "^4.1.0" | ||
"@turf/helpers": "^4.2.0", | ||
"benchmark": "^2.1.4", | ||
"load-json-file": "^2.0.0", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.0.0" | ||
}, | ||
"dependencies": { | ||
"@turf/meta": "^4.1.0" | ||
"@turf/meta": "^4.2.0" | ||
} | ||
} |
@@ -5,8 +5,8 @@ # @turf/flip | ||
Takes input features and flips all of their coordinates | ||
from `[x, y]` to `[y, x]`. | ||
Takes input features and flips all of their coordinates from `[x, y]` to `[y, x]`. | ||
**Parameters** | ||
- `input` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects))** input features | ||
- `geojson` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** input features | ||
- `mutate` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** allows GeoJSON input to be mutated (significant performance increase if true) (optional, default `false`) | ||
@@ -25,10 +25,9 @@ **Examples** | ||
//=serbia | ||
var saudiArabia = turf.flip(serbia); | ||
//=saudiArabia | ||
//addToMap | ||
var addToMap = [serbia, saudiArabia] | ||
``` | ||
Returns **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects))** a feature or set of features of the same type as `input` with flipped coordinates | ||
Returns **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [Feature](http://geojson.org/geojson-spec.html#feature-objects)<any>)** a feature or set of features of the same type as `input` with flipped coordinates | ||
@@ -35,0 +34,0 @@ <!-- This file is automatically generated. Please don't edit it directly: |
5230
5
45
56
Updated@turf/meta@^4.2.0