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

geojson-project

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geojson-project - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

43

index.js

@@ -0,3 +1,22 @@

/**
* Node & browser script to transform/project geojson coordinates
* @copyright Alexander Milevski <info@w8r.name>
* @preserve
* @license MIT
*/
(function (factory) { // UMD wrapper
if (typeof define === 'function' && define.amd) { // AMD
define(factory);
} else if (typeof module === 'object' &&
typeof module.exports === "object") { // Node/CommonJS
module.exports = factory();
} else { // Browser globals
window.geojsonProject = factory();
}
})(function () {
/**
* Takes in GeoJSON and applies a function to each coordinate,
* with a given context
*
* @param {Object} data GeoJSON

@@ -8,3 +27,3 @@ * @param {Function} project

*/
module.exports = function(data, project, context) {
function geojsonProject (data, project, context) {
data = JSON.parse(JSON.stringify(data));

@@ -25,4 +44,4 @@ if (data.type === 'FeatureCollection') {

module.exports.projectFeature = projectFeature;
module.exports.projectGeometry = projectGeometry;
geojsonProject.projectFeature = projectFeature;
geojsonProject.projectGeometry = projectGeometry;

@@ -36,7 +55,7 @@

*/
function projectFeature(feature, project, context) {
if (feature.type === 'GeometryCollection') {
for (var i = 0, len = feature.geometries.length; i < len; i++) {
feature.geometries[i] =
projectGeometry(feature.geometries[i], project, context);
function projectFeature (feature, project, context) {
if (feature.geometry.type === 'GeometryCollection') {
for (var i = 0, len = feature.geometry.geometries.length; i < len; i++) {
feature.geometry.geometries[i] =
projectGeometry(feature.geometry.geometries[i], project, context);
}

@@ -56,3 +75,3 @@ } else {

*/
function projectGeometry(geometry, project, context) {
function projectGeometry (geometry, project, context) {
var coords = geometry.coordinates;

@@ -98,3 +117,3 @@ switch (geometry.type) {

*/
function projectCoords(coords, levelsDeep, project, context) {
function projectCoords (coords, levelsDeep, project, context) {
var coord, i, len;

@@ -113,1 +132,5 @@ var result = [];

}
return geojsonProject;
});
{
"name": "geojson-project",
"version": "1.0.0",
"version": "1.0.1",
"description": "Util for processing geojson coordinates, in most cases to project them",

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

@@ -1,2 +0,2 @@

# geojson-project
# geojson-project [![npm version](https://badge.fury.io/js/geojson-project.svg)](https://badge.fury.io/js/geojson-project) ![circle](https://circleci.com/gh/w8r/geojson-project.svg?style=shield&circle-token=597a6db31df1e249a8a9bf29531f7baefc142641)

@@ -9,3 +9,3 @@ ## API

returns it transformed
* `context` _optional_ - transform function `this`
* `context` _optional_ - transform function's `this`

@@ -71,2 +71,4 @@ returns transformed copy of GeoJSON

## License
The MIT License (MIT)

@@ -93,2 +95,1 @@

SOFTWARE.

@@ -104,5 +104,86 @@ var project = require('./');

t.test('GeometryCollection', function (t) {
var obj = {
value: 2
};
function proj(coords) {
return [coords[0] + this.value, coords[1] + this.value];
}
t.deepEqual(project({
type: 'Feature',
properties: {},
geometry: {
type: 'GeometryCollection',
geometries: [{
type: 'Polygon',
coordinates: [
[[0, 0], [4, 4], [10, 10], [0, 0]]
]
}, {
type: 'MultiPolygon',
coordinates: [
[[[0, 0], [4, 4], [10, 10], [0, 0]]],
[[[1, 1], [5, 5], [9, 9], [1, 1]]]
]
}, {
type: 'LineString',
coordinates: [[0, 0], [2, 2], [4, 4]]
}, {
type: 'MultiLineString',
coordinates: [
[[0, 0], [2, 2], [4, 4]],
[[1, 1], [3, 3], [5, 5]]
]
}, {
type: 'Point',
coordinates: [0, 0]
}, {
type: 'MultiPoint',
coordinates: [[0, 0], [1, 1]]
}]
}
}, proj, obj), {
type: 'Feature',
properties: {},
geometry: {
type: 'GeometryCollection',
geometries: [{
type: 'Polygon',
coordinates: [
[[2, 2], [6, 6], [12, 12], [2, 2]]
]
}, {
type: 'MultiPolygon',
coordinates: [
[[[2, 2], [6, 6], [12, 12], [2, 2]]],
[[[3, 3], [7, 7], [11, 11], [3, 3]]]
]
}, {
type: 'LineString',
coordinates: [[2, 2], [4, 4], [6, 6]]
}, {
type: 'MultiLineString',
coordinates: [
[[2, 2], [4, 4], [6, 6]],
[[3, 3], [5, 5], [7, 7]]
]
}, {
type: 'Point',
coordinates: [2, 2]
}, {
type: 'MultiPoint',
coordinates: [[2, 2], [3, 3]]
}]
}
});
t.end();
});
t.end();
});
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