本文整理汇总了TypeScript中@turf/invariant.getType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getType函数的具体用法?TypeScript getType怎么用?TypeScript getType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getType函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: getType
/**
* Determine whether two geometries of the same type have identical X,Y coordinate values.
* See http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relations.htm
*
* @name booleanEqual
* @param {Geometry|Feature} feature1 GeoJSON input
* @param {Geometry|Feature} feature2 GeoJSON input
* @returns {boolean} true if the objects are equal, false otherwise
* @example
* var pt1 = turf.point([0, 0]);
* var pt2 = turf.point([0, 0]);
* var pt3 = turf.point([1, 1]);
*
* turf.booleanEqual(pt1, pt2);
* //= true
* turf.booleanEqual(pt2, pt3);
* //= false
*/
function booleanEqual<G1 extends Geometry, G2 extends Geometry>(feature1: Feature<G1> | G1, feature2: Feature<G2> | G2): boolean {
// validation
if (!feature1) throw new Error('feature1 is required');
if (!feature2) throw new Error('feature2 is required');
var type1 = getType(feature1);
var type2 = getType(feature2);
if (type1 !== type2) return false;
var equality = new GeojsonEquality({precision: 6});
return equality.compare(cleanCoords(feature1), cleanCoords(feature2));
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:29,代码来源:index.ts
示例2: booleanContains
/**
* Boolean-contains returns True if the second geometry is completely contained by the first geometry.
* The interiors of both geometries must intersect and, the interior and boundary of the secondary (geometry b)
* must not intersect the exterior of the primary (geometry a).
* Boolean-contains returns the exact opposite result of the `@turf/boolean-within`.
*
* @name booleanContains
* @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.booleanContains(line, point);
* //=true
*/
export default function booleanContains(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry) {
const geom1 = getGeom(feature1);
const geom2 = getGeom(feature2);
const type1 = getType(feature1);
const type2 = getType(feature2);
const coords1 = getCoords(feature1);
const coords2 = getCoords(feature2);
switch (type1) {
case 'Point':
switch (type2) {
case 'Point':
return compareCoords(coords1, coords2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'MultiPoint':
switch (type2) {
case 'Point':
return isPointInMultiPoint(geom1, geom2);
case 'MultiPoint':
return isMultiPointInMultiPoint(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'LineString':
switch (type2) {
case 'Point':
return isPointOnLine(geom2, geom1, {ignoreEndVertices: true});
case 'LineString':
return isLineOnLine(geom1, geom2);
case 'MultiPoint':
return isMultiPointOnLine(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'Polygon':
switch (type2) {
case 'Point':
return booleanPointInPolygon(geom2, geom1, {ignoreBoundary: true});
case 'LineString':
return isLineInPoly(geom1, geom2);
case 'Polygon':
return isPolyInPoly(geom1, geom2);
case 'MultiPoint':
return isMultiPointInPoly(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
default:
throw new Error('feature1 ' + type1 + ' geometry not supported');
}
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:70,代码来源:index.ts
示例3: booleanWithin
/**
* 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: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean {
var type1 = getType(feature1);
var type2 = getType(feature2);
var geom1 = getGeom(feature1);
var geom2 = getGeom(feature2);
switch (type1) {
case 'Point':
switch (type2) {
case 'MultiPoint':
return isPointInMultiPoint(geom1, geom2);
case 'LineString':
return booleanPointOnLine(geom1, geom2, {ignoreEndVertices: true});
case 'Polygon':
case 'MultiPolygon':
return booleanPointInPolygon(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');
}
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:70,代码来源:index.ts
示例4: dissolve
/**
* Transform function: attempts to dissolve geojson objects where possible
* [GeoJSON] -> GeoJSON geometry
*
* @private
* @param {FeatureCollection<LineString|MultiLineString|Polygon|MultiPolygon>} geojson Features to dissolved
* @param {Object} [options={}] Optional parameters
* @param {boolean} [options.mutate=false] Prevent input mutation
* @returns {Feature<MultiLineString|MultiPolygon>} Dissolved Features
*/
function dissolve(geojson: FeatureCollection<LineString|MultiLineString|Polygon|MultiPolygon>, options: {
mutate?: boolean,
} = {}): Feature<LineString|MultiLineString|Polygon|MultiPolygon> | null {
// Optional parameters
options = options || {};
if (!isObject(options)) { throw new Error("options is invalid"); }
const mutate = options.mutate;
// Validation
if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
if (!geojson.features.length) { throw new Error("geojson is empty"); }
// Clone geojson to avoid side effects
// Topojson modifies in place, so we need to deep clone first
if (mutate === false || mutate === undefined) { geojson = clone(geojson); }
// Assert homogenity
const type = getHomogenousType(geojson);
if (!type) { throw new Error("geojson must be homogenous"); }
// Data => Typescript hack
const data: any = geojson;
switch (type) {
case "LineString":
return lineDissolve(data, options);
case "Polygon":
return polygonDissolve(data, options);
default:
throw new Error(type + " is not supported");
}
}
开发者ID:Turbo87,项目名称:turf,代码行数:42,代码来源:turf-dissolve.ts
示例5: booleanOverlap
/**
* Compares two geometries of the same dimension and returns true if their intersection set results in a geometry
* different from both but of the same dimension. It applies to Polygon/Polygon, LineString/LineString,
* Multipoint/Multipoint, MultiLineString/MultiLineString and MultiPolygon/MultiPolygon.
*
* @name booleanOverlap
* @param {Geometry|Feature<LineString|MultiLineString|Polygon|MultiPolygon>} feature1 input
* @param {Geometry|Feature<LineString|MultiLineString|Polygon|MultiPolygon>} feature2 input
* @returns {boolean} true/false
* @example
* var poly1 = turf.polygon([[[0,0],[0,5],[5,5],[5,0],[0,0]]]);
* var poly2 = turf.polygon([[[1,1],[1,6],[6,6],[6,1],[1,1]]]);
* var poly3 = turf.polygon([[[10,10],[10,15],[15,15],[15,10],[10,10]]]);
*
* turf.booleanOverlap(poly1, poly2)
* //=true
* turf.booleanOverlap(poly2, poly3)
* //=false
*/
function booleanOverlap(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean {
// validation
if (!feature1) throw new Error('feature1 is required');
if (!feature2) throw new Error('feature2 is required');
var type1 = getType(feature1);
var type2 = getType(feature2);
if (type1 !== type2) throw new Error('features must be of the same type');
if (type1 === 'Point') throw new Error('Point geometry not supported');
// features must be not equal
var equality = new GeojsonEquality({precision: 6});
if (equality.compare(feature1, feature2)) return false;
var overlap = 0;
switch (type1) {
case 'MultiPoint':
var coords1 = coordAll(feature1);
var coords2 = coordAll(feature2);
coords1.forEach(function (coord1) {
coords2.forEach(function (coord2) {
if (coord1[0] === coord2[0] && coord1[1] === coord2[1]) overlap++;
});
});
break;
case 'LineString':
case 'MultiLineString':
segmentEach(feature1, function (segment1) {
segmentEach(feature2, function (segment2) {
if (lineOverlap(segment1, segment2).features.length) overlap++;
});
});
break;
case 'Polygon':
case 'MultiPolygon':
segmentEach(feature1, function (segment1) {
segmentEach(feature2, function (segment2) {
if (lineIntersect(segment1, segment2).features.length) overlap++;
});
});
break;
}
return overlap > 0;
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:66,代码来源:index.ts
示例6: booleanCrosses
/**
* Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than
* the maximum dimension of the two source geometries and the intersection set is interior to
* both source geometries.
*
* Boolean-Crosses returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons.
*
* @name booleanCrosses
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
* @returns {boolean} true/false
* @example
* var line1 = turf.lineString([[-2, 2], [4, 2]]);
* var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
*
* var cross = turf.booleanCrosses(line1, line2);
* //=true
*/
function booleanCrosses(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean {
var type1 = getType(feature1);
var type2 = getType(feature2);
var geom1 = getGeom(feature1);
var geom2 = getGeom(feature2);
switch (type1) {
case 'MultiPoint':
switch (type2) {
case 'LineString':
return doMultiPointAndLineStringCross(geom1, geom2);
case 'Polygon':
return doesMultiPointCrossPoly(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'LineString':
switch (type2) {
case 'MultiPoint': // An inverse operation
return doMultiPointAndLineStringCross(geom2, geom1);
case 'LineString':
return doLineStringsCross(geom1, geom2);
case 'Polygon':
return doLineStringAndPolygonCross(geom1, geom2);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
case 'Polygon':
switch (type2) {
case 'MultiPoint': // An inverse operation
return doesMultiPointCrossPoly(geom2, geom1);
case 'LineString': // An inverse operation
return doLineStringAndPolygonCross(geom2, geom1);
default:
throw new Error('feature2 ' + type2 + ' geometry not supported');
}
default:
throw new Error('feature1 ' + type1 + ' geometry not supported');
}
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:58,代码来源:index.ts
示例7: lineDissolve
/**
* Merges all connected (non-forking, non-junctioning) line strings into single lineStrings.
* [LineString] -> LineString|MultiLineString
*
* @param {FeatureCollection<LineString|MultiLineString>} geojson Lines to dissolve
* @param {Object} [options={}] Optional parameters
* @param {boolean} [options.mutate=false] Prevent input mutation
* @returns {Feature<LineString|MultiLineString>} Dissolved lines
*/
function lineDissolve(
geojson: FeatureCollection<LineString|MultiLineString>,
options: {mutate?: boolean} = {},
): Feature<LineString|MultiLineString> | null {
// Optional parameters
options = options || {};
if (!isObject(options)) { throw new Error("options is invalid"); }
const mutate = options.mutate;
// Validation
if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
if (!geojson.features.length) { throw new Error("geojson is empty"); }
// Clone geojson to avoid side effects
if (mutate === false || mutate === undefined) { geojson = clone(geojson); }
const result: any[] = [];
const lastLine = lineReduce(geojson, (previousLine: any, currentLine: any) => {
// Attempt to merge this LineString with the other LineStrings, updating
// the reference as it is merged with others and grows.
const merged = mergeLineStrings(previousLine, currentLine);
// Accumulate the merged LineString
if (merged) { return merged;
// Put the unmerged LineString back into the list
} else {
result.push(previousLine);
return currentLine;
}
});
// Append the last line
if (lastLine) { result.push(lastLine); }
// Return null if no lines were dissolved
if (!result.length) {
return null;
// Return LineString if only 1 line was dissolved
} else if (result.length === 1) {
return result[0];
// Return MultiLineString if multiple lines were dissolved with gaps
} else { return multiLineString(result.map((line) => {
return line.coordinates;
})); }
}
开发者ID:Turbo87,项目名称:turf,代码行数:53,代码来源:turf-line-dissolve.ts
示例8: polygonDissolve
/**
* Dissolves all overlapping (Multi)Polygon
*
* @param {FeatureCollection<Polygon|MultiPolygon>} geojson Polygons to dissolve
* @param {Object} [options={}] Optional parameters
* @param {boolean} [options.mutate=false] Prevent input mutation
* @returns {Feature<Polygon|MultiPolygon>} Dissolved Polygons
*/
export default function polygonDissolve(
geojson: FeatureCollection<Polygon|MultiPolygon>,
options: {mutate?: boolean} = {},
): Feature<Polygon|MultiPolygon> | null {
// Validation
if (getType(geojson) !== "FeatureCollection") { throw new Error("geojson must be a FeatureCollection"); }
if (!geojson.features.length) { throw new Error("geojson is empty"); }
// Clone geojson to avoid side effects
// Topojson modifies in place, so we need to deep clone first
if (options.mutate === false || options.mutate === undefined) { geojson = clone(geojson); }
const geoms: any[] = [];
flattenEach(geojson, (feature) => {
geoms.push(feature.geometry);
});
const topo: any = topology({geoms: geometryCollection(geoms).geometry});
const merged: any = merge(topo, topo.objects.geoms.geometries);
return merged;
}
开发者ID:Turbo87,项目名称:turf,代码行数:28,代码来源:turf-polygon-dissolve.ts
示例9: normalize
/**
* Returns the closest {@link Point|point}, of a {@link FeatureCollection|collection} of points,
* to a {@link LineString|line}. The returned point has a `dist` property indicating its distance to the line.
*
* @name nearestPointToLine
* @param {FeatureCollection|GeometryCollection<Point>} points Point Collection
* @param {Feature|Geometry<LineString>} line Line Feature
* @param {Object} [options] Optional parameters
* @param {string} [options.units='kilometers'] unit of the output distance property
* (eg: degrees, radians, miles, or kilometers)
* @param {Object} [options.properties={}] Translate Properties to Point
* @returns {Feature<Point>} the closest point
* @example
* var pt1 = turf.point([0, 0]);
* var pt2 = turf.point([0.5, 0.5]);
* var points = turf.featureCollection([pt1, pt2]);
* var line = turf.lineString([[1,1], [-1,1]]);
*
* var nearest = turf.nearestPointToLine(points, line);
*
* //addToMap
* var addToMap = [nearest, line];
*/
function nearestPointToLine<P = {dist: number, [key: string]: any}>(
points: FeatureCollection<Point> | Feature<GeometryCollection> | GeometryCollection,
line: Feature<LineString> | LineString,
options: {
units?: Units,
properties?: Properties,
} = {},
): Feature<Point, P> {
const units = options.units;
const properties = options.properties || {};
// validation
const pts = normalize(points);
if (!pts.features.length) { throw new Error("points must contain features"); }
if (!line) { throw new Error("line is required"); }
if (getType(line) !== "LineString") { throw new Error("line must be a LineString"); }
let dist = Infinity;
let pt: any = null;
featureEach(pts, (point) => {
const d = pointToLineDistance(point, line, { units });
if (d < dist) {
dist = d;
pt = point;
}
});
/**
* Translate Properties to final Point, priorities:
* 1. options.properties
* 2. inherent Point properties
* 3. dist custom properties created by NearestPointToLine
*/
if (pt) { pt.properties = objectAssign({dist}, pt.properties, properties); }
// if (pt) { pt.properties = objectAssign({dist}, pt.properties, properties); }
return pt;
}
开发者ID:Turbo87,项目名称:turf,代码行数:61,代码来源:index.ts
示例10: switch
/**
* Takes any {@link Feature} or a {@link FeatureCollection} and returns its [center of mass](https://en.wikipedia.org/wiki/Center_of_mass) using this formula: [Centroid of Polygon](https://en.wikipedia.org/wiki/Centroid#Centroid_of_polygon).
*
* @name centerOfMass
* @param {GeoJSON} geojson GeoJSON to be centered
* @param {Object} [options={}] Optional Parameters
* @param {Object} [options.properties={}] Translate Properties to Feature
* @returns {Feature<Point>} the center of mass
* @example
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
*
* var center = turf.centerOfMass(polygon);
*
* //addToMap
* var addToMap = [polygon, center]
*/
function centerOfMass<P = Properties>(geojson: any, options: {
properties?: P,
} = {}): Feature<Point, P> {
switch (getType(geojson)) {
case 'Point':
return point(getCoord(geojson), options.properties);
case 'Polygon':
var coords = [];
coordEach(geojson, function (coord) {
coords.push(coord);
});
// First, we neutralize the feature (set it around coordinates [0,0]) to prevent rounding errors
// We take any point to translate all the points around 0
var centre = centroid(geojson, {properties: options.properties});
var translation = centre.geometry.coordinates;
var sx = 0;
var sy = 0;
var sArea = 0;
var i, pi, pj, xi, xj, yi, yj, a;
var neutralizedPoints = coords.map(function (point) {
return [
point[0] - translation[0],
point[1] - translation[1]
];
});
for (i = 0; i < coords.length - 1; i++) {
// pi is the current point
pi = neutralizedPoints[i];
xi = pi[0];
yi = pi[1];
// pj is the next point (pi+1)
pj = neutralizedPoints[i + 1];
xj = pj[0];
yj = pj[1];
// a is the common factor to compute the signed area and the final coordinates
a = xi * yj - xj * yi;
// sArea is the sum used to compute the signed area
sArea += a;
// sx and sy are the sums used to compute the final coordinates
sx += (xi + xj) * a;
sy += (yi + yj) * a;
}
// Shape has no area: fallback on turf.centroid
if (sArea === 0) {
return centre;
} else {
// Compute the signed area, and factorize 1/6A
var area = sArea * 0.5;
var areaFactor = 1 / (6 * area);
// Compute the final coordinates, adding back the values that have been neutralized
return point([
translation[0] + areaFactor * sx,
translation[1] + areaFactor * sy
], options.properties);
}
default:
// Not a polygon: Compute the convex hull and work with that
var hull = convex(geojson);
if (hull) return centerOfMass(hull, {properties: options.properties});
// Hull is empty: fallback on the centroid
else return centroid(geojson, {properties: options.properties});
}
}
开发者ID:Turbo87,项目名称:turf,代码行数:89,代码来源:index.ts
注:本文中的@turf/invariant.getType函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论