当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript helpers.multiPolygon函数代码示例

本文整理汇总了TypeScript中@turf/helpers.multiPolygon函数的典型用法代码示例。如果您正苦于以下问题:TypeScript multiPolygon函数的具体用法?TypeScript multiPolygon怎么用?TypeScript multiPolygon使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了multiPolygon函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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

示例2: switch

/**
 * Converts (Multi)LineString(s) to Polygon(s).
 *
 * @name lineToPolygon
 * @param {FeatureCollection|Feature<LineString|MultiLineString>} lines Features to convert
 * @param {Object} [options={}] Optional parameters
 * @param {Object} [options.properties={}] translates GeoJSON properties to Feature
 * @param {boolean} [options.autoComplete=true] auto complete linestrings (matches first & last coordinates)
 * @param {boolean} [options.orderCoords=true] sorts linestrings to place outer ring at the first position of the coordinates
 * @returns {Feature<Polygon|MultiPolygon>} converted to Polygons
 * @example
 * var line = turf.lineString([[125, -30], [145, -30], [145, -20], [125, -20], [125, -30]]);
 *
 * var polygon = turf.lineToPolygon(line);
 *
 * //addToMap
 * var addToMap = [polygon];
 */
function lineToPolygon<G extends LineString|MultiLineString>(
    lines: Feature<G> | FeatureCollection<G> | G,
    options: {
        properties?: Properties,
        autoComplete?: boolean,
        orderCoords?: boolean,
    } = {}
) {
    // Optional parameters
    var properties = options.properties;
    var autoComplete = options.autoComplete;
    var orderCoords = options.orderCoords;

    // default params
    autoComplete = (autoComplete !== undefined) ? autoComplete : true;
    orderCoords = (orderCoords !== undefined) ? orderCoords : true;

    switch (lines.type) {
        case 'FeatureCollection':
            var coords = [];
            lines.features.forEach(function (line) {
                coords.push(getCoords(lineStringToPolygon(line, {}, autoComplete, orderCoords)));
            });
            return multiPolygon(coords, properties);
        default:
            return lineStringToPolygon(lines, properties, autoComplete, orderCoords);
    }
}
开发者ID:OlympicsORG,项目名称:turf,代码行数:46,代码来源:index.ts

示例3: 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

示例4: polygon

import {polygon, lineString, multiLineString, multiPolygon} from '@turf/helpers'
import * as rewind from './'

const coords = [[121, -29], [138, -29], [138, -18], [121, -18], [121, -29]]
const poly = polygon([coords])
const line = lineString(coords)
const multiPoly = multiPolygon([[coords], [coords]])
const multiLine = multiLineString([coords, coords])

rewind(line)
rewind(poly)
rewind(multiPoly)
rewind(multiLine)
rewind(poly, true)
rewind(poly, true, true)
开发者ID:z0630,项目名称:turf,代码行数:15,代码来源:types.ts

示例5: point

// Standard Geometry
const pt = point([100, 0]);
const line = lineString([[100, 0], [50, 0]]);
const poly = polygon([[[100, 0], [50, 0], [0, 50], [100, 0]]]);

buffer(pt, 5);
buffer(line, 5);
buffer(poly, 5);
buffer(pt, 5, {units: 'miles'});
buffer(pt, 10, {units: 'meters', steps: 64});

// Multi Geometry
const multiPt = multiPoint([[100, 0], [0, 100]]);
const multiLine = multiLineString([[[100, 0], [50, 0]], [[100, 0], [50, 0]]]);
const multiPoly = multiPolygon([[[[100, 0], [50, 0], [0, 50], [100, 0]]], [[[100, 0], [50, 0], [0, 50], [100, 0]]]]);

buffer(multiPt, 5);
buffer(multiLine, 5);
buffer(multiPoly, 5);

// Collections
const fc = featureCollection<Point|LineString>([pt, line]);
const gc = geometryCollection([pt.geometry, line.geometry]);

buffer(fc, 5);
buffer(gc, 5);

// Mixed Collections
const fcMixed = featureCollection<any>([pt, line, multiPt, multiLine]);
const gcMixed = geometryCollection([pt.geometry, line.geometry, multiPt.geometry, multiLine.geometry]);
开发者ID:Turbo87,项目名称:turf,代码行数:30,代码来源:types.ts

示例6: point

import {
    point, lineString, polygon,
    multiPoint, multiLineString, multiPolygon,
    featureCollection, geometryCollection} from '@turf/helpers'
import * as meta from '../index'

const pt = point([0, 0])
const line = lineString([[0, 0], [1, 1]])
const poly = polygon([[[0, 0], [1, 1], [0, 1], [0, 0]]])
const multiPoly = multiPolygon([[[[0, 0], [1, 1], [0, 1], [0, 0]]]])
const geomCollection = geometryCollection([pt.geometry, line.geometry])
const features = featureCollection([pt, line])

// coordEach
meta.coordEach(pt, coords => coords)
meta.coordEach(pt, (coords, index) => coords)
meta.coordEach(pt.geometry, coords => { const equal: number[] = coords })
meta.coordEach(line, coords => { const equal: number[] = coords })
meta.coordEach(poly, coords => { const equal: number[] = coords })
meta.coordEach(multiPoly, coords => { const equal: number[] = coords })
meta.coordEach(geomCollection, coords => coords)

// coordReduce
meta.coordReduce(pt, (previous, coords) => coords)
meta.coordReduce(pt, (previous, coords, index) => coords)
meta.coordReduce(pt, (previous, coords, index) => coords, 0)
meta.coordReduce(pt, (previous, coords) => { const equal: Array<number> = coords })
meta.coordReduce(geomCollection, (previous, coords) => coords)

interface CustomProps {
    foo: string
开发者ID:dpmcmlxxvi,项目名称:turf,代码行数:31,代码来源:types.ts

示例7: lineString

import {lineString, multiLineString, polygon, multiPolygon} from '@turf/helpers'
import * as lineOverlap from './'

const line = lineString([[0, 0], [10, 10]]);
const multiLine = multiLineString([[[0, 0], [10, 10]], [[30, 30], [50, 50]]]);
const poly = polygon([[[0, 0], [10, 10], [15, 15], [0, 0]]]);
const multiPoly = multiPolygon([
  [[[0, 0], [10, 10], [15, 15], [0, 0]]],
  [[[5, 5], [30, 30], [45, 45], [5, 5]]]
])

lineOverlap(line, poly)
lineOverlap(line, line)
lineOverlap(multiPoly, line)
lineOverlap(multiPoly, multiLine)
开发者ID:z0630,项目名称:turf,代码行数:15,代码来源:types.ts


注:本文中的@turf/helpers.multiPolygon函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。