@terraformer/spatial
Advanced tools
Comparing version 2.0.5 to 2.0.6
/* @preserve | ||
* @terraformer/spatial - v2.0.4 - MIT | ||
* @terraformer/spatial - v2.0.6 - MIT | ||
* Copyright (c) 2012-2020 Environmental Systems Research Institute, Inc. | ||
* Sun May 17 2020 12:38:50 GMT-0700 (Pacific Daylight Time) | ||
* Mon May 18 2020 14:16:30 GMT-0700 (Pacific Daylight Time) | ||
*/ | ||
/* Copyright (c) 2012-2019 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
const isNumber = n => !isNaN(parseFloat(n)) && isFinite(n); | ||
const isNumber = (n) => !isNaN(parseFloat(n)) && isFinite(n); | ||
const edgeIntersectsEdge = (a1, a2, b1, b2) => { | ||
@@ -52,17 +51,16 @@ var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]); | ||
} | ||
return false; | ||
}; | ||
const coordinatesContainPoint = (coordinates, point) => { | ||
let contains = false; | ||
for (let 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])) { | ||
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]) { | ||
contains = !contains; | ||
} | ||
} | ||
return contains; | ||
}; | ||
const pointsEqual = (a, b) => { | ||
@@ -81,3 +79,2 @@ for (let i = 0; i < a.length; i++) { | ||
const RADIANS_PER_DEGREE = 0.017453292519943; | ||
const MercatorCRS = { | ||
@@ -90,3 +87,2 @@ type: 'link', | ||
}; | ||
const GeographicCRS = { | ||
@@ -103,16 +99,15 @@ type: 'link', | ||
*/ | ||
const radToDeg = (rad) => rad * DEGREES_PER_RADIAN; | ||
const radToDeg = rad => rad * DEGREES_PER_RADIAN; | ||
/* | ||
Internal: Convert degrees to radians. Used by spatial reference converters. | ||
*/ | ||
const degToRad = (deg) => deg * RADIANS_PER_DEGREE; | ||
const positionToGeographic = (position) => { | ||
const degToRad = deg => deg * RADIANS_PER_DEGREE; | ||
const positionToGeographic = position => { | ||
const x = position[0]; | ||
const 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))))]; | ||
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 positionToMercator = position => { | ||
const lng = position[0]; | ||
@@ -126,2 +121,3 @@ const lat = Math.max(Math.min(position[1], 89.99999), -89.99999); | ||
*/ | ||
const compSort = (p1, p2) => { | ||
@@ -140,6 +136,6 @@ if (p1[0] > p2[0]) { | ||
}; | ||
/* | ||
Internal: -1,0,1 comparison function | ||
*/ | ||
const cmp = (a, b) => { | ||
@@ -154,6 +150,7 @@ if (a < b) { | ||
}; | ||
/* | ||
Internal: used to determine turn | ||
*/ | ||
const turn = (p, q, r) => { | ||
@@ -163,6 +160,7 @@ // Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn. | ||
}; | ||
/* | ||
Internal: used to determine euclidean distance between two points | ||
*/ | ||
const euclideanDistance = (p, q) => { | ||
@@ -172,3 +170,2 @@ // Returns the squared Euclidean distance between p and q. | ||
const dy = q[1] - p[1]; | ||
return dx * dx + dy * dy; | ||
@@ -180,15 +177,17 @@ }; | ||
let q = p; | ||
for (const r in points) { | ||
const t = turn(p, q, points[r]); | ||
if (t === -1 || (t === 0 && euclideanDistance(p, points[r]) > euclideanDistance(p, q))) { | ||
if (t === -1 || t === 0 && euclideanDistance(p, points[r]) > euclideanDistance(p, q)) { | ||
q = points[r]; | ||
} | ||
} | ||
return q; | ||
}; | ||
const coordinateConvexHull = (points) => { | ||
const coordinateConvexHull = points => { | ||
// implementation of the Jarvis March algorithm | ||
// adapted from http://tixxit.wordpress.com/2009/12/09/jarvis-march/ | ||
if (points.length === 0) { | ||
@@ -198,5 +197,5 @@ return []; | ||
return points; | ||
} | ||
} // Returns the points on the convex hull of points in CCW order. | ||
// Returns the points on the convex hull of points in CCW order. | ||
const hull = [points.sort(compSort)[0]]; | ||
@@ -214,7 +213,7 @@ | ||
}; | ||
/* | ||
Internal: Returns a copy of coordinates for a closed polygon | ||
*/ | ||
const closedPolygon = (coordinates) => { | ||
const closedPolygon = coordinates => { | ||
const outer = []; | ||
@@ -224,2 +223,3 @@ | ||
const inner = coordinates[i].slice(); | ||
if (pointsEqual(inner[0], inner[inner.length - 1]) === false) { | ||
@@ -234,7 +234,7 @@ inner.push(inner[0]); | ||
}; | ||
/* | ||
Internal: safe warning | ||
*/ | ||
function warn () { | ||
function warn() { | ||
const args = Array.prototype.slice.apply(arguments); | ||
@@ -246,6 +246,6 @@ | ||
} | ||
/* | ||
Internal: Loop over each array in a geojson object and apply a function to it. Used by spatial reference converters. | ||
*/ | ||
const eachPosition = (coordinates, func) => { | ||
@@ -256,4 +256,5 @@ for (let i = 0; i < coordinates.length; i++) { | ||
coordinates[i] = func(coordinates[i]); | ||
} | ||
// we found an coordinates array it again and run the function against it | ||
} // we found an coordinates array it again and run the function against it | ||
if (typeof coordinates[i] === 'object') { | ||
@@ -263,8 +264,10 @@ coordinates[i] = eachPosition(coordinates[i], func); | ||
} | ||
return coordinates; | ||
}; | ||
/* | ||
Apply a function agaist all positions in a geojson object. Used by spatial reference converters. | ||
*/ | ||
const applyConverter = (geojson, converter, noCrs) => { | ||
@@ -299,3 +302,2 @@ if (geojson.type === 'Point') { | ||
}; | ||
const coordinatesEqual = (a, b) => { | ||
@@ -313,2 +315,3 @@ if (a.length !== b.length) { | ||
} | ||
for (let j = 0; j < na.length; j++) { | ||
@@ -338,4 +341,7 @@ if (na[i][j] !== nb[i][j]) { | ||
*/ | ||
const calculateBoundsFromNestedArrays = (array) => { | ||
let x1 = null; let x2 = null; let y1 = null; let y2 = null; | ||
const calculateBoundsFromNestedArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
@@ -347,3 +353,2 @@ for (let i = 0; i < array.length; i++) { | ||
const lonlat = inner[j]; | ||
const lon = lonlat[0]; | ||
@@ -380,3 +385,2 @@ const lat = lonlat[1]; | ||
}; | ||
/* | ||
@@ -390,9 +394,13 @@ Internal: Calculate a bounding box from an array of arrays of arrays | ||
*/ | ||
const calculateBoundsFromNestedArrayOfArrays = (array) => { | ||
let x1 = null; let x2 = null; let y1 = null; let y2 = null; | ||
const calculateBoundsFromNestedArrayOfArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const inner = array[i]; | ||
const inner = array[i]; // return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
// return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
for (let j = 0; j < inner.length; j++) { | ||
@@ -403,3 +411,2 @@ const innerinner = inner[j]; | ||
const lonlat = innerinner[k]; | ||
const lon = lonlat[0]; | ||
@@ -437,3 +444,2 @@ const lat = lonlat[1]; | ||
}; | ||
/* | ||
@@ -445,5 +451,10 @@ Internal: Calculate a bounding box from an array of positions | ||
*/ | ||
const calculateBoundsFromArray = (array) => { | ||
let x1 = null; let x2 = null; let y1 = null; let y2 = null; | ||
const calculateBoundsFromArray = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
@@ -481,8 +492,10 @@ const lonlat = array[i]; | ||
}; | ||
/* | ||
Internal: Calculate an bounding box for a feature collection | ||
*/ | ||
const calculateBoundsForFeatureCollection = (featureCollection) => { | ||
const calculateBoundsForFeatureCollection = featureCollection => { | ||
const extents = []; | ||
for (let i = featureCollection.features.length - 1; i >= 0; i--) { | ||
@@ -496,7 +509,8 @@ const extent = calculateBounds(featureCollection.features[i].geometry); | ||
}; | ||
/* | ||
Internal: Calculate an bounding box for a geometry collection | ||
*/ | ||
const calculateBoundsForGeometryCollection = (geometryCollection) => { | ||
const calculateBoundsForGeometryCollection = geometryCollection => { | ||
const extents = []; | ||
@@ -513,3 +527,3 @@ | ||
const calculateBounds = (geojson) => { | ||
const calculateBounds = geojson => { | ||
if (geojson.type) { | ||
@@ -548,7 +562,11 @@ switch (geojson.type) { | ||
} | ||
return null; | ||
}; | ||
const convexHull = (geojson) => { | ||
let coordinates = []; let i; let j; | ||
const convexHull = geojson => { | ||
let coordinates = []; | ||
let i; | ||
let j; | ||
if (geojson.type === 'Point') { | ||
@@ -567,2 +585,3 @@ return null; | ||
} | ||
if (coordinates.length < 3) { | ||
@@ -581,2 +600,3 @@ return null; | ||
} | ||
if (coordinates.length < 3) { | ||
@@ -597,4 +617,3 @@ return null; | ||
}; | ||
const isConvex = (points) => { | ||
const isConvex = points => { | ||
let ltz; | ||
@@ -606,5 +625,4 @@ | ||
const p3 = points[i + 2]; | ||
const v = [p2[0] - p1[0], p2[1] - p1[1]]; | ||
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 | ||
// 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]; | ||
@@ -619,3 +637,3 @@ | ||
} else { | ||
if ((ltz && res > 0) || (!ltz && res < 0)) { | ||
if (ltz && res > 0 || !ltz && res < 0) { | ||
return false; | ||
@@ -631,5 +649,7 @@ } | ||
if (polygon && polygon.length) { | ||
if (polygon.length === 1) { // polygon with no holes | ||
if (polygon.length === 1) { | ||
// polygon with no holes | ||
return coordinatesContainPoint(polygon[0], point); | ||
} else { // polygon with holes | ||
} else { | ||
// polygon with holes | ||
if (coordinatesContainPoint(polygon[0], point)) { | ||
@@ -641,2 +661,3 @@ for (let i = 1; i < polygon.length; i++) { | ||
} | ||
return true; | ||
@@ -653,10 +674,9 @@ } else { | ||
const within = (geoJSON, comparisonGeoJSON) => { | ||
let coordinates, i, contains; | ||
let coordinates, i, contains; // if we are passed a feature, use the polygon inside instead | ||
// if we are passed a feature, use the polygon inside instead | ||
if (comparisonGeoJSON.type === 'Feature') { | ||
comparisonGeoJSON = comparisonGeoJSON.geometry; | ||
} | ||
} // point.within(point) :: equality | ||
// point.within(point) :: equality | ||
if (comparisonGeoJSON.type === 'Point') { | ||
@@ -666,9 +686,12 @@ if (geoJSON.type === 'Point') { | ||
} | ||
} | ||
} // point.within(multilinestring) | ||
// point.within(multilinestring) | ||
if (comparisonGeoJSON.type === 'MultiLineString') { | ||
if (geoJSON.type === 'Point') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const linestring = { type: 'LineString', coordinates: comparisonGeoJSON.coordinates[i] }; | ||
const linestring = { | ||
type: 'LineString', | ||
coordinates: comparisonGeoJSON.coordinates[i] | ||
}; | ||
@@ -680,5 +703,5 @@ if (within(geoJSON, linestring)) { | ||
} | ||
} | ||
} // point.within(linestring), point.within(multipoint) | ||
// point.within(linestring), point.within(multipoint) | ||
if (comparisonGeoJSON.type === 'LineString' || comparisonGeoJSON.type === 'MultiPoint') { | ||
@@ -714,9 +737,6 @@ if (geoJSON.type === 'Point') { | ||
return false; | ||
} | ||
} // point.within(polygon) | ||
// point.within(polygon) | ||
} else if (geoJSON.type === 'Point') { | ||
return polygonContainsPoint(comparisonGeoJSON.coordinates, geoJSON.coordinates); | ||
// linestring/multipoint withing polygon | ||
return polygonContainsPoint(comparisonGeoJSON.coordinates, geoJSON.coordinates); // linestring/multipoint withing polygon | ||
} else if (geoJSON.type === 'LineString' || geoJSON.type === 'MultiPoint') { | ||
@@ -733,5 +753,3 @@ if (!geoJSON.coordinates || geoJSON.coordinates.length === 0) { | ||
return true; | ||
// multilinestring.within(polygon) | ||
return true; // multilinestring.within(polygon) | ||
} else if (geoJSON.type === 'MultiLineString') { | ||
@@ -743,2 +761,3 @@ for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
}; | ||
if (within(ls, comparisonGeoJSON) === false) { | ||
@@ -750,8 +769,9 @@ contains++; | ||
return true; | ||
// multipolygon.within(polygon) | ||
return true; // multipolygon.within(polygon) | ||
} else if (geoJSON.type === 'MultiPolygon') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const p1 = { type: 'Polygon', coordinates: geoJSON.coordinates[i] }; | ||
const p1 = { | ||
type: 'Polygon', | ||
coordinates: geoJSON.coordinates[i] | ||
}; | ||
@@ -773,2 +793,3 @@ if (within(p1, comparisonGeoJSON) === false) { | ||
coordinates = comparisonGeoJSON.coordinates[i]; | ||
if (polygonContainsPoint(coordinates, geoJSON.coordinates) && arraysIntersectArrays([geoJSON.coordinates], comparisonGeoJSON.coordinates) === false) { | ||
@@ -780,4 +801,3 @@ return true; | ||
return false; | ||
// polygon.within(multipolygon) | ||
return false; // polygon.within(multipolygon) | ||
} else if (geoJSON.type === 'Polygon') { | ||
@@ -798,2 +818,3 @@ for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
coordinates = comparisonGeoJSON.coordinates[i]; | ||
if (polygonContainsPoint(coordinates, geoJSON.coordinates[0][0]) === false) { | ||
@@ -808,8 +829,10 @@ contains = false; | ||
} | ||
} | ||
} // linestring.within(multipolygon), multipoint.within(multipolygon) | ||
// linestring.within(multipolygon), multipoint.within(multipolygon) | ||
} else if (geoJSON.type === 'LineString' || geoJSON.type === 'MultiPoint') { | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const poly = { type: 'Polygon', coordinates: comparisonGeoJSON.coordinates[i] }; | ||
const poly = { | ||
type: 'Polygon', | ||
coordinates: comparisonGeoJSON.coordinates[i] | ||
}; | ||
@@ -821,8 +844,10 @@ if (within(geoJSON, poly)) { | ||
return false; | ||
} | ||
} // multilinestring.within(multipolygon) | ||
// multilinestring.within(multipolygon) | ||
} else if (geoJSON.type === 'MultiLineString') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const ls = { type: 'LineString', coordinates: geoJSON.coordinates[i] }; | ||
const ls = { | ||
type: 'LineString', | ||
coordinates: geoJSON.coordinates[i] | ||
}; | ||
@@ -834,8 +859,9 @@ if (within(ls, comparisonGeoJSON) === false) { | ||
return true; | ||
// multipolygon.within(multipolygon) | ||
return true; // multipolygon.within(multipolygon) | ||
} else if (geoJSON.type === 'MultiPolygon') { | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const mpoly = { type: 'Polygon', coordinates: comparisonGeoJSON.coordinates[i] }; | ||
const mpoly = { | ||
type: 'Polygon', | ||
coordinates: comparisonGeoJSON.coordinates[i] | ||
}; | ||
@@ -849,5 +875,5 @@ if (within(geoJSON, mpoly) === false) { | ||
} | ||
} | ||
} // default to false | ||
// default to false | ||
return false; | ||
@@ -868,4 +894,3 @@ }; | ||
if (geoJSON.type !== 'Point' && geoJSON.type !== 'MultiPoint' && | ||
comparisonGeoJSON.type !== 'Point' && comparisonGeoJSON.type !== 'MultiPoint') { | ||
if (geoJSON.type !== 'Point' && geoJSON.type !== 'MultiPoint' && comparisonGeoJSON.type !== 'Point' && comparisonGeoJSON.type !== 'MultiPoint') { | ||
return arraysIntersectArrays(geoJSON.coordinates, comparisonGeoJSON.coordinates); | ||
@@ -887,5 +912,3 @@ } else if (geoJSON.type === 'Feature') { | ||
}; | ||
const toGeographic = (geojson) => applyConverter(geojson, positionToGeographic); | ||
const toGeographic = geojson => applyConverter(geojson, positionToGeographic); | ||
const toCircle = (center, radius, interpolate) => { | ||
@@ -909,6 +932,6 @@ const steps = interpolate || 64; | ||
}; | ||
/* cribbed from | ||
http://stackoverflow.com/questions/24145205/writing-a-function-to-convert-a-circle-to-a-polygon-using-leaflet-js | ||
*/ | ||
const createGeodesicCircle = (center, radius, interpolate) => { | ||
@@ -920,6 +943,6 @@ const steps = interpolate || 64; | ||
}; | ||
let angle; | ||
let angle; | ||
for (var i = 0; i < steps; i++) { | ||
angle = (i * 360 / steps); | ||
angle = i * 360 / steps; | ||
polygon.coordinates[0].push(destinationVincenty(center, angle, radius)); | ||
@@ -929,3 +952,2 @@ } | ||
polygon.coordinates = closedPolygon(polygon.coordinates); | ||
return polygon; | ||
@@ -936,3 +958,5 @@ }; | ||
var cos2SigmaM, sinSigma, cosSigma, deltaSigma; | ||
var a = VINCENTY.a; var b = VINCENTY.b; var f = VINCENTY.f; | ||
var a = VINCENTY.a; | ||
var b = VINCENTY.b; | ||
var f = VINCENTY.f; | ||
var lon1 = coords[0]; | ||
@@ -943,6 +967,10 @@ var lat1 = coords[1]; | ||
var alpha1 = brng * pi / 180; // converts brng degrees to radius | ||
var sinAlpha1 = Math.sin(alpha1); | ||
var cosAlpha1 = Math.cos(alpha1); | ||
var tanU1 = (1 - f) * Math.tan(lat1 * pi / 180 /* converts lat1 degrees to radius */); | ||
var cosU1 = 1 / Math.sqrt((1 + tanU1 * tanU1)); var sinU1 = tanU1 * cosU1; | ||
var tanU1 = (1 - f) * Math.tan(lat1 * pi / 180 | ||
/* converts lat1 degrees to radius */ | ||
); | ||
var cosU1 = 1 / Math.sqrt(1 + tanU1 * tanU1); | ||
var sinU1 = tanU1 * cosU1; | ||
var sigma1 = Math.atan2(tanU1, cosAlpha1); | ||
@@ -954,3 +982,5 @@ var sinAlpha = cosU1 * sinAlpha1; | ||
var B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq))); | ||
var sigma = s / (b * A); var sigmaP = 2 * Math.PI; | ||
var sigma = s / (b * A); | ||
var sigmaP = 2 * Math.PI; | ||
while (Math.abs(sigma - sigmaP) > 1e-12) { | ||
@@ -960,15 +990,14 @@ cos2SigmaM = Math.cos(2 * sigma1 + sigma); | ||
cosSigma = Math.cos(sigma); | ||
deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - | ||
B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM))); | ||
deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM))); | ||
sigmaP = sigma; | ||
sigma = s / (b * A) + deltaSigma; | ||
} | ||
var tmp = sinU1 * sinSigma - cosU1 * cosSigma * cosAlpha1; | ||
var lat2 = Math.atan2(sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1, | ||
(1 - f) * Math.sqrt(sinAlpha * sinAlpha + tmp * tmp)); | ||
var lat2 = Math.atan2(sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1, (1 - f) * Math.sqrt(sinAlpha * sinAlpha + tmp * tmp)); | ||
var lambda = Math.atan2(sinSigma * sinAlpha1, cosU1 * cosSigma - sinU1 * sinSigma * cosAlpha1); | ||
var C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha)); | ||
var lam = lambda - (1 - C) * f * sinAlpha * | ||
(sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM))); | ||
var lamFunc = lon1 + (lam * 180 / pi); // converts lam radius to degrees | ||
var lam = lambda - (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM))); | ||
var lamFunc = lon1 + lam * 180 / pi; // converts lam radius to degrees | ||
var lat2a = lat2 * 180 / pi; // converts lat2a radius to degrees | ||
@@ -981,3 +1010,2 @@ | ||
* Apache-2.0 */ | ||
/** | ||
@@ -999,3 +1027,4 @@ * Calculate the envelope surrounding the input. | ||
*/ | ||
const calculateEnvelope = (geojson) => { | ||
const calculateEnvelope = geojson => { | ||
const bounds = calculateBounds(geojson); | ||
@@ -1009,3 +1038,2 @@ return { | ||
}; | ||
/** | ||
@@ -1027,4 +1055,5 @@ * Reproject WGS84 (Lat/Lng) GeoJSON to Web Mercator. | ||
*/ | ||
const toMercator = (geojson) => applyConverter(geojson, positionToMercator); | ||
const toMercator = geojson => applyConverter(geojson, positionToMercator); | ||
export { GeographicCRS, MercatorCRS, calculateBounds, calculateEnvelope, contains, convexHull, intersects, isConvex, polygonContainsPoint, positionToGeographic, positionToMercator, toCircle, toGeographic, toMercator, within }; |
/* @preserve | ||
* @terraformer/spatial - v2.0.4 - MIT | ||
* @terraformer/spatial - v2.0.6 - MIT | ||
* Copyright (c) 2012-2020 Environmental Systems Research Institute, Inc. | ||
* Sun May 17 2020 12:38:49 GMT-0700 (Pacific Daylight Time) | ||
* Mon May 18 2020 14:16:27 GMT-0700 (Pacific Daylight Time) | ||
*/ | ||
@@ -14,5 +14,4 @@ (function (global, factory) { | ||
* Apache-2.0 */ | ||
const isNumber = n => !isNaN(parseFloat(n)) && isFinite(n); | ||
const isNumber = (n) => !isNaN(parseFloat(n)) && isFinite(n); | ||
const edgeIntersectsEdge = (a1, a2, b1, b2) => { | ||
@@ -59,17 +58,16 @@ var uaT = (b2[0] - b1[0]) * (a1[1] - b1[1]) - (b2[1] - b1[1]) * (a1[0] - b1[0]); | ||
} | ||
return false; | ||
}; | ||
const coordinatesContainPoint = (coordinates, point) => { | ||
let contains = false; | ||
for (let 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])) { | ||
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]) { | ||
contains = !contains; | ||
} | ||
} | ||
return contains; | ||
}; | ||
const pointsEqual = (a, b) => { | ||
@@ -88,3 +86,2 @@ for (let i = 0; i < a.length; i++) { | ||
const RADIANS_PER_DEGREE = 0.017453292519943; | ||
const MercatorCRS = { | ||
@@ -97,3 +94,2 @@ type: 'link', | ||
}; | ||
const GeographicCRS = { | ||
@@ -110,16 +106,15 @@ type: 'link', | ||
*/ | ||
const radToDeg = (rad) => rad * DEGREES_PER_RADIAN; | ||
const radToDeg = rad => rad * DEGREES_PER_RADIAN; | ||
/* | ||
Internal: Convert degrees to radians. Used by spatial reference converters. | ||
*/ | ||
const degToRad = (deg) => deg * RADIANS_PER_DEGREE; | ||
const positionToGeographic = (position) => { | ||
const degToRad = deg => deg * RADIANS_PER_DEGREE; | ||
const positionToGeographic = position => { | ||
const x = position[0]; | ||
const 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))))]; | ||
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 positionToMercator = position => { | ||
const lng = position[0]; | ||
@@ -133,2 +128,3 @@ const lat = Math.max(Math.min(position[1], 89.99999), -89.99999); | ||
*/ | ||
const compSort = (p1, p2) => { | ||
@@ -147,6 +143,6 @@ if (p1[0] > p2[0]) { | ||
}; | ||
/* | ||
Internal: -1,0,1 comparison function | ||
*/ | ||
const cmp = (a, b) => { | ||
@@ -161,6 +157,7 @@ if (a < b) { | ||
}; | ||
/* | ||
Internal: used to determine turn | ||
*/ | ||
const turn = (p, q, r) => { | ||
@@ -170,6 +167,7 @@ // Returns -1, 0, 1 if p,q,r forms a right, straight, or left turn. | ||
}; | ||
/* | ||
Internal: used to determine euclidean distance between two points | ||
*/ | ||
const euclideanDistance = (p, q) => { | ||
@@ -179,3 +177,2 @@ // Returns the squared Euclidean distance between p and q. | ||
const dy = q[1] - p[1]; | ||
return dx * dx + dy * dy; | ||
@@ -187,15 +184,17 @@ }; | ||
let q = p; | ||
for (const r in points) { | ||
const t = turn(p, q, points[r]); | ||
if (t === -1 || (t === 0 && euclideanDistance(p, points[r]) > euclideanDistance(p, q))) { | ||
if (t === -1 || t === 0 && euclideanDistance(p, points[r]) > euclideanDistance(p, q)) { | ||
q = points[r]; | ||
} | ||
} | ||
return q; | ||
}; | ||
const coordinateConvexHull = (points) => { | ||
const coordinateConvexHull = points => { | ||
// implementation of the Jarvis March algorithm | ||
// adapted from http://tixxit.wordpress.com/2009/12/09/jarvis-march/ | ||
if (points.length === 0) { | ||
@@ -205,5 +204,5 @@ return []; | ||
return points; | ||
} | ||
} // Returns the points on the convex hull of points in CCW order. | ||
// Returns the points on the convex hull of points in CCW order. | ||
const hull = [points.sort(compSort)[0]]; | ||
@@ -221,7 +220,7 @@ | ||
}; | ||
/* | ||
Internal: Returns a copy of coordinates for a closed polygon | ||
*/ | ||
const closedPolygon = (coordinates) => { | ||
const closedPolygon = coordinates => { | ||
const outer = []; | ||
@@ -231,2 +230,3 @@ | ||
const inner = coordinates[i].slice(); | ||
if (pointsEqual(inner[0], inner[inner.length - 1]) === false) { | ||
@@ -241,7 +241,7 @@ inner.push(inner[0]); | ||
}; | ||
/* | ||
Internal: safe warning | ||
*/ | ||
function warn () { | ||
function warn() { | ||
const args = Array.prototype.slice.apply(arguments); | ||
@@ -253,6 +253,6 @@ | ||
} | ||
/* | ||
Internal: Loop over each array in a geojson object and apply a function to it. Used by spatial reference converters. | ||
*/ | ||
const eachPosition = (coordinates, func) => { | ||
@@ -263,4 +263,5 @@ for (let i = 0; i < coordinates.length; i++) { | ||
coordinates[i] = func(coordinates[i]); | ||
} | ||
// we found an coordinates array it again and run the function against it | ||
} // we found an coordinates array it again and run the function against it | ||
if (typeof coordinates[i] === 'object') { | ||
@@ -270,8 +271,10 @@ coordinates[i] = eachPosition(coordinates[i], func); | ||
} | ||
return coordinates; | ||
}; | ||
/* | ||
Apply a function agaist all positions in a geojson object. Used by spatial reference converters. | ||
*/ | ||
const applyConverter = (geojson, converter, noCrs) => { | ||
@@ -306,3 +309,2 @@ if (geojson.type === 'Point') { | ||
}; | ||
const coordinatesEqual = (a, b) => { | ||
@@ -320,2 +322,3 @@ if (a.length !== b.length) { | ||
} | ||
for (let j = 0; j < na.length; j++) { | ||
@@ -345,4 +348,7 @@ if (na[i][j] !== nb[i][j]) { | ||
*/ | ||
const calculateBoundsFromNestedArrays = (array) => { | ||
let x1 = null; let x2 = null; let y1 = null; let y2 = null; | ||
const calculateBoundsFromNestedArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
@@ -354,3 +360,2 @@ for (let i = 0; i < array.length; i++) { | ||
const lonlat = inner[j]; | ||
const lon = lonlat[0]; | ||
@@ -387,3 +392,2 @@ const lat = lonlat[1]; | ||
}; | ||
/* | ||
@@ -397,9 +401,13 @@ Internal: Calculate a bounding box from an array of arrays of arrays | ||
*/ | ||
const calculateBoundsFromNestedArrayOfArrays = (array) => { | ||
let x1 = null; let x2 = null; let y1 = null; let y2 = null; | ||
const calculateBoundsFromNestedArrayOfArrays = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
const inner = array[i]; | ||
const inner = array[i]; // return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
// return calculateBoundsFromNestedArrays(inner); // more DRY? | ||
for (let j = 0; j < inner.length; j++) { | ||
@@ -410,3 +418,2 @@ const innerinner = inner[j]; | ||
const lonlat = innerinner[k]; | ||
const lon = lonlat[0]; | ||
@@ -444,3 +451,2 @@ const lat = lonlat[1]; | ||
}; | ||
/* | ||
@@ -452,5 +458,10 @@ Internal: Calculate a bounding box from an array of positions | ||
*/ | ||
const calculateBoundsFromArray = (array) => { | ||
let x1 = null; let x2 = null; let y1 = null; let y2 = null; | ||
const calculateBoundsFromArray = array => { | ||
let x1 = null; | ||
let x2 = null; | ||
let y1 = null; | ||
let y2 = null; | ||
for (let i = 0; i < array.length; i++) { | ||
@@ -488,8 +499,10 @@ const lonlat = array[i]; | ||
}; | ||
/* | ||
Internal: Calculate an bounding box for a feature collection | ||
*/ | ||
const calculateBoundsForFeatureCollection = (featureCollection) => { | ||
const calculateBoundsForFeatureCollection = featureCollection => { | ||
const extents = []; | ||
for (let i = featureCollection.features.length - 1; i >= 0; i--) { | ||
@@ -503,7 +516,8 @@ const extent = calculateBounds(featureCollection.features[i].geometry); | ||
}; | ||
/* | ||
Internal: Calculate an bounding box for a geometry collection | ||
*/ | ||
const calculateBoundsForGeometryCollection = (geometryCollection) => { | ||
const calculateBoundsForGeometryCollection = geometryCollection => { | ||
const extents = []; | ||
@@ -520,3 +534,3 @@ | ||
const calculateBounds = (geojson) => { | ||
const calculateBounds = geojson => { | ||
if (geojson.type) { | ||
@@ -555,7 +569,11 @@ switch (geojson.type) { | ||
} | ||
return null; | ||
}; | ||
const convexHull = (geojson) => { | ||
let coordinates = []; let i; let j; | ||
const convexHull = geojson => { | ||
let coordinates = []; | ||
let i; | ||
let j; | ||
if (geojson.type === 'Point') { | ||
@@ -574,2 +592,3 @@ return null; | ||
} | ||
if (coordinates.length < 3) { | ||
@@ -588,2 +607,3 @@ return null; | ||
} | ||
if (coordinates.length < 3) { | ||
@@ -604,4 +624,3 @@ return null; | ||
}; | ||
const isConvex = (points) => { | ||
const isConvex = points => { | ||
let ltz; | ||
@@ -613,5 +632,4 @@ | ||
const p3 = points[i + 2]; | ||
const v = [p2[0] - p1[0], p2[1] - p1[1]]; | ||
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 | ||
// 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]; | ||
@@ -626,3 +644,3 @@ | ||
} else { | ||
if ((ltz && res > 0) || (!ltz && res < 0)) { | ||
if (ltz && res > 0 || !ltz && res < 0) { | ||
return false; | ||
@@ -638,5 +656,7 @@ } | ||
if (polygon && polygon.length) { | ||
if (polygon.length === 1) { // polygon with no holes | ||
if (polygon.length === 1) { | ||
// polygon with no holes | ||
return coordinatesContainPoint(polygon[0], point); | ||
} else { // polygon with holes | ||
} else { | ||
// polygon with holes | ||
if (coordinatesContainPoint(polygon[0], point)) { | ||
@@ -648,2 +668,3 @@ for (let i = 1; i < polygon.length; i++) { | ||
} | ||
return true; | ||
@@ -660,10 +681,9 @@ } else { | ||
const within = (geoJSON, comparisonGeoJSON) => { | ||
let coordinates, i, contains; | ||
let coordinates, i, contains; // if we are passed a feature, use the polygon inside instead | ||
// if we are passed a feature, use the polygon inside instead | ||
if (comparisonGeoJSON.type === 'Feature') { | ||
comparisonGeoJSON = comparisonGeoJSON.geometry; | ||
} | ||
} // point.within(point) :: equality | ||
// point.within(point) :: equality | ||
if (comparisonGeoJSON.type === 'Point') { | ||
@@ -673,9 +693,12 @@ if (geoJSON.type === 'Point') { | ||
} | ||
} | ||
} // point.within(multilinestring) | ||
// point.within(multilinestring) | ||
if (comparisonGeoJSON.type === 'MultiLineString') { | ||
if (geoJSON.type === 'Point') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const linestring = { type: 'LineString', coordinates: comparisonGeoJSON.coordinates[i] }; | ||
const linestring = { | ||
type: 'LineString', | ||
coordinates: comparisonGeoJSON.coordinates[i] | ||
}; | ||
@@ -687,5 +710,5 @@ if (within(geoJSON, linestring)) { | ||
} | ||
} | ||
} // point.within(linestring), point.within(multipoint) | ||
// point.within(linestring), point.within(multipoint) | ||
if (comparisonGeoJSON.type === 'LineString' || comparisonGeoJSON.type === 'MultiPoint') { | ||
@@ -721,9 +744,6 @@ if (geoJSON.type === 'Point') { | ||
return false; | ||
} | ||
} // point.within(polygon) | ||
// point.within(polygon) | ||
} else if (geoJSON.type === 'Point') { | ||
return polygonContainsPoint(comparisonGeoJSON.coordinates, geoJSON.coordinates); | ||
// linestring/multipoint withing polygon | ||
return polygonContainsPoint(comparisonGeoJSON.coordinates, geoJSON.coordinates); // linestring/multipoint withing polygon | ||
} else if (geoJSON.type === 'LineString' || geoJSON.type === 'MultiPoint') { | ||
@@ -740,5 +760,3 @@ if (!geoJSON.coordinates || geoJSON.coordinates.length === 0) { | ||
return true; | ||
// multilinestring.within(polygon) | ||
return true; // multilinestring.within(polygon) | ||
} else if (geoJSON.type === 'MultiLineString') { | ||
@@ -750,2 +768,3 @@ for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
}; | ||
if (within(ls, comparisonGeoJSON) === false) { | ||
@@ -757,8 +776,9 @@ contains++; | ||
return true; | ||
// multipolygon.within(polygon) | ||
return true; // multipolygon.within(polygon) | ||
} else if (geoJSON.type === 'MultiPolygon') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const p1 = { type: 'Polygon', coordinates: geoJSON.coordinates[i] }; | ||
const p1 = { | ||
type: 'Polygon', | ||
coordinates: geoJSON.coordinates[i] | ||
}; | ||
@@ -780,2 +800,3 @@ if (within(p1, comparisonGeoJSON) === false) { | ||
coordinates = comparisonGeoJSON.coordinates[i]; | ||
if (polygonContainsPoint(coordinates, geoJSON.coordinates) && arraysIntersectArrays([geoJSON.coordinates], comparisonGeoJSON.coordinates) === false) { | ||
@@ -787,4 +808,3 @@ return true; | ||
return false; | ||
// polygon.within(multipolygon) | ||
return false; // polygon.within(multipolygon) | ||
} else if (geoJSON.type === 'Polygon') { | ||
@@ -805,2 +825,3 @@ for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
coordinates = comparisonGeoJSON.coordinates[i]; | ||
if (polygonContainsPoint(coordinates, geoJSON.coordinates[0][0]) === false) { | ||
@@ -815,8 +836,10 @@ contains = false; | ||
} | ||
} | ||
} // linestring.within(multipolygon), multipoint.within(multipolygon) | ||
// linestring.within(multipolygon), multipoint.within(multipolygon) | ||
} else if (geoJSON.type === 'LineString' || geoJSON.type === 'MultiPoint') { | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const poly = { type: 'Polygon', coordinates: comparisonGeoJSON.coordinates[i] }; | ||
const poly = { | ||
type: 'Polygon', | ||
coordinates: comparisonGeoJSON.coordinates[i] | ||
}; | ||
@@ -828,8 +851,10 @@ if (within(geoJSON, poly)) { | ||
return false; | ||
} | ||
} // multilinestring.within(multipolygon) | ||
// multilinestring.within(multipolygon) | ||
} else if (geoJSON.type === 'MultiLineString') { | ||
for (i = 0; i < geoJSON.coordinates.length; i++) { | ||
const ls = { type: 'LineString', coordinates: geoJSON.coordinates[i] }; | ||
const ls = { | ||
type: 'LineString', | ||
coordinates: geoJSON.coordinates[i] | ||
}; | ||
@@ -841,8 +866,9 @@ if (within(ls, comparisonGeoJSON) === false) { | ||
return true; | ||
// multipolygon.within(multipolygon) | ||
return true; // multipolygon.within(multipolygon) | ||
} else if (geoJSON.type === 'MultiPolygon') { | ||
for (i = 0; i < comparisonGeoJSON.coordinates.length; i++) { | ||
const mpoly = { type: 'Polygon', coordinates: comparisonGeoJSON.coordinates[i] }; | ||
const mpoly = { | ||
type: 'Polygon', | ||
coordinates: comparisonGeoJSON.coordinates[i] | ||
}; | ||
@@ -856,5 +882,5 @@ if (within(geoJSON, mpoly) === false) { | ||
} | ||
} | ||
} // default to false | ||
// default to false | ||
return false; | ||
@@ -875,4 +901,3 @@ }; | ||
if (geoJSON.type !== 'Point' && geoJSON.type !== 'MultiPoint' && | ||
comparisonGeoJSON.type !== 'Point' && comparisonGeoJSON.type !== 'MultiPoint') { | ||
if (geoJSON.type !== 'Point' && geoJSON.type !== 'MultiPoint' && comparisonGeoJSON.type !== 'Point' && comparisonGeoJSON.type !== 'MultiPoint') { | ||
return arraysIntersectArrays(geoJSON.coordinates, comparisonGeoJSON.coordinates); | ||
@@ -894,5 +919,3 @@ } else if (geoJSON.type === 'Feature') { | ||
}; | ||
const toGeographic = (geojson) => applyConverter(geojson, positionToGeographic); | ||
const toGeographic = geojson => applyConverter(geojson, positionToGeographic); | ||
const toCircle = (center, radius, interpolate) => { | ||
@@ -916,6 +939,6 @@ const steps = interpolate || 64; | ||
}; | ||
/* cribbed from | ||
http://stackoverflow.com/questions/24145205/writing-a-function-to-convert-a-circle-to-a-polygon-using-leaflet-js | ||
*/ | ||
const createGeodesicCircle = (center, radius, interpolate) => { | ||
@@ -927,6 +950,6 @@ const steps = interpolate || 64; | ||
}; | ||
let angle; | ||
let angle; | ||
for (var i = 0; i < steps; i++) { | ||
angle = (i * 360 / steps); | ||
angle = i * 360 / steps; | ||
polygon.coordinates[0].push(destinationVincenty(center, angle, radius)); | ||
@@ -936,3 +959,2 @@ } | ||
polygon.coordinates = closedPolygon(polygon.coordinates); | ||
return polygon; | ||
@@ -943,3 +965,5 @@ }; | ||
var cos2SigmaM, sinSigma, cosSigma, deltaSigma; | ||
var a = VINCENTY.a; var b = VINCENTY.b; var f = VINCENTY.f; | ||
var a = VINCENTY.a; | ||
var b = VINCENTY.b; | ||
var f = VINCENTY.f; | ||
var lon1 = coords[0]; | ||
@@ -950,6 +974,10 @@ var lat1 = coords[1]; | ||
var alpha1 = brng * pi / 180; // converts brng degrees to radius | ||
var sinAlpha1 = Math.sin(alpha1); | ||
var cosAlpha1 = Math.cos(alpha1); | ||
var tanU1 = (1 - f) * Math.tan(lat1 * pi / 180 /* converts lat1 degrees to radius */); | ||
var cosU1 = 1 / Math.sqrt((1 + tanU1 * tanU1)); var sinU1 = tanU1 * cosU1; | ||
var tanU1 = (1 - f) * Math.tan(lat1 * pi / 180 | ||
/* converts lat1 degrees to radius */ | ||
); | ||
var cosU1 = 1 / Math.sqrt(1 + tanU1 * tanU1); | ||
var sinU1 = tanU1 * cosU1; | ||
var sigma1 = Math.atan2(tanU1, cosAlpha1); | ||
@@ -961,3 +989,5 @@ var sinAlpha = cosU1 * sinAlpha1; | ||
var B = uSq / 1024 * (256 + uSq * (-128 + uSq * (74 - 47 * uSq))); | ||
var sigma = s / (b * A); var sigmaP = 2 * Math.PI; | ||
var sigma = s / (b * A); | ||
var sigmaP = 2 * Math.PI; | ||
while (Math.abs(sigma - sigmaP) > 1e-12) { | ||
@@ -967,15 +997,14 @@ cos2SigmaM = Math.cos(2 * sigma1 + sigma); | ||
cosSigma = Math.cos(sigma); | ||
deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - | ||
B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM))); | ||
deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM) - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM))); | ||
sigmaP = sigma; | ||
sigma = s / (b * A) + deltaSigma; | ||
} | ||
var tmp = sinU1 * sinSigma - cosU1 * cosSigma * cosAlpha1; | ||
var lat2 = Math.atan2(sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1, | ||
(1 - f) * Math.sqrt(sinAlpha * sinAlpha + tmp * tmp)); | ||
var lat2 = Math.atan2(sinU1 * cosSigma + cosU1 * sinSigma * cosAlpha1, (1 - f) * Math.sqrt(sinAlpha * sinAlpha + tmp * tmp)); | ||
var lambda = Math.atan2(sinSigma * sinAlpha1, cosU1 * cosSigma - sinU1 * sinSigma * cosAlpha1); | ||
var C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha)); | ||
var lam = lambda - (1 - C) * f * sinAlpha * | ||
(sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM))); | ||
var lamFunc = lon1 + (lam * 180 / pi); // converts lam radius to degrees | ||
var lam = lambda - (1 - C) * f * sinAlpha * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM))); | ||
var lamFunc = lon1 + lam * 180 / pi; // converts lam radius to degrees | ||
var lat2a = lat2 * 180 / pi; // converts lat2a radius to degrees | ||
@@ -988,3 +1017,2 @@ | ||
* Apache-2.0 */ | ||
/** | ||
@@ -1006,3 +1034,4 @@ * Calculate the envelope surrounding the input. | ||
*/ | ||
const calculateEnvelope = (geojson) => { | ||
const calculateEnvelope = geojson => { | ||
const bounds = calculateBounds(geojson); | ||
@@ -1016,3 +1045,2 @@ return { | ||
}; | ||
/** | ||
@@ -1034,4 +1062,5 @@ * Reproject WGS84 (Lat/Lng) GeoJSON to Web Mercator. | ||
*/ | ||
const toMercator = (geojson) => applyConverter(geojson, positionToMercator); | ||
const toMercator = geojson => applyConverter(geojson, positionToMercator); | ||
exports.GeographicCRS = GeographicCRS; | ||
@@ -1038,0 +1067,0 @@ exports.MercatorCRS = MercatorCRS; |
{ | ||
"name": "@terraformer/spatial", | ||
"description": "Spatial predicates for GeoJSON.", | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"author": "Patrick Arlt <patrick.arlt@gmail.com>", | ||
@@ -15,3 +15,3 @@ "bugs": { | ||
"dependencies": { | ||
"@terraformer/common": "^2.0.0" | ||
"@terraformer/common": "^2.0.6" | ||
}, | ||
@@ -45,3 +45,3 @@ "files": [ | ||
}, | ||
"gitHead": "9f19918eb640d4c8817da255555a9f525442f3f0" | ||
"gitHead": "d21bc2e4f11231029c64cefd8d64ee23a2327961" | ||
} |
73287
1687
Updated@terraformer/common@^2.0.6