emcconville/point-reduction-algorithms
Composer 安装命令:
composer require emcconville/point-reduction-algorithms
包简介
A collection of algorithms for reducing the number of points in polyline
README 文档
README
#Point Reduction Algorithms
A collection of algorithms for reducing the number of points in polygon / polyline.
Custom shapes, polygon & polyline in web-map applications, can have too many points. Often a shape will be rendered at a distant zoom-level, and wouldn't require such high-resolution. This library's goal is to provided basic methods to simplify & reduce shapes.
Install
With composer.
$ curl -sS https://getcomposer.org/installer | php
$ cat > composer.json <<EOF
{
"require": {
"emcconville/point-reduction-algorithms" : "~1.0"
}
}
EOF
$ php composer.phar install
Algorithms & Usage
Below is an original, uncompressed, polyline with 2151 points, and is delivered as SVG weighing in @ 175K.
All algorithms share a common abstraction, but each class implements a unique reduce method. Most reduction methods require one argument for tolerance / threshold; except, Visvalingam–Whyatt requires the desired final point count, and Opheim requires two independent thresholds.
Example Pseudo code:
use PointReduction\Algorithms\ALGORITHM_NAME; $obj = new ALGORITHM_NAME($myPoints); $myReducedPoints = $obj->reduce($tolerance);
The $myPoints must be an array, or traversable object that supports removing element at index. Each user defined point must implement PointReduction\Common\PointInterface which enforces a getCoordinates method. This common interface allows user objects to have any type of property (ie. x/y, latitude/longitude, left/top).
use PointReduction\Common\PointInterface; class MyPoint implements PointInterface { // ... my stuff here ... public function getCoordinates() { return array($this->myOwnX, $this->myOwnY); } }
Ramer–Douglas–Peucker
use PointReduction\Common\Point, PointReduction\Algorithms\RamerDouglasPeucker; $givenPoints = array( new Point(-84.158640, -39.822480), new Point(-84.159250, -39.820120), // ... and so one ); $epsilon = 0.001 $reducer = new RamerDouglasPeucker($givenPoints); $reducedPoints = $reducer->reduce($epsilon);
The original polygon of 2151 points has been reduced to 343.
Visvalingam–Whyatt
use PointReduction\Common\Point, PointReduction\Algorithms\VisvalingamWhyatt; $givenPoints = array( new Point(-84.158640, -39.822480), new Point(-84.159250, -39.820120), // ... and so one ); $desiredPointCount = 343; $reducer = new VisvalingamWhyatt($givenPoints); $reducedPoints = $reducer->reduce($desiredPointCount);
The original polygon of 2151 points has been reduced to 343.
Reumann–Witkam
use PointReduction\Common\Point, PointReduction\Algorithms\ReumannWitkam; $givenPoints = array( new Point(-84.158640, -39.822480), new Point(-84.159250, -39.820120), // ... and so one ); $threshold = 0.001; $reducer = new ReumannWitkam($givenPoints); $reducedPoints = $reducer->reduce($threshold);
The original polygon of 2151 points has been reduced to 872.
Opheim
use PointReduction\Common\Point, PointReduction\Algorithms\Opheim; $givenPoints = array( new Point(-84.158640, -39.822480), new Point(-84.159250, -39.820120), // ... and so one ); $perpendicularTolerance = 0.005; $radialTolerance = 0.01; $reducer = new Opheim($givenPoints); $reducedPoints = $reducer->reduce($perpendicularTolerance, $radialTolerance);
The original polygon of 2151 points has been reduced to 684.
Lang
use PointReduction\Common\Point, PointReduction\Algorithms\Lang; $givenPoints = array( new Point(-84.158640, -39.822480), new Point(-84.159250, -39.820120), // ... and so one ); $threshold = 0.001; $lookAhead = 7; $reducer = new Lang($givenPoints); $reducedPoints = $reducer->reduce($threshold, $lookAhead);
The original polygon of 2151 points has been reduced to 293.
Zhao-Saalfeld
Added in version 1.2.0.
use PointReduction\Common\Point, PointReduction\Algorithms\ZhaoSAalfeld; $givenPoints = array( new Point(-84.158640, -39.822480), new Point(-84.159250, -39.820120), // ... and so one ); $degree = 7; $lookAhead = 7; $reducer = new ZhaoSAalfeld($givenPoints); $reducedPoints = $reducer->reduce($degree, $lookAhead);
The original polygon of 2151 points has been reduced to 1493.
Radial Distance
Added in version 1.2.0.
use PointReduction\Common\Point, PointReduction\Algorithms\RadialDistance; $givenPoints = array( new Point(-84.158640, -39.822480), new Point(-84.159250, -39.820120), // ... and so one ); $tolerance = 0.0025; $reducer = new RadialDistance($givenPoints); $reducedPoints = $reducer->reduce($tolerance);
The original polygon of 2151 points has been reduced to 449.
emcconville/point-reduction-algorithms 适用场景与选型建议
emcconville/point-reduction-algorithms 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 202.73k 次下载、GitHub Stars 达 61, 最近一次更新时间为 2015 年 01 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Polygon」 「polyline」 「point-reduction」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 emcconville/point-reduction-algorithms 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 emcconville/point-reduction-algorithms 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 emcconville/point-reduction-algorithms 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ramer–Douglas–Peucker algorithm for polyline simplification
Simple Yet Powerful Geo Library
PHP helper classes to enforce RFC7946 polygon winding order in GeoJSON
Open-source native PHP library for doing geometry operations. Can read and write a wide variety of formats: (E)WKT, (E)WKB, TWKB, GeoJSON, KML, GPX, GeoRSS. Works with all Simple-Feature geometries (Point, LineString, Polygon...) and can be used to get centroids, bounding-boxes, area, etc.
Pure (no dependencies) implementation of blocksdk
Intended for use with lib16 SVG Builder.
统计信息
- 总下载量: 202.73k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 62
- 点击次数: 30
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GNU
- 更新时间: 2015-01-08