Comparing version 1.0.1 to 3.0.0-canary.2f5f7167
@@ -5,4 +5,4 @@ var tag = require('./'); | ||
var points = JSON.parse(fs.readFileSync('./geojson/tagPoints.geojson')); | ||
var polygons = JSON.parse(fs.readFileSync('./geojson/tagPolygons.geojson')); | ||
var points = JSON.parse(fs.readFileSync('./test/tagPoints.geojson')); | ||
var polygons = JSON.parse(fs.readFileSync('./test/tagPolygons.geojson')); | ||
@@ -20,2 +20,2 @@ var suite = new Benchmark.Suite('turf-tag'); | ||
}) | ||
.run(); | ||
.run(); |
46
index.js
var inside = require('turf-inside'); | ||
/** | ||
* Takes a {@link FeatureCollection} of {@link Point} features and a FeatureCollection of {@link Polygon} features and performs a spatial join. | ||
* Takes a set of {@link Point|points} and a set of {@link Polygon|polygons} and performs a spatial join. | ||
* | ||
* @module turf/tag | ||
* @name tag | ||
* @category joins | ||
* @param {FeatureCollection} points a FeatureCollection of {@link Point} features | ||
* @param {FeatureCollection} polygons a FeatureCollection of {@link Polygon} features | ||
* @param {FeatureCollection<Point>} points input points | ||
* @param {FeatureCollection<Polygon>} polygons input polygons | ||
* @param {String} polyId property in `polygons` to add to joined Point features | ||
* @param {String} containingPolyId property in `points` in which to store joined property from `polygons | ||
* @return {FeatureCollection} a FeatureCollection of point features | ||
* @return {FeatureCollection<Point>} points with `containingPolyId` property containing values from `polyId` | ||
* @example | ||
* var bbox = [0, 0, 50, 50]; | ||
* var bbox = [0, 0, 10, 10]; | ||
* // create a triangular grid of polygons | ||
* var triangleGrid = turf.tin(turf.grid(bbox, 10)); | ||
* var triangleGrid = turf.triangleGrid(bbox, 50, 'miles'); | ||
* triangleGrid.features.forEach(function(f) { | ||
@@ -38,20 +38,20 @@ * f.properties.fill = '#' + | ||
*/ | ||
module.exports = function(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) { | ||
if (pt.properties[outField] === undefined) { | ||
var isInside = inside(pt, poly); | ||
if (isInside) { | ||
pt.properties[outField] = poly.properties[field]; | ||
module.exports = function (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) { | ||
if (pt.properties[outField] === undefined) { | ||
var isInside = inside(pt, poly); | ||
if (isInside) { | ||
pt.properties[outField] = poly.properties[field]; | ||
} | ||
} | ||
}); | ||
}); | ||
}); | ||
return points; | ||
return points; | ||
}; |
{ | ||
"name": "turf-tag", | ||
"version": "1.0.1", | ||
"version": "3.0.0-canary.2f5f7167", | ||
"description": "turf tag module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test.js", | ||
"doc": "dox -r < index.js | doxme --readme > README.md" | ||
"test": "node test.js" | ||
}, | ||
@@ -31,10 +30,8 @@ "repository": { | ||
"dependencies": { | ||
"turf-inside": "^1.1.3" | ||
"turf-inside": "^3.0.0-canary.2f5f7167" | ||
}, | ||
"devDependencies": { | ||
"benchmark": "^1.0.0", | ||
"tape": "^3.5.0", | ||
"dox": "^0.6.1", | ||
"doxme": "^1.4.3" | ||
"tape": "^3.5.0" | ||
} | ||
} |
@@ -10,3 +10,3 @@ # turf-tag | ||
Takes a FeatureCollection of Point features and a FeatureCollection of Polygon features and performs a spatial join. | ||
Takes a set of Point|points and a set of Polygon|polygons and performs a spatial join. | ||
@@ -16,8 +16,8 @@ | ||
| parameter | type | description | | ||
| ------------------ | ----------------- | --------------------------------------------------------------------- | | ||
| `points` | FeatureCollection | a FeatureCollection of Point features | | ||
| `polygons` | FeatureCollection | a FeatureCollection of Polygon features | | ||
| `polyId` | String | property in `polygons` to add to joined Point features | | ||
| `containingPolyId` | String | property in `points` in which to store joined property from `polygons | | ||
| parameter | type | description | | ||
| ------------------ | ------------------------------ | --------------------------------------------------------------------- | | ||
| `points` | FeatureCollection\.\<Point\> | input points | | ||
| `polygons` | FeatureCollection\.\<Polygon\> | input polygons | | ||
| `polyId` | String | property in `polygons` to add to joined Point features | | ||
| `containingPolyId` | String | property in `points` in which to store joined property from `polygons | | ||
@@ -28,5 +28,5 @@ | ||
```js | ||
var bbox = [0, 0, 50, 50]; | ||
var bbox = [0, 0, 10, 10]; | ||
// create a triangular grid of polygons | ||
var triangleGrid = turf.tin(turf.grid(bbox, 10)); | ||
var triangleGrid = turf.triangleGrid(bbox, 50, 'miles'); | ||
triangleGrid.features.forEach(function(f) { | ||
@@ -54,2 +54,5 @@ f.properties.fill = '#' + | ||
**Returns** `FeatureCollection.<Point>`, points with `containingPolyId` property containing values from `polyId` | ||
## Installation | ||
@@ -69,1 +72,2 @@ | ||
@@ -6,4 +6,4 @@ var test = require('tape'); | ||
test('tag', function(t){ | ||
var points = JSON.parse(fs.readFileSync(__dirname + '/geojson/tagPoints.geojson')); | ||
var polygons = JSON.parse(fs.readFileSync(__dirname + '/geojson/tagPolygons.geojson')); | ||
var points = JSON.parse(fs.readFileSync(__dirname + '/test/tagPoints.geojson')); | ||
var polygons = JSON.parse(fs.readFileSync(__dirname + '/test/tagPolygons.geojson')); | ||
@@ -10,0 +10,0 @@ var taggedPoints = tag(points, polygons, 'polyID', 'containingPolyID'); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
2
87
0
69
7053
7
1
1
+ Addedturf-inside@3.0.12(transitive)
+ Addedturf-invariant@3.0.12(transitive)
- Removedminimist@1.2.8(transitive)
- Removedturf-inside@1.1.4(transitive)