搜尋套件、儲存庫與 APP 分類

套件詳情v0.0.2

turf_pip

用於檢測點是否位於多邊形內的小型函式庫

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
16.2萬
喜歡數
1
Pub 分數
150

安裝套件

flutter pub add turf_pip

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

turf_pip 是一個輕量級的 Dart 庫,用於判斷地理點是否位於多邊形內。它實現了點在多邊形內的演算法,常見於空間分析和地圖應用。該套件支援 Android、iOS、Web、macOS、Windows 和 Linux 等多個平台,適用於跨平台地理空間邏輯。非常適合用於基於位置的服務、地圖互動或空間資料驗證等情境。可透過 Flutter 的 pub 套件管理器輕鬆整合。

適用情境

  • 地理定位驗證
  • 基於地圖的篩選
  • 空間資料分析
  • 互動式地圖功能
  • 位置感知應用
  • GIS 處理

主要特色

  • 點在多邊形內檢測
  • 跨平台支援
  • 輕量且快速
  • 與 Flutter 的輕鬆整合
  • 純 Dart 實現
  • 無外部依賴

適合對象

  • 使用地圖的Flutter開發者
  • 需要空間查詢的應用程式
  • 後端或前端地理空間邏輯
  • 具有位置功能的行動和網頁應用
  • 尋求最小佔用空間工具的開發者

使用建議

  • 限制為2D點和多邊形幾何
  • 不支援複雜的幾何圖形,例如多邊形
  • 無座標轉換或投影處理
  • 假設輸入座標為WGS84(緯度/經度)格式
  • 未針對高頻率即時檢查進行優化

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

turf_pip

A small library for detecting if a point lies inside a polygon.

A port of: point-in-polygon-hao NPM package.

Point in polygon library based on the paper "Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons" by Hao.

Features

  • Works on polygons with holes
  • Works with degenerate/self-intersecting polyons
  • Returns PointInPolygonResult.isOnEdge if on the edge, PointInPolygonResult.isInside if inside and PointInPolygonResult.isOutside if outside
  • Not effected by floating point errors
Usage

Install via dart pub add turf_pip

import 'package:turf_pip/turf_pip.dart';

const polygon = Polygon(coordinates:[
  [
    Position.of([1, 1]),
    Position.of([1, 2]),
    Position.of([2, 2]),
    Position.of([2, 1]),
    Position.of([1, 1])
  ]
]);

pointInPolygon(Point(coordinates: Position.of([ 1.5, 1.5 ]), polygon)
// => PointInPolygonResult.isInside

pointInPolygon(Point(coordinates: Position.of([ 4.9, 1.2 ]), polygon)
// => PointInPolygonResult.isOutside

pointInPolygon(Point(coordinates: Position.of([1, 2]), polygon)
// => PointInPolygonResult.isOnEdge

Note: The input polygon format aligns with the GeoJson specification for polygons. This means that the first and last coordinate in a polygon must be repeated, if not this library will throw an error.

var polygonWithHole = Polygon(coordinates:([
  [
    Position.of([0, 0]),
    Position.of([1, 0]),
    Position.of([1, 1]),
    Position.of([0, 1]),
    Position.of([0, 0]),
  ],
  [
    Position.of([0.1, 0.1]),
    Position.of([0.1, 0.9]),
    Position.of([0.9, 0.9]),
    Position.of([0.9, 0.1]),
    Position.of([0.1, 0.1]),
  ]
]);

The library does not support multi-polygons.

Comparisons

Some rough comparisons to similar libraries. While point-in-polygon is slightly faster in most cases it does not support polygons with holes or degenerate polygons.

// For a point in a much larger geometry (700+ vertices)
point-in-poly-hao x 474,180 ops/sec ±0.55% (93 runs sampled)
point-in-polygon x 489,649 ops/sec ±0.75% (91 runs sampled)
robust-point-in-polygon x 376,268 ops/sec ±0.79% (89 runs sampled)
// For a point in bounding box check
point-in-poly-hao x 29,365,704 ops/sec ±1.30% (90 runs sampled)
point-in-polygon x 42,339,450 ops/sec ±0.78% (95 runs sampled)
robust-point-in-polygon x 20,675,569 ops/sec ±0.65% (95 runs sampled)
Algorithm

This library is based on the paper Optimal Reliable Point-in-Polygon Test and Differential Coding Boolean Operations on Polygons

Other notes
  • Works irrespective of winding order of polygon
  • Does not appear to be effected by floating point errors compared to point-in-polygon or robust-point-in-polygon

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案