@terraformer/spatial
Advanced tools
Comparing version 2.0.6 to 2.0.7
/* @preserve | ||
* @terraformer/spatial - v2.0.6 - MIT | ||
* Copyright (c) 2012-2020 Environmental Systems Research Institute, Inc. | ||
* Mon May 18 2020 14:16:30 GMT-0700 (Pacific Daylight Time) | ||
* Mon May 18 2020 14:30:36 GMT-0700 (Pacific Daylight Time) | ||
*/ | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
const isNumber = n => !isNaN(parseFloat(n)) && isFinite(n); | ||
var isNumber = function isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
}; | ||
const edgeIntersectsEdge = (a1, a2, b1, b2) => { | ||
var edgeIntersectsEdge = function edgeIntersectsEdge(a1, a2, b1, b2) { | ||
var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]); | ||
@@ -27,3 +45,3 @@ var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]); | ||
const arraysIntersectArrays = (a, b) => { | ||
var arraysIntersectArrays = function arraysIntersectArrays(a, b) { | ||
if (isNumber(a[0][0])) { | ||
@@ -55,6 +73,6 @@ if (isNumber(b[0][0])) { | ||
}; | ||
const coordinatesContainPoint = (coordinates, point) => { | ||
let contains = false; | ||
var coordinatesContainPoint = function coordinatesContainPoint(coordinates, point) { | ||
var contains = false; | ||
for (let i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) { | ||
for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) { | ||
if ((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1] || coordinates[j][1] <= point[1] && point[1] < coordinates[i][1]) && point[0] < (coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1]) / (coordinates[j][1] - coordinates[i][1]) + coordinates[i][0]) { | ||
@@ -67,4 +85,4 @@ contains = !contains; | ||
}; | ||
const pointsEqual = (a, b) => { | ||
for (let i = 0; i < a.length; i++) { | ||
var pointsEqual = function pointsEqual(a, b) { | ||
for (var i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) { | ||
@@ -78,6 +96,6 @@ return false; | ||
const EARTH_RADIUS = 6378137; | ||
const DEGREES_PER_RADIAN = 57.295779513082320; | ||
const RADIANS_PER_DEGREE = 0.017453292519943; | ||
const MercatorCRS = { | ||
var EARTH_RADIUS = 6378137; | ||
var DEGREES_PER_RADIAN = 57.295779513082320; | ||
var RADIANS_PER_DEGREE = 0.017453292519943; | ||
var MercatorCRS = { | ||
type: 'link', | ||
@@ -89,3 +107,3 @@ properties: { | ||
}; | ||
const GeographicCRS = { | ||
var GeographicCRS = { | ||
type: 'link', | ||
@@ -102,3 +120,5 @@ properties: { | ||
const radToDeg = rad => rad * DEGREES_PER_RADIAN; | ||
var radToDeg = function radToDeg(rad) { | ||
return rad * DEGREES_PER_RADIAN; | ||
}; | ||
/* | ||
@@ -108,11 +128,13 @@ Internal: Convert degrees to radians. Used by spatial reference converters. | ||
const degToRad = deg => deg * RADIANS_PER_DEGREE; | ||
const positionToGeographic = position => { | ||
const x = position[0]; | ||
const y = position[1]; | ||
var degToRad = function degToRad(deg) { | ||
return deg * RADIANS_PER_DEGREE; | ||
}; | ||
var positionToGeographic = function positionToGeographic(position) { | ||
var x = position[0]; | ||
var y = position[1]; | ||
return [radToDeg(x / EARTH_RADIUS) - Math.floor((radToDeg(x / EARTH_RADIUS) + 180) / 360) * 360, radToDeg(Math.PI / 2 - 2 * Math.atan(Math.exp(-1.0 * y / EARTH_RADIUS)))]; | ||
}; | ||
const positionToMercator = position => { | ||
const lng = position[0]; | ||
const lat = Math.max(Math.min(position[1], 89.99999), -89.99999); | ||
var positionToMercator = function positionToMercator(position) { | ||
var lng = position[0]; | ||
var lat = Math.max(Math.min(position[1], 89.99999), -89.99999); | ||
return [degToRad(lng) * EARTH_RADIUS, EARTH_RADIUS / 2.0 * Math.log((1.0 + Math.sin(degToRad(lat))) / (1.0 - Math.sin(degToRad(lat))))]; | ||
@@ -125,3 +147,3 @@ }; | ||
const compSort = (p1, p2) => { | ||
var compSort = function compSort(p1, p2) { | ||
if (p1[0] > p2[0]) { | ||
@@ -143,3 +165,3 @@ return -1; | ||
const cmp = (a, b) => { | ||
var cmp = function cmp(a, b) { | ||
if (a < b) { | ||
@@ -158,3 +180,3 @@ return -1; | ||
const turn = (p, q, r) => { | ||
var turn = function turn(p, q, r) { | ||
// Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn. | ||
@@ -168,15 +190,15 @@ return cmp((q[0] - p[0]) * (r[1] - p[1]) - (r[0] - p[0]) * (q[1] - p[1]), 0); | ||
const euclideanDistance = (p, q) => { | ||
var euclideanDistance = function euclideanDistance(p, q) { | ||
// Returns the squared Euclidean distance between p and q. | ||
const dx = q[0] - p[0]; | ||
const dy = q[1] - p[1]; | ||
var dx = q[0] - p[0]; | ||
var dy = q[1] - p[1]; | ||
return dx * dx + dy * dy; | ||
}; | ||
const nextHullPoint = (points, p) => { | ||
var nextHullPoint = function nextHullPoint(points, p) { | ||
// Returns the next point on the convex hull in CCW from p. | ||
let q = p; | ||
var q = p; | ||
for (const r in points) { | ||
const t = turn(p, q, points[r]); | ||
for (var r in points) { | ||
var t = turn(p, q, points[r]); | ||
@@ -191,3 +213,3 @@ if (t === -1 || t === 0 && euclideanDistance(p, points[r]) > euclideanDistance(p, q)) { | ||
const coordinateConvexHull = points => { | ||
var coordinateConvexHull = function coordinateConvexHull(points) { | ||
// implementation of the Jarvis March algorithm | ||
@@ -202,6 +224,6 @@ // adapted from http://tixxit.wordpress.com/2009/12/09/jarvis-march/ | ||
const hull = [points.sort(compSort)[0]]; | ||
var hull = [points.sort(compSort)[0]]; | ||
for (var p = 0; p < hull.length; p++) { | ||
const q = nextHullPoint(points, hull[p]); | ||
var q = nextHullPoint(points, hull[p]); | ||
@@ -219,7 +241,7 @@ if (q !== hull[0]) { | ||
const closedPolygon = coordinates => { | ||
const outer = []; | ||
var closedPolygon = function closedPolygon(coordinates) { | ||
var outer = []; | ||
for (let i = 0; i < coordinates.length; i++) { | ||
const inner = coordinates[i].slice(); | ||
for (var i = 0; i < coordinates.length; i++) { | ||
var inner = coordinates[i].slice(); | ||
@@ -240,3 +262,3 @@ if (pointsEqual(inner[0], inner[inner.length - 1]) === false) { | ||
function warn() { | ||
const args = Array.prototype.slice.apply(arguments); | ||
var args = Array.prototype.slice.apply(arguments); | ||
@@ -251,4 +273,4 @@ if (typeof console !== 'undefined' && console.warn) { | ||
const eachPosition = (coordinates, func) => { | ||
for (let i = 0; i < coordinates.length; i++) { | ||
var eachPosition = function eachPosition(coordinates, func) { | ||
for (var i = 0; i < coordinates.length; i++) { | ||
// we found a number so lets convert the pair | ||
@@ -260,3 +282,3 @@ if (typeof coordinates[i][0] === 'number') { | ||
if (typeof coordinates[i] === 'object') { | ||
if (_typeof(coordinates[i]) === 'object') { | ||
coordinates[i] = eachPosition(coordinates[i], func); | ||
@@ -273,3 +295,3 @@ } | ||
const applyConverter = (geojson, converter, noCrs) => { | ||
var applyConverter = function applyConverter(geojson, converter, noCrs) { | ||
if (geojson.type === 'Point') { | ||
@@ -280,7 +302,7 @@ geojson.coordinates = converter(geojson.coordinates); | ||
} else if (geojson.type === 'FeatureCollection') { | ||
for (let f = 0; f < geojson.features.length; f++) { | ||
for (var f = 0; f < geojson.features.length; f++) { | ||
geojson.features[f] = applyConverter(geojson.features[f], converter, true); | ||
} | ||
} else if (geojson.type === 'GeometryCollection') { | ||
for (let g = 0; g < geojson.geometries.length; g++) { | ||
for (var g = 0; g < geojson.geometries.length; g++) { | ||
geojson.geometries[g] = applyConverter(geojson.geometries[g], converter, true); | ||
@@ -304,3 +326,3 @@ } | ||
}; | ||
const coordinatesEqual = (a, b) => { | ||
var coordinatesEqual = function coordinatesEqual(a, b) { | ||
if (a.length !== b.length) { | ||
@@ -310,6 +332,6 @@ return false; | ||
const na = a.slice().sort(compSort); | ||
const nb = b.slice().sort(compSort); | ||
var na = a.slice().sort(compSort); | ||
var nb = b.slice().sort(compSort); | ||
for (let i = 0; i < na.length; i++) { | ||
for (var i = 0; i < na.length; i++) { | ||
if (na[i].length !== nb[i].length) { | ||
@@ -319,3 +341,3 @@ return false; | ||
for (let j = 0; j < na.length; j++) { | ||
for (var j = 0; j < na.length; j++) { | ||
if (na[i][j] !== nb[i][j]) { | ||
@@ -344,15 +366,15 @@ return false; | ||
*/ | ||
const calculateBoundsFromNestedArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
var calculateBoundsFromNestedArrays = function calculateBoundsFromNestedArrays(array) { | ||
var x1 = null; | ||
var x2 = null; | ||
var y1 = null; | ||
var y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const inner = array[i]; | ||
for (var i = 0; i < array.length; i++) { | ||
var inner = array[i]; | ||
for (let j = 0; j < inner.length; j++) { | ||
const lonlat = inner[j]; | ||
const lon = lonlat[0]; | ||
const lat = lonlat[1]; | ||
for (var j = 0; j < inner.length; j++) { | ||
var lonlat = inner[j]; | ||
var lon = lonlat[0]; | ||
var lat = lonlat[1]; | ||
@@ -397,18 +419,18 @@ if (x1 === null) { | ||
const calculateBoundsFromNestedArrayOfArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
var calculateBoundsFromNestedArrayOfArrays = function calculateBoundsFromNestedArrayOfArrays(array) { | ||
var x1 = null; | ||
var x2 = null; | ||
var y1 = null; | ||
var y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const inner = array[i]; // return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
for (var i = 0; i < array.length; i++) { | ||
var inner = array[i]; // return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
for (let j = 0; j < inner.length; j++) { | ||
const innerinner = inner[j]; | ||
for (var j = 0; j < inner.length; j++) { | ||
var innerinner = inner[j]; | ||
for (let k = 0; k < innerinner.length; k++) { | ||
const lonlat = innerinner[k]; | ||
const lon = lonlat[0]; | ||
const lat = lonlat[1]; | ||
for (var k = 0; k < innerinner.length; k++) { | ||
var lonlat = innerinner[k]; | ||
var lon = lonlat[0]; | ||
var lat = lonlat[1]; | ||
@@ -452,12 +474,12 @@ if (x1 === null) { | ||
const calculateBoundsFromArray = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
var calculateBoundsFromArray = function calculateBoundsFromArray(array) { | ||
var x1 = null; | ||
var x2 = null; | ||
var y1 = null; | ||
var y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const lonlat = array[i]; | ||
const lon = lonlat[0]; | ||
const lat = lonlat[1]; | ||
for (var i = 0; i < array.length; i++) { | ||
var lonlat = array[i]; | ||
var lon = lonlat[0]; | ||
var lat = lonlat[1]; | ||
@@ -496,7 +518,7 @@ if (x1 === null) { | ||
const calculateBoundsForFeatureCollection = featureCollection => { | ||
const extents = []; | ||
var calculateBoundsForFeatureCollection = function calculateBoundsForFeatureCollection(featureCollection) { | ||
var extents = []; | ||
for (let i = featureCollection.features.length - 1; i >= 0; i--) { | ||
const extent = calculateBounds(featureCollection.features[i].geometry); | ||
for (var i = featureCollection.features.length - 1; i >= 0; i--) { | ||
var extent = calculateBounds(featureCollection.features[i].geometry); | ||
extents.push([extent[0], extent[1]]); | ||
@@ -513,7 +535,7 @@ extents.push([extent[2], extent[3]]); | ||
const calculateBoundsForGeometryCollection = geometryCollection => { | ||
const extents = []; | ||
var calculateBoundsForGeometryCollection = function calculateBoundsForGeometryCollection(geometryCollection) { | ||
var extents = []; | ||
for (let i = geometryCollection.geometries.length - 1; i >= 0; i--) { | ||
const extent = calculateBounds(geometryCollection.geometries[i]); | ||
for (var i = geometryCollection.geometries.length - 1; i >= 0; i--) { | ||
var extent = calculateBounds(geometryCollection.geometries[i]); | ||
extents.push([extent[0], extent[1]]); | ||
@@ -526,3 +548,3 @@ extents.push([extent[2], extent[3]]); | ||
const calculateBounds = geojson => { | ||
var calculateBounds = function calculateBounds(geojson) { | ||
if (geojson.type) { | ||
@@ -565,6 +587,6 @@ switch (geojson.type) { | ||
const convexHull = geojson => { | ||
let coordinates = []; | ||
let i; | ||
let j; | ||
var convexHull = function convexHull(geojson) { | ||
var coordinates = []; | ||
var i; | ||
var j; | ||
@@ -614,12 +636,12 @@ if (geojson.type === 'Point') { | ||
}; | ||
const isConvex = points => { | ||
let ltz; | ||
var isConvex = function isConvex(points) { | ||
var ltz; | ||
for (var i = 0; i < points.length - 3; i++) { | ||
const p1 = points[i]; | ||
const p2 = points[i + 1]; | ||
const p3 = points[i + 2]; | ||
const v = [p2[0] - p1[0], p2[1] - p1[1]]; // p3.x * v.y - p3.y * v.x + v.x * p1.y - v.y * p1.x | ||
var p1 = points[i]; | ||
var p2 = points[i + 1]; | ||
var p3 = points[i + 2]; | ||
var v = [p2[0] - p1[0], p2[1] - p1[1]]; // p3.x * v.y - p3.y * v.x + v.x * p1.y - v.y * p1.x | ||
const res = p3[0] * v[1] - p3[1] * v[0] + v[0] * p1[1] - v[1] * p1[0]; | ||
var res = p3[0] * v[1] - p3[1] * v[0] + v[0] * p1[1] - v[1] * p1[0]; | ||
@@ -642,3 +664,3 @@ if (i === 0) { | ||
const polygonContainsPoint = (polygon, point) => { | ||
var polygonContainsPoint = function polygonContainsPoint(polygon, point) { | ||
if (polygon && polygon.length) { | ||
@@ -651,3 +673,3 @@ if (polygon.length === 1) { | ||
if (coordinatesContainPoint(polygon[0], point)) { | ||
for (let i = 1; i < polygon.length; i++) { | ||
for (var i = 1; i < polygon.length; i++) { | ||
if (coordinatesContainPoint(polygon[i], point)) { | ||
@@ -668,4 +690,4 @@ return false; // found in hole | ||
const within = (geoJSON, comparisonGeoJSON) => { | ||
let coordinates, i, contains; // if we are passed a feature, use the polygon inside instead | ||
var within = function within(geoJSON, comparisonGeoJSON) { | ||
var coordinates, i, contains; // if we are passed a feature, use the polygon inside instead | ||
@@ -687,3 +709,3 @@ if (comparisonGeoJSON.type === 'Feature') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const linestring = { | ||
var linestring = { | ||
type: 'LineString', | ||
@@ -749,3 +771,3 @@ coordinates: comparisonGeoJSON.coordinates[i] | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const ls = { | ||
var ls = { | ||
type: 'LineString', | ||
@@ -764,3 +786,3 @@ coordinates: geoJSON.coordinates[i] | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const p1 = { | ||
var p1 = { | ||
type: 'Polygon', | ||
@@ -796,3 +818,3 @@ coordinates: geoJSON.coordinates[i] | ||
if (comparisonGeoJSON.coordinates[i].length === geoJSON.coordinates.length) { | ||
for (let j = 0; j < geoJSON.coordinates.length; j++) { | ||
for (var j = 0; j < geoJSON.coordinates.length; j++) { | ||
if (coordinatesEqual(geoJSON.coordinates[j], comparisonGeoJSON.coordinates[i][j])) { | ||
@@ -823,3 +845,3 @@ return true; | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const poly = { | ||
var poly = { | ||
type: 'Polygon', | ||
@@ -838,3 +860,3 @@ coordinates: comparisonGeoJSON.coordinates[i] | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const ls = { | ||
var _ls = { | ||
type: 'LineString', | ||
@@ -844,3 +866,3 @@ coordinates: geoJSON.coordinates[i] | ||
if (within(ls, comparisonGeoJSON) === false) { | ||
if (within(_ls, comparisonGeoJSON) === false) { | ||
return false; | ||
@@ -853,3 +875,3 @@ } | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const mpoly = { | ||
var mpoly = { | ||
type: 'Polygon', | ||
@@ -872,5 +894,7 @@ coordinates: comparisonGeoJSON.coordinates[i] | ||
const contains = (geoJSON, comparisonGeoJSON) => within(comparisonGeoJSON, geoJSON); | ||
var contains = function contains(geoJSON, comparisonGeoJSON) { | ||
return within(comparisonGeoJSON, geoJSON); | ||
}; | ||
const intersects = (geoJSON, comparisonGeoJSON) => { | ||
var intersects = function intersects(geoJSON, comparisonGeoJSON) { | ||
// if we are passed a feature, use the polygon inside instead | ||
@@ -889,3 +913,3 @@ if (comparisonGeoJSON.type === 'Feature') { | ||
// in the case of a Feature, use the internal geometry for intersection | ||
const inner = geoJSON.geometry; | ||
var inner = geoJSON.geometry; | ||
return intersects(inner, comparisonGeoJSON); | ||
@@ -898,3 +922,3 @@ } | ||
const VINCENTY = { | ||
var VINCENTY = { | ||
a: 6378137, | ||
@@ -904,6 +928,8 @@ b: 6356752.3142, | ||
}; | ||
const toGeographic = geojson => applyConverter(geojson, positionToGeographic); | ||
const toCircle = (center, radius, interpolate) => { | ||
const steps = interpolate || 64; | ||
const rad = radius || 250; | ||
var toGeographic = function toGeographic(geojson) { | ||
return applyConverter(geojson, positionToGeographic); | ||
}; | ||
var toCircle = function toCircle(center, radius, interpolate) { | ||
var steps = interpolate || 64; | ||
var rad = radius || 250; | ||
@@ -928,9 +954,9 @@ if (!center || center.length < 2 || !rad || !steps) { | ||
const createGeodesicCircle = (center, radius, interpolate) => { | ||
const steps = interpolate || 64; | ||
const polygon = { | ||
var createGeodesicCircle = function createGeodesicCircle(center, radius, interpolate) { | ||
var steps = interpolate || 64; | ||
var polygon = { | ||
type: 'Polygon', | ||
coordinates: [[]] | ||
}; | ||
let angle; | ||
var angle; | ||
@@ -946,3 +972,3 @@ for (var i = 0; i < steps; i++) { | ||
const destinationVincenty = (coords, brng, dist) => { | ||
var destinationVincenty = function destinationVincenty(coords, brng, dist) { | ||
var cos2SigmaM, sinSigma, cosSigma, deltaSigma; | ||
@@ -1014,4 +1040,4 @@ var a = VINCENTY.a; | ||
const calculateEnvelope = geojson => { | ||
const bounds = calculateBounds(geojson); | ||
var calculateEnvelope = function calculateEnvelope(geojson) { | ||
var bounds = calculateBounds(geojson); | ||
return { | ||
@@ -1041,4 +1067,6 @@ x: bounds[0], | ||
const toMercator = geojson => applyConverter(geojson, positionToMercator); | ||
var toMercator = function toMercator(geojson) { | ||
return applyConverter(geojson, positionToMercator); | ||
}; | ||
export { GeographicCRS, MercatorCRS, calculateBounds, calculateEnvelope, contains, convexHull, intersects, isConvex, polygonContainsPoint, positionToGeographic, positionToMercator, toCircle, toGeographic, toMercator, within }; |
/* @preserve | ||
* @terraformer/spatial - v2.0.6 - MIT | ||
* Copyright (c) 2012-2020 Environmental Systems Research Institute, Inc. | ||
* Mon May 18 2020 14:16:27 GMT-0700 (Pacific Daylight Time) | ||
* Mon May 18 2020 14:30:31 GMT-0700 (Pacific Daylight Time) | ||
*/ | ||
@@ -12,7 +12,25 @@ (function (global, factory) { | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
const isNumber = n => !isNaN(parseFloat(n)) && isFinite(n); | ||
var isNumber = function isNumber(n) { | ||
return !isNaN(parseFloat(n)) && isFinite(n); | ||
}; | ||
const edgeIntersectsEdge = (a1, a2, b1, b2) => { | ||
var edgeIntersectsEdge = function edgeIntersectsEdge(a1, a2, b1, b2) { | ||
var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]); | ||
@@ -34,3 +52,3 @@ var ubT = (a2[0] - a1[0]) * (a1[1] - b1[1]) - (a2[1] - a1[1]) * (a1[0] - b1[0]); | ||
const arraysIntersectArrays = (a, b) => { | ||
var arraysIntersectArrays = function arraysIntersectArrays(a, b) { | ||
if (isNumber(a[0][0])) { | ||
@@ -62,6 +80,6 @@ if (isNumber(b[0][0])) { | ||
}; | ||
const coordinatesContainPoint = (coordinates, point) => { | ||
let contains = false; | ||
var coordinatesContainPoint = function coordinatesContainPoint(coordinates, point) { | ||
var contains = false; | ||
for (let i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) { | ||
for (var i = -1, l = coordinates.length, j = l - 1; ++i < l; j = i) { | ||
if ((coordinates[i][1] <= point[1] && point[1] < coordinates[j][1] || coordinates[j][1] <= point[1] && point[1] < coordinates[i][1]) && point[0] < (coordinates[j][0] - coordinates[i][0]) * (point[1] - coordinates[i][1]) / (coordinates[j][1] - coordinates[i][1]) + coordinates[i][0]) { | ||
@@ -74,4 +92,4 @@ contains = !contains; | ||
}; | ||
const pointsEqual = (a, b) => { | ||
for (let i = 0; i < a.length; i++) { | ||
var pointsEqual = function pointsEqual(a, b) { | ||
for (var i = 0; i < a.length; i++) { | ||
if (a[i] !== b[i]) { | ||
@@ -85,6 +103,6 @@ return false; | ||
const EARTH_RADIUS = 6378137; | ||
const DEGREES_PER_RADIAN = 57.295779513082320; | ||
const RADIANS_PER_DEGREE = 0.017453292519943; | ||
const MercatorCRS = { | ||
var EARTH_RADIUS = 6378137; | ||
var DEGREES_PER_RADIAN = 57.295779513082320; | ||
var RADIANS_PER_DEGREE = 0.017453292519943; | ||
var MercatorCRS = { | ||
type: 'link', | ||
@@ -96,3 +114,3 @@ properties: { | ||
}; | ||
const GeographicCRS = { | ||
var GeographicCRS = { | ||
type: 'link', | ||
@@ -109,3 +127,5 @@ properties: { | ||
const radToDeg = rad => rad * DEGREES_PER_RADIAN; | ||
var radToDeg = function radToDeg(rad) { | ||
return rad * DEGREES_PER_RADIAN; | ||
}; | ||
/* | ||
@@ -115,11 +135,13 @@ Internal: Convert degrees to radians. Used by spatial reference converters. | ||
const degToRad = deg => deg * RADIANS_PER_DEGREE; | ||
const positionToGeographic = position => { | ||
const x = position[0]; | ||
const y = position[1]; | ||
var degToRad = function degToRad(deg) { | ||
return deg * RADIANS_PER_DEGREE; | ||
}; | ||
var positionToGeographic = function positionToGeographic(position) { | ||
var x = position[0]; | ||
var y = position[1]; | ||
return [radToDeg(x / EARTH_RADIUS) - Math.floor((radToDeg(x / EARTH_RADIUS) + 180) / 360) * 360, radToDeg(Math.PI / 2 - 2 * Math.atan(Math.exp(-1.0 * y / EARTH_RADIUS)))]; | ||
}; | ||
const positionToMercator = position => { | ||
const lng = position[0]; | ||
const lat = Math.max(Math.min(position[1], 89.99999), -89.99999); | ||
var positionToMercator = function positionToMercator(position) { | ||
var lng = position[0]; | ||
var lat = Math.max(Math.min(position[1], 89.99999), -89.99999); | ||
return [degToRad(lng) * EARTH_RADIUS, EARTH_RADIUS / 2.0 * Math.log((1.0 + Math.sin(degToRad(lat))) / (1.0 - Math.sin(degToRad(lat))))]; | ||
@@ -132,3 +154,3 @@ }; | ||
const compSort = (p1, p2) => { | ||
var compSort = function compSort(p1, p2) { | ||
if (p1[0] > p2[0]) { | ||
@@ -150,3 +172,3 @@ return -1; | ||
const cmp = (a, b) => { | ||
var cmp = function cmp(a, b) { | ||
if (a < b) { | ||
@@ -165,3 +187,3 @@ return -1; | ||
const turn = (p, q, r) => { | ||
var turn = function turn(p, q, r) { | ||
// Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn. | ||
@@ -175,15 +197,15 @@ return cmp((q[0] - p[0]) * (r[1] - p[1]) - (r[0] - p[0]) * (q[1] - p[1]), 0); | ||
const euclideanDistance = (p, q) => { | ||
var euclideanDistance = function euclideanDistance(p, q) { | ||
// Returns the squared Euclidean distance between p and q. | ||
const dx = q[0] - p[0]; | ||
const dy = q[1] - p[1]; | ||
var dx = q[0] - p[0]; | ||
var dy = q[1] - p[1]; | ||
return dx * dx + dy * dy; | ||
}; | ||
const nextHullPoint = (points, p) => { | ||
var nextHullPoint = function nextHullPoint(points, p) { | ||
// Returns the next point on the convex hull in CCW from p. | ||
let q = p; | ||
var q = p; | ||
for (const r in points) { | ||
const t = turn(p, q, points[r]); | ||
for (var r in points) { | ||
var t = turn(p, q, points[r]); | ||
@@ -198,3 +220,3 @@ if (t === -1 || t === 0 && euclideanDistance(p, points[r]) > euclideanDistance(p, q)) { | ||
const coordinateConvexHull = points => { | ||
var coordinateConvexHull = function coordinateConvexHull(points) { | ||
// implementation of the Jarvis March algorithm | ||
@@ -209,6 +231,6 @@ // adapted from http://tixxit.wordpress.com/2009/12/09/jarvis-march/ | ||
const hull = [points.sort(compSort)[0]]; | ||
var hull = [points.sort(compSort)[0]]; | ||
for (var p = 0; p < hull.length; p++) { | ||
const q = nextHullPoint(points, hull[p]); | ||
var q = nextHullPoint(points, hull[p]); | ||
@@ -226,7 +248,7 @@ if (q !== hull[0]) { | ||
const closedPolygon = coordinates => { | ||
const outer = []; | ||
var closedPolygon = function closedPolygon(coordinates) { | ||
var outer = []; | ||
for (let i = 0; i < coordinates.length; i++) { | ||
const inner = coordinates[i].slice(); | ||
for (var i = 0; i < coordinates.length; i++) { | ||
var inner = coordinates[i].slice(); | ||
@@ -247,3 +269,3 @@ if (pointsEqual(inner[0], inner[inner.length - 1]) === false) { | ||
function warn() { | ||
const args = Array.prototype.slice.apply(arguments); | ||
var args = Array.prototype.slice.apply(arguments); | ||
@@ -258,4 +280,4 @@ if (typeof console !== 'undefined' && console.warn) { | ||
const eachPosition = (coordinates, func) => { | ||
for (let i = 0; i < coordinates.length; i++) { | ||
var eachPosition = function eachPosition(coordinates, func) { | ||
for (var i = 0; i < coordinates.length; i++) { | ||
// we found a number so lets convert the pair | ||
@@ -267,3 +289,3 @@ if (typeof coordinates[i][0] === 'number') { | ||
if (typeof coordinates[i] === 'object') { | ||
if (_typeof(coordinates[i]) === 'object') { | ||
coordinates[i] = eachPosition(coordinates[i], func); | ||
@@ -280,3 +302,3 @@ } | ||
const applyConverter = (geojson, converter, noCrs) => { | ||
var applyConverter = function applyConverter(geojson, converter, noCrs) { | ||
if (geojson.type === 'Point') { | ||
@@ -287,7 +309,7 @@ geojson.coordinates = converter(geojson.coordinates); | ||
} else if (geojson.type === 'FeatureCollection') { | ||
for (let f = 0; f < geojson.features.length; f++) { | ||
for (var f = 0; f < geojson.features.length; f++) { | ||
geojson.features[f] = applyConverter(geojson.features[f], converter, true); | ||
} | ||
} else if (geojson.type === 'GeometryCollection') { | ||
for (let g = 0; g < geojson.geometries.length; g++) { | ||
for (var g = 0; g < geojson.geometries.length; g++) { | ||
geojson.geometries[g] = applyConverter(geojson.geometries[g], converter, true); | ||
@@ -311,3 +333,3 @@ } | ||
}; | ||
const coordinatesEqual = (a, b) => { | ||
var coordinatesEqual = function coordinatesEqual(a, b) { | ||
if (a.length !== b.length) { | ||
@@ -317,6 +339,6 @@ return false; | ||
const na = a.slice().sort(compSort); | ||
const nb = b.slice().sort(compSort); | ||
var na = a.slice().sort(compSort); | ||
var nb = b.slice().sort(compSort); | ||
for (let i = 0; i < na.length; i++) { | ||
for (var i = 0; i < na.length; i++) { | ||
if (na[i].length !== nb[i].length) { | ||
@@ -326,3 +348,3 @@ return false; | ||
for (let j = 0; j < na.length; j++) { | ||
for (var j = 0; j < na.length; j++) { | ||
if (na[i][j] !== nb[i][j]) { | ||
@@ -351,15 +373,15 @@ return false; | ||
*/ | ||
const calculateBoundsFromNestedArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
var calculateBoundsFromNestedArrays = function calculateBoundsFromNestedArrays(array) { | ||
var x1 = null; | ||
var x2 = null; | ||
var y1 = null; | ||
var y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const inner = array[i]; | ||
for (var i = 0; i < array.length; i++) { | ||
var inner = array[i]; | ||
for (let j = 0; j < inner.length; j++) { | ||
const lonlat = inner[j]; | ||
const lon = lonlat[0]; | ||
const lat = lonlat[1]; | ||
for (var j = 0; j < inner.length; j++) { | ||
var lonlat = inner[j]; | ||
var lon = lonlat[0]; | ||
var lat = lonlat[1]; | ||
@@ -404,18 +426,18 @@ if (x1 === null) { | ||
const calculateBoundsFromNestedArrayOfArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
var calculateBoundsFromNestedArrayOfArrays = function calculateBoundsFromNestedArrayOfArrays(array) { | ||
var x1 = null; | ||
var x2 = null; | ||
var y1 = null; | ||
var y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const inner = array[i]; // return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
for (var i = 0; i < array.length; i++) { | ||
var inner = array[i]; // return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
for (let j = 0; j < inner.length; j++) { | ||
const innerinner = inner[j]; | ||
for (var j = 0; j < inner.length; j++) { | ||
var innerinner = inner[j]; | ||
for (let k = 0; k < innerinner.length; k++) { | ||
const lonlat = innerinner[k]; | ||
const lon = lonlat[0]; | ||
const lat = lonlat[1]; | ||
for (var k = 0; k < innerinner.length; k++) { | ||
var lonlat = innerinner[k]; | ||
var lon = lonlat[0]; | ||
var lat = lonlat[1]; | ||
@@ -459,12 +481,12 @@ if (x1 === null) { | ||
const calculateBoundsFromArray = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
var calculateBoundsFromArray = function calculateBoundsFromArray(array) { | ||
var x1 = null; | ||
var x2 = null; | ||
var y1 = null; | ||
var y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const lonlat = array[i]; | ||
const lon = lonlat[0]; | ||
const lat = lonlat[1]; | ||
for (var i = 0; i < array.length; i++) { | ||
var lonlat = array[i]; | ||
var lon = lonlat[0]; | ||
var lat = lonlat[1]; | ||
@@ -503,7 +525,7 @@ if (x1 === null) { | ||
const calculateBoundsForFeatureCollection = featureCollection => { | ||
const extents = []; | ||
var calculateBoundsForFeatureCollection = function calculateBoundsForFeatureCollection(featureCollection) { | ||
var extents = []; | ||
for (let i = featureCollection.features.length - 1; i >= 0; i--) { | ||
const extent = calculateBounds(featureCollection.features[i].geometry); | ||
for (var i = featureCollection.features.length - 1; i >= 0; i--) { | ||
var extent = calculateBounds(featureCollection.features[i].geometry); | ||
extents.push([extent[0], extent[1]]); | ||
@@ -520,7 +542,7 @@ extents.push([extent[2], extent[3]]); | ||
const calculateBoundsForGeometryCollection = geometryCollection => { | ||
const extents = []; | ||
var calculateBoundsForGeometryCollection = function calculateBoundsForGeometryCollection(geometryCollection) { | ||
var extents = []; | ||
for (let i = geometryCollection.geometries.length - 1; i >= 0; i--) { | ||
const extent = calculateBounds(geometryCollection.geometries[i]); | ||
for (var i = geometryCollection.geometries.length - 1; i >= 0; i--) { | ||
var extent = calculateBounds(geometryCollection.geometries[i]); | ||
extents.push([extent[0], extent[1]]); | ||
@@ -533,3 +555,3 @@ extents.push([extent[2], extent[3]]); | ||
const calculateBounds = geojson => { | ||
var calculateBounds = function calculateBounds(geojson) { | ||
if (geojson.type) { | ||
@@ -572,6 +594,6 @@ switch (geojson.type) { | ||
const convexHull = geojson => { | ||
let coordinates = []; | ||
let i; | ||
let j; | ||
var convexHull = function convexHull(geojson) { | ||
var coordinates = []; | ||
var i; | ||
var j; | ||
@@ -621,12 +643,12 @@ if (geojson.type === 'Point') { | ||
}; | ||
const isConvex = points => { | ||
let ltz; | ||
var isConvex = function isConvex(points) { | ||
var ltz; | ||
for (var i = 0; i < points.length - 3; i++) { | ||
const p1 = points[i]; | ||
const p2 = points[i + 1]; | ||
const p3 = points[i + 2]; | ||
const v = [p2[0] - p1[0], p2[1] - p1[1]]; // p3.x * v.y - p3.y * v.x + v.x * p1.y - v.y * p1.x | ||
var p1 = points[i]; | ||
var p2 = points[i + 1]; | ||
var p3 = points[i + 2]; | ||
var v = [p2[0] - p1[0], p2[1] - p1[1]]; // p3.x * v.y - p3.y * v.x + v.x * p1.y - v.y * p1.x | ||
const res = p3[0] * v[1] - p3[1] * v[0] + v[0] * p1[1] - v[1] * p1[0]; | ||
var res = p3[0] * v[1] - p3[1] * v[0] + v[0] * p1[1] - v[1] * p1[0]; | ||
@@ -649,3 +671,3 @@ if (i === 0) { | ||
const polygonContainsPoint = (polygon, point) => { | ||
var polygonContainsPoint = function polygonContainsPoint(polygon, point) { | ||
if (polygon && polygon.length) { | ||
@@ -658,3 +680,3 @@ if (polygon.length === 1) { | ||
if (coordinatesContainPoint(polygon[0], point)) { | ||
for (let i = 1; i < polygon.length; i++) { | ||
for (var i = 1; i < polygon.length; i++) { | ||
if (coordinatesContainPoint(polygon[i], point)) { | ||
@@ -675,4 +697,4 @@ return false; // found in hole | ||
const within = (geoJSON, comparisonGeoJSON) => { | ||
let coordinates, i, contains; // if we are passed a feature, use the polygon inside instead | ||
var within = function within(geoJSON, comparisonGeoJSON) { | ||
var coordinates, i, contains; // if we are passed a feature, use the polygon inside instead | ||
@@ -694,3 +716,3 @@ if (comparisonGeoJSON.type === 'Feature') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const linestring = { | ||
var linestring = { | ||
type: 'LineString', | ||
@@ -756,3 +778,3 @@ coordinates: comparisonGeoJSON.coordinates[i] | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const ls = { | ||
var ls = { | ||
type: 'LineString', | ||
@@ -771,3 +793,3 @@ coordinates: geoJSON.coordinates[i] | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const p1 = { | ||
var p1 = { | ||
type: 'Polygon', | ||
@@ -803,3 +825,3 @@ coordinates: geoJSON.coordinates[i] | ||
if (comparisonGeoJSON.coordinates[i].length === geoJSON.coordinates.length) { | ||
for (let j = 0; j < geoJSON.coordinates.length; j++) { | ||
for (var j = 0; j < geoJSON.coordinates.length; j++) { | ||
if (coordinatesEqual(geoJSON.coordinates[j], comparisonGeoJSON.coordinates[i][j])) { | ||
@@ -830,3 +852,3 @@ return true; | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const poly = { | ||
var poly = { | ||
type: 'Polygon', | ||
@@ -845,3 +867,3 @@ coordinates: comparisonGeoJSON.coordinates[i] | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const ls = { | ||
var _ls = { | ||
type: 'LineString', | ||
@@ -851,3 +873,3 @@ coordinates: geoJSON.coordinates[i] | ||
if (within(ls, comparisonGeoJSON) === false) { | ||
if (within(_ls, comparisonGeoJSON) === false) { | ||
return false; | ||
@@ -860,3 +882,3 @@ } | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const mpoly = { | ||
var mpoly = { | ||
type: 'Polygon', | ||
@@ -879,5 +901,7 @@ coordinates: comparisonGeoJSON.coordinates[i] | ||
const contains = (geoJSON, comparisonGeoJSON) => within(comparisonGeoJSON, geoJSON); | ||
var contains = function contains(geoJSON, comparisonGeoJSON) { | ||
return within(comparisonGeoJSON, geoJSON); | ||
}; | ||
const intersects = (geoJSON, comparisonGeoJSON) => { | ||
var intersects = function intersects(geoJSON, comparisonGeoJSON) { | ||
// if we are passed a feature, use the polygon inside instead | ||
@@ -896,3 +920,3 @@ if (comparisonGeoJSON.type === 'Feature') { | ||
// in the case of a Feature, use the internal geometry for intersection | ||
const inner = geoJSON.geometry; | ||
var inner = geoJSON.geometry; | ||
return intersects(inner, comparisonGeoJSON); | ||
@@ -905,3 +929,3 @@ } | ||
const VINCENTY = { | ||
var VINCENTY = { | ||
a: 6378137, | ||
@@ -911,6 +935,8 @@ b: 6356752.3142, | ||
}; | ||
const toGeographic = geojson => applyConverter(geojson, positionToGeographic); | ||
const toCircle = (center, radius, interpolate) => { | ||
const steps = interpolate || 64; | ||
const rad = radius || 250; | ||
var toGeographic = function toGeographic(geojson) { | ||
return applyConverter(geojson, positionToGeographic); | ||
}; | ||
var toCircle = function toCircle(center, radius, interpolate) { | ||
var steps = interpolate || 64; | ||
var rad = radius || 250; | ||
@@ -935,9 +961,9 @@ if (!center || center.length < 2 || !rad || !steps) { | ||
const createGeodesicCircle = (center, radius, interpolate) => { | ||
const steps = interpolate || 64; | ||
const polygon = { | ||
var createGeodesicCircle = function createGeodesicCircle(center, radius, interpolate) { | ||
var steps = interpolate || 64; | ||
var polygon = { | ||
type: 'Polygon', | ||
coordinates: [[]] | ||
}; | ||
let angle; | ||
var angle; | ||
@@ -953,3 +979,3 @@ for (var i = 0; i < steps; i++) { | ||
const destinationVincenty = (coords, brng, dist) => { | ||
var destinationVincenty = function destinationVincenty(coords, brng, dist) { | ||
var cos2SigmaM, sinSigma, cosSigma, deltaSigma; | ||
@@ -1021,4 +1047,4 @@ var a = VINCENTY.a; | ||
const calculateEnvelope = geojson => { | ||
const bounds = calculateBounds(geojson); | ||
var calculateEnvelope = function calculateEnvelope(geojson) { | ||
var bounds = calculateBounds(geojson); | ||
return { | ||
@@ -1048,3 +1074,5 @@ x: bounds[0], | ||
const toMercator = geojson => applyConverter(geojson, positionToMercator); | ||
var toMercator = function toMercator(geojson) { | ||
return applyConverter(geojson, positionToMercator); | ||
}; | ||
@@ -1051,0 +1079,0 @@ exports.GeographicCRS = GeographicCRS; |
{ | ||
"name": "@terraformer/spatial", | ||
"description": "Spatial predicates for GeoJSON.", | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"author": "Patrick Arlt <patrick.arlt@gmail.com>", | ||
@@ -15,3 +15,3 @@ "bugs": { | ||
"dependencies": { | ||
"@terraformer/common": "^2.0.6" | ||
"@terraformer/common": "^2.0.7" | ||
}, | ||
@@ -45,3 +45,3 @@ "files": [ | ||
}, | ||
"gitHead": "d21bc2e4f11231029c64cefd8d64ee23a2327961" | ||
"gitHead": "48e9db8c3fbd6660d5a50c3d160a9f3fdd4837df" | ||
} |
75641
1737
Updated@terraformer/common@^2.0.7