Comparing version 4.7.3 to 5.0.4
@@ -1,12 +0,11 @@ | ||
/// <reference types="geojson" /> | ||
import { BBox, Point, FeatureCollection, Polygon } from '@turf/helpers' | ||
type BBox = Array<number>; | ||
type Points = GeoJSON.FeatureCollection<GeoJSON.Point>; | ||
type Polygons = GeoJSON.FeatureCollection<GeoJSON.Polygon>; | ||
/** | ||
* http://turfjs.org/docs/#tag | ||
*/ | ||
declare function tag(points: Points, polygons: Polygons, field: string, outField: string): Points; | ||
declare namespace tag { } | ||
export = tag; | ||
export default function tag( | ||
points: FeatureCollection<Point>, | ||
polygons: FeatureCollection<Polygon>, | ||
field: string, | ||
outField: string | ||
): FeatureCollection<Point>; |
27
index.js
@@ -1,2 +0,4 @@ | ||
var inside = require('@turf/inside'); | ||
import booleanPointInPolygon from '@turf/boolean-point-in-polygon'; | ||
import clone from '@turf/clone'; | ||
import { featureEach } from '@turf/meta'; | ||
@@ -38,16 +40,11 @@ /** | ||
*/ | ||
module.exports = function (points, polygons, field, outField) { | ||
function tag(points, polygons, field, outField) { | ||
// prevent mutations | ||
points = JSON.parse(JSON.stringify(points)); | ||
polygons = JSON.parse(JSON.stringify(polygons)); | ||
points.features.forEach(function (pt) { | ||
if (!pt.properties) { | ||
pt.properties = {}; | ||
} | ||
polygons.features.forEach(function (poly) { | ||
points = clone(points); | ||
polygons = clone(polygons); | ||
featureEach(points, function (pt) { | ||
if (!pt.properties) pt.properties = {}; | ||
featureEach(polygons, function (poly) { | ||
if (pt.properties[outField] === undefined) { | ||
var isInside = inside(pt, poly); | ||
if (isInside) { | ||
pt.properties[outField] = poly.properties[field]; | ||
} | ||
if (booleanPointInPolygon(pt, poly)) pt.properties[outField] = poly.properties[field]; | ||
} | ||
@@ -57,2 +54,4 @@ }); | ||
return points; | ||
}; | ||
} | ||
export default tag; |
{ | ||
"name": "@turf/tag", | ||
"version": "4.7.3", | ||
"version": "5.0.4", | ||
"description": "turf tag module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -36,8 +40,18 @@ "repository": { | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"tape": "^4.6.3" | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/inside": "^4.7.3" | ||
"@turf/boolean-point-in-polygon": "^5.0.4", | ||
"@turf/clone": "^5.0.4", | ||
"@turf/helpers": "^5.0.4", | ||
"@turf/meta": "^5.0.4" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/tag | ||
# tag | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## tag | ||
Takes a set of [points](http://geojson.org/geojson-spec.html#point) and a set of [polygons](http://geojson.org/geojson-spec.html#polygon) and performs a spatial join. | ||
@@ -6,0 +8,0 @@ |
8664
6
119
71
4
5
+ Added@turf/clone@^5.0.4
+ Added@turf/helpers@^5.0.4
+ Added@turf/meta@^5.0.4
+ Added@turf/boolean-point-in-polygon@5.1.5(transitive)
+ Added@turf/clone@5.1.5(transitive)
+ Added@turf/helpers@5.1.5(transitive)
+ Added@turf/invariant@5.2.0(transitive)
+ Added@turf/meta@5.2.0(transitive)
- Removed@turf/inside@^4.7.3
- Removed@turf/inside@4.7.3(transitive)
- Removed@turf/invariant@4.7.3(transitive)