搜索插件、代码仓与 APP 分类

插件详情v0.0.2

turf_pip

一个用于检测点是否位于多边形内的小型库

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
17万
喜欢数
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 项

源码仓库

使用此插件的项目