本文整理汇总了TypeScript中@turf/invariant.getGeom函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getGeom函数的具体用法?TypeScript getGeom怎么用?TypeScript getGeom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getGeom函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: booleanEqual
/**
* 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(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean {
const type1 = getGeom(feature1).type;
const type2 = getGeom(feature2).type;
if (type1 !== type2) return false;
const equality = new GeojsonEquality({precision: 6});
return equality.compare(cleanCoords(feature1), cleanCoords(feature2));
}
开发者ID:Turbo87,项目名称:turf,代码行数:26,代码来源:index.ts
示例2: getGeom
/**
* Takes two {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
* finds their polygonal intersection. If they don't intersect, returns null.
*
* @name intersect
* @param {Feature<Polygon | MultiPolygon>} poly1 the first polygon or multipolygon
* @param {Feature<Polygon | MultiPolygon>} poly2 the second polygon or multipolygon
* @param {Object} [options={}] Optional Parameters
* @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
* @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or
* {@link MultiPolygon}). If they do not share any area, returns `null`.
* @example
* var poly1 = turf.polygon([[
* [-122.801742, 45.48565],
* [-122.801742, 45.60491],
* [-122.584762, 45.60491],
* [-122.584762, 45.48565],
* [-122.801742, 45.48565]
* ]]);
*
* var poly2 = turf.polygon([[
* [-122.520217, 45.535693],
* [-122.64038, 45.553967],
* [-122.720031, 45.526554],
* [-122.669906, 45.507309],
* [-122.723464, 45.446643],
* [-122.532577, 45.408574],
* [-122.487258, 45.477466],
* [-122.520217, 45.535693]
* ]]);
*
* var intersection = turf.intersect(poly1, poly2);
*
* //addToMap
* var addToMap = [poly1, poly2, intersection];
*/
export default function intersect<P = Properties>(
poly1: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon,
poly2: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon,
options: {
properties?: P,
} = {},
): Feature<Polygon | MultiPolygon, P> | null {
const geom1 = getGeom(poly1);
const geom2 = getGeom(poly2);
if (geom1.type === "Polygon" && geom2.type === "Polygon") {
const intersection: any = martinez.intersection(geom1.coordinates, geom2.coordinates);
if (intersection === null || intersection.length === 0) { return null; }
if (intersection.length === 1) {
const start = intersection[0][0][0];
const end = intersection[0][0][intersection[0][0].length - 1];
if (start[0] === end[0] && start[1] === end[1]) { return polygon(intersection[0], options.properties); }
return null;
}
return multiPolygon(intersection, options.properties);
} else if (geom1.type === "MultiPolygon") {
let resultCoords: any[] = [];
// iterate through the polygon and run intersect with each part, adding to the resultCoords.
for (const coords of geom1.coordinates) {
const subGeom = getGeom(polygon(coords));
const subIntersection = intersect(subGeom, geom2);
if (subIntersection) {
const subIntGeom = getGeom(subIntersection);
if (subIntGeom.type === "Polygon") { resultCoords.push(subIntGeom.coordinates);
} else if (subIntGeom.type === "MultiPolygon") { resultCoords = resultCoords.concat(subIntGeom.coordinates);
} else { throw new Error("intersection is invalid"); }
}
}
// Make a polygon with the result
if (resultCoords.length === 0) { return null; }
if (resultCoords.length === 1) { return polygon(resultCoords[0], options.properties);
} else { return multiPolygon(resultCoords, options.properties); }
} else if (geom2.type === "MultiPolygon") {
// geom1 is a polygon and geom2 a multiPolygon,
// put the multiPolygon first and fallback to the previous case.
return intersect(geom2, geom1);
} else {
// handle invalid geometry types
throw new Error("poly1 and poly2 must be either polygons or multiPolygons");
}
}
开发者ID:Turbo87,项目名称:turf,代码行数:90,代码来源:index.ts
示例3: 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 = geom1.type;
const type2 = geom2.type;
const coords1 = geom1.coordinates;
const coords2 = geom2.coordinates;
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:Turbo87,项目名称:turf,代码行数:70,代码来源:index.ts
示例4: 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
示例5: 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
示例6: 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
*/
export default function booleanOverlap(
feature1: Feature<any> | Geometry,
feature2: Feature<any> | Geometry,
): boolean {
const geom1 = getGeom(feature1);
const geom2 = getGeom(feature2);
const type1 = geom1.type;
const type2 = geom2.type;
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
const equality = new GeojsonEquality({precision: 6});
if (equality.compare(feature1, feature2)) return false;
let overlap = 0;
switch (type1) {
case 'MultiPoint':
const coords1 = coordAll(feature1);
const coords2 = coordAll(feature2);
coords1.forEach((coord1) => {
coords2.forEach((coord2) => {
if (coord1[0] === coord2[0] && coord1[1] === coord2[1]) overlap++;
});
});
break;
case 'LineString':
case 'MultiLineString':
segmentEach(feature1, (segment1) => {
segmentEach(feature2, (segment2) => {
if (lineOverlap(segment1, segment2).features.length) overlap++;
});
});
break;
case 'Polygon':
case 'MultiPolygon':
segmentEach(feature1, (segment1) => {
segmentEach(feature2, (segment2) => {
if (lineIntersect(segment1, segment2).features.length) overlap++;
});
});
break;
}
return overlap > 0;
}
开发者ID:Turbo87,项目名称:turf,代码行数:68,代码来源:index.ts
示例7: getGeom
/**
* Takes a {@link Feature} and a bbox and clips the feature to the bbox using [lineclip](https://github.com/mapbox/lineclip).
* May result in degenerate edges when clipping Polygons.
*
* @name bboxClip
* @param {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} feature feature to clip to the bbox
* @param {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @returns {Feature<LineString|MultiLineString|Polygon|MultiPolygon>} clipped Feature
* @example
* var bbox = [0, 0, 10, 10];
* var poly = turf.polygon([[[2, 2], [8, 4], [12, 8], [3, 7], [2, 2]]]);
*
* var clipped = turf.bboxClip(poly, bbox);
*
* //addToMap
* var addToMap = [bbox, poly, clipped]
*/
function bboxClip<G extends Polygon | MultiPolygon | LineString | MultiLineString, P = Properties>(
feature: Feature<G, P> | G,
bbox: BBox
) {
const geom = getGeom(feature);
const type = geom.type;
const properties = feature.type === 'Feature' ? feature.properties : {};
let coords: any[] = geom.coordinates;
switch (type) {
case 'LineString':
case 'MultiLineString':
const lines = [];
if (type === 'LineString') coords = [coords];
coords.forEach(function (line) {
lineclip.polyline(line, bbox, lines);
});
if (lines.length === 1) return lineString(lines[0], properties);
return multiLineString(lines, properties);
case 'Polygon':
return polygon(clipPolygon(coords, bbox), properties);
case 'MultiPolygon':
return multiPolygon(coords.map((polygon) => {
return clipPolygon(polygon, bbox);
}), properties);
default:
throw new Error('geometry ' + type + ' not supported');
}
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:46,代码来源:index.ts
示例8: along
/**
* Takes a {@link LineString} and returns a {@link Point} at a specified distance along the line.
*
* @name along
* @param {Feature<LineString>} line input line
* @param {number} distance distance along the line
* @param {Object} [options] Optional parameters
* @param {string} [options.units="kilometers"] can be degrees, radians, miles, or kilometers
* @returns {Feature<Point>} Point `distance` `units` along the line
* @example
* var line = turf.lineString([[-83, 30], [-84, 36], [-78, 41]]);
* var options = {units: 'miles'};
*
* var along = turf.along(line, 200, options);
*
* //addToMap
* var addToMap = [along, line]
*/
export default function along(
line: Feature<LineString> | LineString,
distance: number,
options: {units?: Units} = {},
): Feature<Point> {
// Get Coords
const geom = getGeom(line);
const coords = geom.coordinates;
let travelled = 0;
for (let i = 0; i < coords.length; i++) {
if (distance >= travelled && i === coords.length - 1) { break;
} else if (travelled >= distance) {
const overshot = distance - travelled;
if (!overshot) { return point(coords[i]);
} else {
const direction = bearing(coords[i], coords[i - 1]) - 180;
const interpolated = destination(coords[i], overshot, direction, options);
return interpolated;
}
} else {
travelled += measureDistance(coords[i], coords[i + 1], options);
}
}
return point(coords[coords.length - 1]);
}
开发者ID:Turbo87,项目名称:turf,代码行数:43,代码来源:index.ts
注:本文中的@turf/invariant.getGeom函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论