UNPKG

overpass-frontend

Version:

A JavaScript (NodeJS/Browser) library to easily access data from OpenStreetMap via Overpass API or from an OSM File. The objects can directly be used with LeafletJS or exported to GeoJSON. Data will be cached in the browser memory.

1,417 lines (1,367 loc) 1.89 MB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ const OverpassFrontend = require('./') if (typeof window !== 'undefined') { window.OverpassFrontend = OverpassFrontend } },{"./":207}],2:[function(require,module,exports){ module.exports = rewind; function rewind(gj, outer) { var type = gj && gj.type, i; if (type === 'FeatureCollection') { for (i = 0; i < gj.features.length; i++) rewind(gj.features[i], outer); } else if (type === 'GeometryCollection') { for (i = 0; i < gj.geometries.length; i++) rewind(gj.geometries[i], outer); } else if (type === 'Feature') { rewind(gj.geometry, outer); } else if (type === 'Polygon') { rewindRings(gj.coordinates, outer); } else if (type === 'MultiPolygon') { for (i = 0; i < gj.coordinates.length; i++) rewindRings(gj.coordinates[i], outer); } return gj; } function rewindRings(rings, outer) { if (rings.length === 0) return; rewindRing(rings[0], outer); for (var i = 1; i < rings.length; i++) { rewindRing(rings[i], !outer); } } function rewindRing(ring, dir) { var area = 0, err = 0; for (var i = 0, len = ring.length, j = len - 1; i < len; j = i++) { var k = (ring[i][0] - ring[j][0]) * (ring[j][1] + ring[i][1]); var m = area + k; err += Math.abs(area) >= Math.abs(k) ? area - m + k : k - m + area; area = m; } if (area + err >= 0 !== !!dir) ring.reverse(); } },{}],3:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var meta_1 = require("@turf/meta"); /** * Takes a set of features, calculates the bbox of all input features, and returns a bounding box. * * @name bbox * @param {GeoJSON} geojson any GeoJSON object * @returns {BBox} bbox extent in [minX, minY, maxX, maxY] order * @example * var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]]); * var bbox = turf.bbox(line); * var bboxPolygon = turf.bboxPolygon(bbox); * * //addToMap * var addToMap = [line, bboxPolygon] */ function bbox(geojson) { var result = [Infinity, Infinity, -Infinity, -Infinity]; meta_1.coordEach(geojson, function (coord) { if (result[0] > coord[0]) { result[0] = coord[0]; } if (result[1] > coord[1]) { result[1] = coord[1]; } if (result[2] < coord[0]) { result[2] = coord[0]; } if (result[3] < coord[1]) { result[3] = coord[1]; } }); return result; } bbox["default"] = bbox; exports.default = bbox; },{"@turf/meta":19}],4:[function(require,module,exports){ "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon")); var line_intersect_1 = __importDefault(require("@turf/line-intersect")); var meta_1 = require("@turf/meta"); var polygon_to_line_1 = __importDefault(require("@turf/polygon-to-line")); /** * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set. * * @name booleanDisjoint * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry * @returns {boolean} true/false * @example * var point = turf.point([2, 2]); * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]); * * turf.booleanDisjoint(line, point); * //=true */ function booleanDisjoint(feature1, feature2) { var bool = true; meta_1.flattenEach(feature1, function (flatten1) { meta_1.flattenEach(feature2, function (flatten2) { if (bool === false) { return false; } bool = disjoint(flatten1.geometry, flatten2.geometry); }); }); return bool; } /** * Disjoint operation for simple Geometries (Point/LineString/Polygon) * * @private * @param {Geometry<any>} geom1 GeoJSON Geometry * @param {Geometry<any>} geom2 GeoJSON Geometry * @returns {boolean} true/false */ function disjoint(geom1, geom2) { switch (geom1.type) { case "Point": switch (geom2.type) { case "Point": return !compareCoords(geom1.coordinates, geom2.coordinates); case "LineString": return !isPointOnLine(geom2, geom1); case "Polygon": return !boolean_point_in_polygon_1.default(geom1, geom2); } /* istanbul ignore next */ break; case "LineString": switch (geom2.type) { case "Point": return !isPointOnLine(geom1, geom2); case "LineString": return !isLineOnLine(geom1, geom2); case "Polygon": return !isLineInPoly(geom2, geom1); } /* istanbul ignore next */ break; case "Polygon": switch (geom2.type) { case "Point": return !boolean_point_in_polygon_1.default(geom2, geom1); case "LineString": return !isLineInPoly(geom1, geom2); case "Polygon": return !isPolyInPoly(geom2, geom1); } } return false; } // http://stackoverflow.com/a/11908158/1979085 function isPointOnLine(lineString, pt) { for (var i = 0; i < lineString.coordinates.length - 1; i++) { if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], pt.coordinates)) { return true; } } return false; } function isLineOnLine(lineString1, lineString2) { var doLinesIntersect = line_intersect_1.default(lineString1, lineString2); if (doLinesIntersect.features.length > 0) { return true; } return false; } function isLineInPoly(polygon, lineString) { for (var _i = 0, _a = lineString.coordinates; _i < _a.length; _i++) { var coord = _a[_i]; if (boolean_point_in_polygon_1.default(coord, polygon)) { return true; } } var doLinesIntersect = line_intersect_1.default(lineString, polygon_to_line_1.default(polygon)); if (doLinesIntersect.features.length > 0) { return true; } return false; } /** * Is Polygon (geom1) in Polygon (geom2) * Only takes into account outer rings * See http://stackoverflow.com/a/4833823/1979085 * * @private * @param {Geometry|Feature<Polygon>} feature1 Polygon1 * @param {Geometry|Feature<Polygon>} feature2 Polygon2 * @returns {boolean} true/false */ function isPolyInPoly(feature1, feature2) { for (var _i = 0, _a = feature1.coordinates[0]; _i < _a.length; _i++) { var coord1 = _a[_i]; if (boolean_point_in_polygon_1.default(coord1, feature2)) { return true; } } for (var _b = 0, _c = feature2.coordinates[0]; _b < _c.length; _b++) { var coord2 = _c[_b]; if (boolean_point_in_polygon_1.default(coord2, feature1)) { return true; } } var doLinesIntersect = line_intersect_1.default(polygon_to_line_1.default(feature1), polygon_to_line_1.default(feature2)); if (doLinesIntersect.features.length > 0) { return true; } return false; } function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) { var dxc = pt[0] - lineSegmentStart[0]; var dyc = pt[1] - lineSegmentStart[1]; var dxl = lineSegmentEnd[0] - lineSegmentStart[0]; var dyl = lineSegmentEnd[1] - lineSegmentStart[1]; var cross = dxc * dyl - dyc * dxl; if (cross !== 0) { return false; } if (Math.abs(dxl) >= Math.abs(dyl)) { if (dxl > 0) { return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0]; } else { return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0]; } } else if (dyl > 0) { return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1]; } else { return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1]; } } /** * compareCoords * * @private * @param {Position} pair1 point [x,y] * @param {Position} pair2 point [x,y] * @returns {boolean} true/false if coord pairs match */ function compareCoords(pair1, pair2) { return pair1[0] === pair2[0] && pair1[1] === pair2[1]; } exports.default = booleanDisjoint; },{"@turf/boolean-point-in-polygon":6,"@turf/line-intersect":17,"@turf/meta":19,"@turf/polygon-to-line":20}],5:[function(require,module,exports){ "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var boolean_disjoint_1 = __importDefault(require("@turf/boolean-disjoint")); var meta_1 = require("@turf/meta"); /** * Boolean-intersects returns (TRUE) two geometries intersect. * * @name booleanIntersects * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry * @returns {boolean} true/false * @example * var point = turf.point([2, 2]); * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]); * * turf.booleanIntersects(line, point); * //=true */ function booleanIntersects(feature1, feature2) { var bool = false; meta_1.flattenEach(feature1, function (flatten1) { meta_1.flattenEach(feature2, function (flatten2) { if (bool === true) { return true; } bool = !boolean_disjoint_1.default(flatten1.geometry, flatten2.geometry); }); }); return bool; } exports.default = booleanIntersects; },{"@turf/boolean-disjoint":4,"@turf/meta":19}],6:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var invariant_1 = require("@turf/invariant"); // http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule // modified from: https://github.com/substack/point-in-polygon/blob/master/index.js // which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html /** * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point * resides inside the polygon. The polygon can be convex or concave. The function accounts for holes. * * @name booleanPointInPolygon * @param {Coord} point input point * @param {Feature<Polygon|MultiPolygon>} polygon input polygon or multipolygon * @param {Object} [options={}] Optional parameters * @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if * the point is inside the polygon otherwise false. * @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon * @example * var pt = turf.point([-77, 44]); * var poly = turf.polygon([[ * [-81, 41], * [-81, 47], * [-72, 47], * [-72, 41], * [-81, 41] * ]]); * * turf.booleanPointInPolygon(pt, poly); * //= true */ function booleanPointInPolygon(point, polygon, options) { if (options === void 0) { options = {}; } // validation if (!point) { throw new Error("point is required"); } if (!polygon) { throw new Error("polygon is required"); } var pt = invariant_1.getCoord(point); var geom = invariant_1.getGeom(polygon); var type = geom.type; var bbox = polygon.bbox; var polys = geom.coordinates; // Quick elimination if point is not inside bbox if (bbox && inBBox(pt, bbox) === false) { return false; } // normalize to multipolygon if (type === "Polygon") { polys = [polys]; } var insidePoly = false; for (var i = 0; i < polys.length && !insidePoly; i++) { // check if it is in the outer ring first if (inRing(pt, polys[i][0], options.ignoreBoundary)) { var inHole = false; var k = 1; // check for the point in any of the holes while (k < polys[i].length && !inHole) { if (inRing(pt, polys[i][k], !options.ignoreBoundary)) { inHole = true; } k++; } if (!inHole) { insidePoly = true; } } } return insidePoly; } exports.default = booleanPointInPolygon; /** * inRing * * @private * @param {Array<number>} pt [x,y] * @param {Array<Array<number>>} ring [[x,y], [x,y],..] * @param {boolean} ignoreBoundary ignoreBoundary * @returns {boolean} inRing */ function inRing(pt, ring, ignoreBoundary) { var isInside = false; if (ring[0][0] === ring[ring.length - 1][0] && ring[0][1] === ring[ring.length - 1][1]) { ring = ring.slice(0, ring.length - 1); } for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) { var xi = ring[i][0]; var yi = ring[i][1]; var xj = ring[j][0]; var yj = ring[j][1]; var onBoundary = pt[1] * (xi - xj) + yi * (xj - pt[0]) + yj * (pt[0] - xi) === 0 && (xi - pt[0]) * (xj - pt[0]) <= 0 && (yi - pt[1]) * (yj - pt[1]) <= 0; if (onBoundary) { return !ignoreBoundary; } var intersect = yi > pt[1] !== yj > pt[1] && pt[0] < ((xj - xi) * (pt[1] - yi)) / (yj - yi) + xi; if (intersect) { isInside = !isInside; } } return isInside; } /** * inBBox * * @private * @param {Position} pt point [x,y] * @param {BBox} bbox BBox [west, south, east, north] * @returns {boolean} true/false if point is inside BBox */ function inBBox(pt, bbox) { return (bbox[0] <= pt[0] && bbox[1] <= pt[1] && bbox[2] >= pt[0] && bbox[3] >= pt[1]); } },{"@turf/invariant":15}],7:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var invariant_1 = require("@turf/invariant"); /** * Returns true if a point is on a line. Accepts a optional parameter to ignore the * start and end vertices of the linestring. * * @name booleanPointOnLine * @param {Coord} pt GeoJSON Point * @param {Feature<LineString>} line GeoJSON LineString * @param {Object} [options={}] Optional parameters * @param {boolean} [options.ignoreEndVertices=false] whether to ignore the start and end vertices. * @param {number} [options.epsilon] Fractional number to compare with the cross product result. Useful for dealing with floating points such as lng/lat points * @returns {boolean} true/false * @example * var pt = turf.point([0, 0]); * var line = turf.lineString([[-1, -1],[1, 1],[1.5, 2.2]]); * var isPointOnLine = turf.booleanPointOnLine(pt, line); * //=true */ function booleanPointOnLine(pt, line, options) { if (options === void 0) { options = {}; } // Normalize inputs var ptCoords = invariant_1.getCoord(pt); var lineCoords = invariant_1.getCoords(line); // Main for (var i = 0; i < lineCoords.length - 1; i++) { var ignoreBoundary = false; if (options.ignoreEndVertices) { if (i === 0) { ignoreBoundary = "start"; } if (i === lineCoords.length - 2) { ignoreBoundary = "end"; } if (i === 0 && i + 1 === lineCoords.length - 1) { ignoreBoundary = "both"; } } if (isPointOnLineSegment(lineCoords[i], lineCoords[i + 1], ptCoords, ignoreBoundary, typeof options.epsilon === "undefined" ? null : options.epsilon)) { return true; } } return false; } // See http://stackoverflow.com/a/4833823/1979085 // See https://stackoverflow.com/a/328122/1048847 /** * @private * @param {Position} lineSegmentStart coord pair of start of line * @param {Position} lineSegmentEnd coord pair of end of line * @param {Position} pt coord pair of point to check * @param {boolean|string} excludeBoundary whether the point is allowed to fall on the line ends. * @param {number} epsilon Fractional number to compare with the cross product result. Useful for dealing with floating points such as lng/lat points * If true which end to ignore. * @returns {boolean} true/false */ function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt, excludeBoundary, epsilon) { var x = pt[0]; var y = pt[1]; var x1 = lineSegmentStart[0]; var y1 = lineSegmentStart[1]; var x2 = lineSegmentEnd[0]; var y2 = lineSegmentEnd[1]; var dxc = pt[0] - x1; var dyc = pt[1] - y1; var dxl = x2 - x1; var dyl = y2 - y1; var cross = dxc * dyl - dyc * dxl; if (epsilon !== null) { if (Math.abs(cross) > epsilon) { return false; } } else if (cross !== 0) { return false; } if (!excludeBoundary) { if (Math.abs(dxl) >= Math.abs(dyl)) { return dxl > 0 ? x1 <= x && x <= x2 : x2 <= x && x <= x1; } return dyl > 0 ? y1 <= y && y <= y2 : y2 <= y && y <= y1; } else if (excludeBoundary === "start") { if (Math.abs(dxl) >= Math.abs(dyl)) { return dxl > 0 ? x1 < x && x <= x2 : x2 <= x && x < x1; } return dyl > 0 ? y1 < y && y <= y2 : y2 <= y && y < y1; } else if (excludeBoundary === "end") { if (Math.abs(dxl) >= Math.abs(dyl)) { return dxl > 0 ? x1 <= x && x < x2 : x2 < x && x <= x1; } return dyl > 0 ? y1 <= y && y < y2 : y2 < y && y <= y1; } else if (excludeBoundary === "both") { if (Math.abs(dxl) >= Math.abs(dyl)) { return dxl > 0 ? x1 < x && x < x2 : x2 < x && x < x1; } return dyl > 0 ? y1 < y && y < y2 : y2 < y && y < y1; } return false; } exports.default = booleanPointOnLine; },{"@turf/invariant":15}],8:[function(require,module,exports){ "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var bbox_1 = __importDefault(require("@turf/bbox")); var boolean_point_on_line_1 = __importDefault(require("@turf/boolean-point-on-line")); var boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon")); var invariant_1 = require("@turf/invariant"); /** * Boolean-within returns true if the first geometry is completely within the second geometry. * The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a) * must not intersect the exterior of the secondary (geometry b). * Boolean-within returns the exact opposite result of the `@turf/boolean-contains`. * * @name booleanWithin * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry * @returns {boolean} true/false * @example * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]); * var point = turf.point([1, 2]); * * turf.booleanWithin(point, line); * //=true */ function booleanWithin(feature1, feature2) { var geom1 = invariant_1.getGeom(feature1); var geom2 = invariant_1.getGeom(feature2); var type1 = geom1.type; var type2 = geom2.type; switch (type1) { case "Point": switch (type2) { case "MultiPoint": return isPointInMultiPoint(geom1, geom2); case "LineString": return boolean_point_on_line_1.default(geom1, geom2, { ignoreEndVertices: true }); case "Polygon": case "MultiPolygon": return boolean_point_in_polygon_1.default(geom1, geom2, { ignoreBoundary: true }); default: throw new Error("feature2 " + type2 + " geometry not supported"); } case "MultiPoint": switch (type2) { case "MultiPoint": return isMultiPointInMultiPoint(geom1, geom2); case "LineString": return isMultiPointOnLine(geom1, geom2); case "Polygon": case "MultiPolygon": return isMultiPointInPoly(geom1, geom2); default: throw new Error("feature2 " + type2 + " geometry not supported"); } case "LineString": switch (type2) { case "LineString": return isLineOnLine(geom1, geom2); case "Polygon": case "MultiPolygon": return isLineInPoly(geom1, geom2); default: throw new Error("feature2 " + type2 + " geometry not supported"); } case "Polygon": switch (type2) { case "Polygon": case "MultiPolygon": return isPolyInPoly(geom1, geom2); default: throw new Error("feature2 " + type2 + " geometry not supported"); } default: throw new Error("feature1 " + type1 + " geometry not supported"); } } function isPointInMultiPoint(point, multiPoint) { var i; var output = false; for (i = 0; i < multiPoint.coordinates.length; i++) { if (compareCoords(multiPoint.coordinates[i], point.coordinates)) { output = true; break; } } return output; } function isMultiPointInMultiPoint(multiPoint1, multiPoint2) { for (var i = 0; i < multiPoint1.coordinates.length; i++) { var anyMatch = false; for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) { if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) { anyMatch = true; } } if (!anyMatch) { return false; } } return true; } function isMultiPointOnLine(multiPoint, lineString) { var foundInsidePoint = false; for (var i = 0; i < multiPoint.coordinates.length; i++) { if (!boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString)) { return false; } if (!foundInsidePoint) { foundInsidePoint = boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString, { ignoreEndVertices: true }); } } return foundInsidePoint; } function isMultiPointInPoly(multiPoint, polygon) { var output = true; var oneInside = false; var isInside = false; for (var i = 0; i < multiPoint.coordinates.length; i++) { isInside = boolean_point_in_polygon_1.default(multiPoint.coordinates[1], polygon); if (!isInside) { output = false; break; } if (!oneInside) { isInside = boolean_point_in_polygon_1.default(multiPoint.coordinates[1], polygon, { ignoreBoundary: true, }); } } return output && isInside; } function isLineOnLine(lineString1, lineString2) { for (var i = 0; i < lineString1.coordinates.length; i++) { if (!boolean_point_on_line_1.default(lineString1.coordinates[i], lineString2)) { return false; } } return true; } function isLineInPoly(linestring, polygon) { var polyBbox = bbox_1.default(polygon); var lineBbox = bbox_1.default(linestring); if (!doBBoxOverlap(polyBbox, lineBbox)) { return false; } var foundInsidePoint = false; for (var i = 0; i < linestring.coordinates.length - 1; i++) { if (!boolean_point_in_polygon_1.default(linestring.coordinates[i], polygon)) { return false; } if (!foundInsidePoint) { foundInsidePoint = boolean_point_in_polygon_1.default(linestring.coordinates[i], polygon, { ignoreBoundary: true }); } if (!foundInsidePoint) { var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]); foundInsidePoint = boolean_point_in_polygon_1.default(midpoint, polygon, { ignoreBoundary: true, }); } } return foundInsidePoint; } /** * Is Polygon2 in Polygon1 * Only takes into account outer rings * * @private * @param {Polygon} geometry1 * @param {Polygon|MultiPolygon} geometry2 * @returns {boolean} true/false */ function isPolyInPoly(geometry1, geometry2) { var poly1Bbox = bbox_1.default(geometry1); var poly2Bbox = bbox_1.default(geometry2); if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) { return false; } for (var i = 0; i < geometry1.coordinates[0].length; i++) { if (!boolean_point_in_polygon_1.default(geometry1.coordinates[0][i], geometry2)) { return false; } } return true; } function doBBoxOverlap(bbox1, bbox2) { if (bbox1[0] > bbox2[0]) return false; if (bbox1[2] < bbox2[2]) return false; if (bbox1[1] > bbox2[1]) return false; if (bbox1[3] < bbox2[3]) return false; return true; } /** * compareCoords * * @private * @param {Position} pair1 point [x,y] * @param {Position} pair2 point [x,y] * @returns {boolean} true/false if coord pairs match */ function compareCoords(pair1, pair2) { return pair1[0] === pair2[0] && pair1[1] === pair2[1]; } /** * getMidpoint * * @private * @param {Position} pair1 point [x,y] * @param {Position} pair2 point [x,y] * @returns {Position} midpoint of pair1 and pair2 */ function getMidpoint(pair1, pair2) { return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2]; } exports.default = booleanWithin; },{"@turf/bbox":3,"@turf/boolean-point-in-polygon":6,"@turf/boolean-point-on-line":7,"@turf/invariant":15}],9:[function(require,module,exports){ 'use strict'; var center = require('@turf/center'); var turfJsts = require('turf-jsts'); var meta = require('@turf/meta'); var d3Geo = require('d3-geo'); var helpers = require('@turf/helpers'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var center__default = /*#__PURE__*/_interopDefaultLegacy(center); /** * Calculates a buffer for input features for a given radius. Units supported are miles, kilometers, and degrees. * * When using a negative radius, the resulting geometry may be invalid if * it's too small compared to the radius magnitude. If the input is a * FeatureCollection, only valid members will be returned in the output * FeatureCollection - i.e., the output collection may have fewer members than * the input, or even be empty. * * @name buffer * @param {FeatureCollection|Geometry|Feature<any>} geojson input to be buffered * @param {number} radius distance to draw the buffer (negative values are allowed) * @param {Object} [options={}] Optional parameters * @param {string} [options.units="kilometers"] any of the options supported by turf units * @param {number} [options.steps=8] number of steps * @returns {FeatureCollection|Feature<Polygon|MultiPolygon>|undefined} buffered features * @example * var point = turf.point([-90.548630, 14.616599]); * var buffered = turf.buffer(point, 500, {units: 'miles'}); * * //addToMap * var addToMap = [point, buffered] */ function buffer(geojson, radius, options) { // Optional params options = options || {}; // use user supplied options or default values var units = options.units || "kilometers"; var steps = options.steps || 8; // validation if (!geojson) throw new Error("geojson is required"); if (typeof options !== "object") throw new Error("options must be an object"); if (typeof steps !== "number") throw new Error("steps must be an number"); // Allow negative buffers ("erosion") or zero-sized buffers ("repair geometry") if (radius === undefined) throw new Error("radius is required"); if (steps <= 0) throw new Error("steps must be greater than 0"); var results = []; switch (geojson.type) { case "GeometryCollection": meta.geomEach(geojson, function (geometry) { var buffered = bufferFeature(geometry, radius, units, steps); if (buffered) results.push(buffered); }); return helpers.featureCollection(results); case "FeatureCollection": meta.featureEach(geojson, function (feature) { var multiBuffered = bufferFeature(feature, radius, units, steps); if (multiBuffered) { meta.featureEach(multiBuffered, function (buffered) { if (buffered) results.push(buffered); }); } }); return helpers.featureCollection(results); } return bufferFeature(geojson, radius, units, steps); } /** * Buffer single Feature/Geometry * * @private * @param {Feature<any>} geojson input to be buffered * @param {number} radius distance to draw the buffer * @param {string} [units='kilometers'] any of the options supported by turf units * @param {number} [steps=8] number of steps * @returns {Feature<Polygon|MultiPolygon>} buffered feature */ function bufferFeature(geojson, radius, units, steps) { var properties = geojson.properties || {}; var geometry = geojson.type === "Feature" ? geojson.geometry : geojson; // Geometry Types faster than jsts if (geometry.type === "GeometryCollection") { var results = []; meta.geomEach(geojson, function (geometry) { var buffered = bufferFeature(geometry, radius, units, steps); if (buffered) results.push(buffered); }); return helpers.featureCollection(results); } // Project GeoJSON to Azimuthal Equidistant projection (convert to Meters) var projection = defineProjection(geometry); var projected = { type: geometry.type, coordinates: projectCoords(geometry.coordinates, projection), }; // JSTS buffer operation var reader = new turfJsts.GeoJSONReader(); var geom = reader.read(projected); var distance = helpers.radiansToLength(helpers.lengthToRadians(radius, units), "meters"); var buffered = turfJsts.BufferOp.bufferOp(geom, distance, steps); var writer = new turfJsts.GeoJSONWriter(); buffered = writer.write(buffered); // Detect if empty geometries if (coordsIsNaN(buffered.coordinates)) return undefined; // Unproject coordinates (convert to Degrees) var result = { type: buffered.type, coordinates: unprojectCoords(buffered.coordinates, projection), }; return helpers.feature(result, properties); } /** * Coordinates isNaN * * @private * @param {Array<any>} coords GeoJSON Coordinates * @returns {boolean} if NaN exists */ function coordsIsNaN(coords) { if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]); return isNaN(coords[0]); } /** * Project coordinates to projection * * @private * @param {Array<any>} coords to project * @param {GeoProjection} proj D3 Geo Projection * @returns {Array<any>} projected coordinates */ function projectCoords(coords, proj) { if (typeof coords[0] !== "object") return proj(coords); return coords.map(function (coord) { return projectCoords(coord, proj); }); } /** * Un-Project coordinates to projection * * @private * @param {Array<any>} coords to un-project * @param {GeoProjection} proj D3 Geo Projection * @returns {Array<any>} un-projected coordinates */ function unprojectCoords(coords, proj) { if (typeof coords[0] !== "object") return proj.invert(coords); return coords.map(function (coord) { return unprojectCoords(coord, proj); }); } /** * Define Azimuthal Equidistant projection * * @private * @param {Geometry|Feature<any>} geojson Base projection on center of GeoJSON * @returns {GeoProjection} D3 Geo Azimuthal Equidistant Projection */ function defineProjection(geojson) { var coords = center__default['default'](geojson).geometry.coordinates; var rotation = [-coords[0], -coords[1]]; return d3Geo.geoAzimuthalEquidistant().rotate(rotation).scale(helpers.earthRadius); } module.exports = buffer; module.exports.default = buffer; },{"@turf/center":10,"@turf/helpers":13,"@turf/meta":19,"d3-geo":36,"turf-jsts":192}],10:[function(require,module,exports){ "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var bbox_1 = __importDefault(require("@turf/bbox")); var helpers_1 = require("@turf/helpers"); /** * Takes a {@link Feature} or {@link FeatureCollection} and returns the absolute center point of all features. * * @name center * @param {GeoJSON} geojson GeoJSON to be centered * @param {Object} [options={}] Optional parameters * @param {Object} [options.properties={}] Translate GeoJSON Properties to Point * @param {Object} [options.bbox={}] Translate GeoJSON BBox to Point * @param {Object} [options.id={}] Translate GeoJSON Id to Point * @returns {Feature<Point>} a Point feature at the absolute center point of all input features * @example * var features = turf.points([ * [-97.522259, 35.4691], * [-97.502754, 35.463455], * [-97.508269, 35.463245] * ]); * * var center = turf.center(features); * * //addToMap * var addToMap = [features, center] * center.properties['marker-size'] = 'large'; * center.properties['marker-color'] = '#000'; */ function center(geojson, options) { if (options === void 0) { options = {}; } var ext = bbox_1.default(geojson); var x = (ext[0] + ext[2]) / 2; var y = (ext[1] + ext[3]) / 2; return helpers_1.point([x, y], options.properties, options); } exports.default = center; },{"@turf/bbox":3,"@turf/helpers":13}],11:[function(require,module,exports){ 'use strict'; var polygonClipping = require('polygon-clipping'); var helpers = require('@turf/helpers'); var invariant = require('@turf/invariant'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var polygonClipping__default = /*#__PURE__*/_interopDefaultLegacy(polygonClipping); /** * Finds the difference between two {@link Polygon|polygons} by clipping the second polygon from the first. * * @name difference * @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature * @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1 * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`) * @example * var polygon1 = turf.polygon([[ * [128, -26], * [141, -26], * [141, -21], * [128, -21], * [128, -26] * ]], { * "fill": "#F00", * "fill-opacity": 0.1 * }); * var polygon2 = turf.polygon([[ * [126, -28], * [140, -28], * [140, -20], * [126, -20], * [126, -28] * ]], { * "fill": "#00F", * "fill-opacity": 0.1 * }); * * var difference = turf.difference(polygon1, polygon2); * * //addToMap * var addToMap = [polygon1, polygon2, difference]; */ function difference(polygon1, polygon2) { var geom1 = invariant.getGeom(polygon1); var geom2 = invariant.getGeom(polygon2); var properties = polygon1.properties || {}; var differenced = polygonClipping__default['default'].difference( geom1.coordinates, geom2.coordinates ); if (differenced.length === 0) return null; if (differenced.length === 1) return helpers.polygon(differenced[0], properties); return helpers.multiPolygon(differenced, properties); } module.exports = difference; module.exports.default = difference; },{"@turf/helpers":13,"@turf/invariant":15,"polygon-clipping":187}],12:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var invariant_1 = require("@turf/invariant"); var helpers_1 = require("@turf/helpers"); //http://en.wikipedia.org/wiki/Haversine_formula //http://www.movable-type.co.uk/scripts/latlong.html /** * Calculates the distance between two {@link Point|points} in degrees, radians, miles, or kilometers. * This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature. * * @name distance * @param {Coord | Point} from origin point or coordinate * @param {Coord | Point} to destination point or coordinate * @param {Object} [options={}] Optional parameters * @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers * @returns {number} distance between the two points * @example * var from = turf.point([-75.343, 39.984]); * var to = turf.point([-75.534, 39.123]); * var options = {units: 'miles'}; * * var distance = turf.distance(from, to, options); * * //addToMap * var addToMap = [from, to]; * from.properties.distance = distance; * to.properties.distance = distance; */ function distance(from, to, options) { if (options === void 0) { options = {}; } var coordinates1 = invariant_1.getCoord(from); var coordinates2 = invariant_1.getCoord(to); var dLat = helpers_1.degreesToRadians(coordinates2[1] - coordinates1[1]); var dLon = helpers_1.degreesToRadians(coordinates2[0] - coordinates1[0]); var lat1 = helpers_1.degreesToRadians(coordinates1[1]); var lat2 = helpers_1.degreesToRadians(coordinates2[1]); var a = Math.pow(Math.sin(dLat / 2), 2) + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2); return helpers_1.radiansToLength(2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)), options.units); } exports.default = distance; },{"@turf/helpers":13,"@turf/invariant":15}],13:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * @module helpers */ /** * Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth. * * @memberof helpers * @type {number} */ exports.earthRadius = 6371008.8; /** * Unit of measurement factors using a spherical (non-ellipsoid) earth radius. * * @memberof helpers * @type {Object} */ exports.factors = { centimeters: exports.earthRadius * 100, centimetres: exports.earthRadius * 100, degrees: exports.earthRadius / 111325, feet: exports.earthRadius * 3.28084, inches: exports.earthRadius * 39.37, kilometers: exports.earthRadius / 1000, kilometres: exports.earthRadius / 1000, meters: exports.earthRadius, metres: exports.earthRadius, miles: exports.earthRadius / 1609.344, millimeters: exports.earthRadius * 1000, millimetres: exports.earthRadius * 1000, nauticalmiles: exports.earthRadius / 1852, radians: 1, yards: exports.earthRadius * 1.0936, }; /** * Units of measurement factors based on 1 meter. * * @memberof helpers * @type {Object} */ exports.unitsFactors = { centimeters: 100, centimetres: 100, degrees: 1 / 111325, feet: 3.28084, inches: 39.37, kilometers: 1 / 1000, kilometres: 1 / 1000, meters: 1, metres: 1, miles: 1 / 1609.344, millimeters: 1000, millimetres: 1000, nauticalmiles: 1 / 1852, radians: 1 / exports.earthRadius, yards: 1.0936133, }; /** * Area of measurement factors based on 1 square meter. * * @memberof helpers * @type {Object} */ exports.areaFactors = { acres: 0.000247105, centimeters: 10000, centimetres: 10000, feet: 10.763910417, hectares: 0.0001, inches: 1550.003100006, kilometers: 0.000001, kilometres: 0.000001, meters: 1, metres: 1, miles: 3.86e-7, millimeters: 1000000, millimetres: 1000000, yards: 1.195990046, }; /** * Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}. * * @name feature * @param {Geometry} geometry input geometry * @param {Object} [properties={}] an Object of key-value pairs to add as properties * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature * @param {string|number} [options.id] Identifier associated with the Feature * @returns {Feature} a GeoJSON Feature * @example * var geometry = { * "type": "Point", * "coordinates": [110, 50] * }; * * var feature = turf.feature(geometry); * * //=feature */ function feature(geom, properties, options) { if (options === void 0) { options = {}; } var feat = { type: "Feature" }; if (options.id === 0 || options.id) { feat.id = options.id; } if (options.bbox) { feat.bbox = options.bbox; } feat.properties = properties || {}; feat.geometry = geom; return feat; } exports.feature = feature; /** * Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates. * For GeometryCollection type use `helpers.geometryCollection` * * @name geometry * @param {string} type Geometry Type * @param {Array<any>} coordinates Coordinates * @param {Object} [options={}] Optional Parameters * @returns {Geometry} a GeoJSON Geometry * @example * var type = "Point"; * var coordinates = [110, 50]; * var geometry = turf.geometry(type, coordinates); * // => geometry */ function geometry(type, coordinates, _options) { if (_options === void 0) { _options = {}; } switch (type) { case "Point": return point(coordinates).geometry; case "LineString": return lineString(coordinates).geometry; case "Polygon": return polygon(coordinates).geometry; case "MultiPoint": return multiPoint(coordinates).geometry; case "MultiLineString": return multiLineString(coordinates).geometry; case "MultiPolygon": return multiPolygon(coordinates).geometry; default: throw new Error(type + " is invalid"); } } exports.geometry = geometry; /** * Creates a {@link Point} {@link Feature} from a Position. * * @name point * @param {Array<number>} coordinates longitude, latitude position (each in decimal degrees) * @param {Object} [properties={}] an Object of key-value pairs to add as properties * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature * @param {string|number} [options.id] Identifier associated with the Feature * @returns {Feature<Point>} a Point feature * @example * var point = turf.point([-75.343, 39.984]); * * //=point */ function point(coordinates, properties, options) { if (options === void 0) { options = {}; } if (!coordinates) { throw new Error("coordinates is required"); } if (!Array.isArray(coordinates)) { throw new Error("coordinates must be an Array"); } if (coordinates.length < 2) { throw new Error("coordinates must be at least 2 numbers long"); } if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) { throw new Error("coordinates must contain numbers"); } var geom = { type: "Point", coordinates: coordinates, }; return feature(geom, properties, options); } exports.point = point; /** * Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates. * * @name points * @param {Array<Array<number>>} coordinates an array of Points * @param {Object} [properties={}] Translate these properties to each Feature * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] * associated with the FeatureCollection * @param {string|number} [options.id] Identifier associated with the FeatureCollection * @returns {FeatureCollection<Point>} Point Feature * @example * var points = turf.points([ * [-75, 39], * [-80, 45], * [-78, 50] * ]); * * //=points */ function points(coordinates, properties, options) { if (options === void 0) { options = {}; } return featureCollection(coordinates.map(function (coords) { return point(coords, properties); }), options); } exports.points = points; /** * Creates a {@link Polygon} {@link Feature} from an Array of LinearRings. * * @name polygon * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings * @param {Object} [properties={}] an Object of key-value pairs to add as properties * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature * @param {string|number} [options.id] Identifier associated with the Feature * @returns {Feature<Polygon>} Polygon Feature * @example * var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' }); * * //=polygon */ function polygon(coordinates, properties, options) { if (options === void 0) { options = {}; } for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) { var ring = coordinates_1[_i]; if (ring.length < 4) { throw new Error("Each LinearRing of a Polygon must have 4 or more Positions."); } for (var j = 0; j < ring[ring.length - 1].length; j++) { // Check if first point of Polygon contains two numbers if (ring[ring.length - 1][j] !== ring[0][j]) { throw new Error("First and last Position are not equivalent."); } } } var geom = { type: "Polygon", coordinates: coordinates, }; return feature(geom, properties, options); } exports.polygon = polygon; /** * Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates. * * @name polygons * @param {Array<Array<Array<Array<number>>>>} coordinates an array of Polygon coordinates * @param {Object} [properties={}] an Object of key-value pairs to add as properties * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature * @param {string|number} [options.id] Identifier associated with the FeatureCollection * @returns {FeatureCollection<Polygon>} Polygon FeatureCollection * @example * var polygons = turf.polygons([ * [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], * [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]], * ]); * * //=polygons */ function polygons(coordinates, properties, options) { if (options === void 0) { options = {}; } return featureCollection(coordinates.map(function (coords) { return polygon(coords, properties); }), options); } exports.polygons = polygons; /** * Creates a {@link LineString} {@link Feature} from an Array of Positions. * * @name lineString * @param {Array<Array<number>>} coordinates an array of Positions * @param {Object} [properties={}] an Object of key-value pairs to add as properties * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature * @param {string|number} [options.id] Identifier associated with the Feature * @returns {Feature<LineString>} LineString Feature * @example * var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'}); * var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'}); * * //=linestring1 * //=linestring2 */ function lineString(coordinates, properties, options) { if (options === void 0) { options = {}; } if (coordinates.length < 2) { throw new Error("coordinates must be an array of two or more positions"); } var geom = { type: "LineString", coordinates: coordinates, }; return feature(geom, properties, options); } exports.lineString = lineString; /** * Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates. * * @name lineStrings * @param {Array<Array<Array<number>>>} coordinates an array of LinearRings * @param {Object} [properties={}] an Object of key-value pairs to add as properties * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] * associated with the FeatureCollection * @param {string|number} [options.id] Identifier associated with the FeatureCollection * @returns {FeatureCollection<LineString>} LineString FeatureCollection * @example * var linestrings = turf.lineStrings([ * [[-24, 63], [-23, 60], [-25, 65], [-20, 69]], * [[-14, 43], [-13, 40], [-15, 45], [-10, 49]] * ]); * * //=linestrings */ function lineStrings(coordinates, properties, options) { if (options === void 0) { options = {}; } return featureCollection(coordinates.map(function (coords) { return lineString(coords, properties); }), options); } exports.lineStrings = lineStrings; /** * Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}. * * @name featureCollection * @param {Feature[]} features input features * @param {Object} [options={}] Optional Parameters * @param {Array<number>} [options.bbox] Bounding Box Array [west, south, east, north] associated