Socket
Socket
Sign inDemoInstall

geohash-poly

Package Overview
Dependencies
70
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.0 to 0.4.0

46

index.js

@@ -6,3 +6,4 @@ var Readable = require('stream').Readable,

through2 = require('through2'),
async = require('async');
async = require('async'),
geojsonArea = require('geojson-area');

@@ -40,3 +41,4 @@ /**

splitAt: 2000,
hashMode: 'inside'
hashMode: 'inside',
threshold: 0
};

@@ -148,3 +150,7 @@ options = options || {};

while (columnHash != westerly) {
if(self.hashMode !== 'inside' || inside(columnCenter, prepared)) rowHashes.push(columnHash);
if(self.hashMode === 'inside' && inside(columnCenter, prepared)) {
rowHashes.push(columnHash);
} else if (self.hashMode === 'intersect' || self.hashMode === 'extent') {
rowHashes.push(columnHash);
}
columnHash = geohash.neighbor(columnHash, [0, 1]);

@@ -166,4 +172,33 @@ columnCenter = geohash.decode(columnHash);

}
done(null, rowHashes);
if(self.hashMode === 'inside' || self.hashMode === 'extent' || !rowHashes.length) {
done(null, rowHashes);
} else if (self.hashMode === 'intersect') {
var baseArea = null;
async.filter(rowHashes, function (h, cb) {
var bb = geohash.decode_bbox(h);
bb = turf.polygon([[
[bb[1], bb[2]],
[bb[3], bb[2]],
[bb[3], bb[0]],
[bb[1], bb[0]],
[bb[1], bb[2]]
]]);
if(!baseArea) baseArea = geojsonArea.geometry(bb.geometry);
turf.intersect(turf.featurecollection([turf.polygon(prepared.coordinates)]), turf.featurecollection([bb]), function (err, intersected) {
var keepIntersection = !self.threshold ? true : false;
if(self.threshold && intersected.features.length && (intersected.features[0].type === 'Polygon' || intersected.features[0].type === 'MultiPolygon')) {
var intersectedArea = geojsonArea.geometry(intersected.features[0]);
keepIntersection = baseArea && intersectedArea / baseArea >= self.threshold;
}
cb(keepIntersection);
});
}, function (results) {
done(null, results);
});
}
});

@@ -213,4 +248,5 @@ };

rowMode: options.rowMode ? true : false,
hashMode: options.hashMode
hashMode: options.hashMode,
threshold: options.threshold
});
};

5

package.json
{
"name": "geohash-poly",
"version": "0.3.0",
"version": "0.4.0",
"description": "Transform a GeoJSON Polygon or MultiPolygon to a list of geohashes that form it.",

@@ -22,3 +22,4 @@ "main": "index.js",

"async": "~0.2.10",
"through2": "~0.4.0"
"through2": "~0.4.0",
"geojson-area": "^0.1.0"
},

@@ -25,0 +26,0 @@ "devDependencies": {

@@ -72,1 +72,2 @@ # Geohash-poly

- `'extent'`: return all hashes which make up the bounding box of the shape.
- `'intersect'`: return all hashes that intersect with the shape. Use the `'threshold'` option to specify a percentage of least coverage. See `examples/streaming.js`.

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc