LineSimplifier - Polyline simplification. Port of simplify.js

Overview

LineSimplifier

LineSimplifier is a small Swift Package to simplify lines. A line is connecting multiple points and does not need to be straight. In this package a line could also be called path or route.

Limitations: This package only works with 2 dimensional points.

Sometimes you have a lot of points describing the line, but they are not all needed, because a rough course of the line is good enough. Using a lot of points in a line requires a lot of resources which is not always needed. So a simplified version of the line is good enough

This Swift Package is inspired by the original simplify in Java and the Swift translation. However, I felt like the swift version of it could use some improvements.

Example GPS tracks

A real life example to use this package are gps tracks. Depending on the data it might include a ton of data which is not really needed to simply draw the gps route on a map. Especially when multiple routes are displayed, memory can become a problem when only the raw route data is used.

With LineSimplifier the route can be simplified and a lot of points will drop out which saves memory.

Underlaying algorithm

LineSimplifier is based on the Ramer–Douglas–Peucker algorithm.

Using LineSimplifier

LineSimplifier comes with the Point2DRepresentable protocol. Just conform your type to this protocol to use the simplification algorithm. After conforming to the protocol, just use the LineSimplifier.simplify function. Use the tolerance prameter to control the degree of simplification. Use the useHighestQuality parameter to get the best quality. However, better quality requires more time to calculate the simplification. If useHighestQuality is used, only the Ramer–Douglas–Peucker algorithm will be used. If useHighestQuality is set to false, a pre filtering with a radial distance is used to save some steps in Ramer–Douglas–Peucker algorithm.

LineSimplifier adds the Point2DRepresentable conformance to CLLocationCoordinate2D and CGPoint out of the box. For other types, you need to implement th protocol yourself.

Here is a small example:

import CoreLocation
import LineSimplifier

let points: [CLLocationCoordinate2D] = ...
let result = LineSimplifier.simplify(points: points, withTolerance: 0.003)
let result2 = LineSimplifier.simplify(points: points, withTolerance: 0.003, useHighestQuality: true)

With the Array extension you can also use it just like this:

import CoreLocation
import LineSimplifier

let points: [CLLocationCoordinate2D] = ...
let result = points.simplify(withTolerance: 0.003)
let result2 = points.simplify(withTolerance: 0.003, useHighestQuality: true)

Tolerance

The value of the tolerance heavyly depends on the points range.

For GPS coordinates the tests resulted like so:

Tolerance Resulting points
0.0001 107
0.00001 818
0.000001 3.575
0.0000001 10.088
0.00000001 12.798
Original 13.395

The tolerance needs to be quite small, because it is in gps coordinates nature to only differ in decimal points for distances in meter range.

You might also like...
KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.
KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS.

KolodaView Check this article on our blog. Purpose KolodaView is a class designed to simplify the implementation of Tinder like cards on iOS. It adds

TLIndexPathTools is a small set of classes that can greatly simplify your table and collection views.

TLIndexPathTools TLIndexPathTools is a small set of classes that can greatly simplify your table and collection views. Here are some of the awesome th

A Swift port of the Cassowary linear constraint solver

Cassowary Swift A Swift port of the Cassowary linear constraints solver. Tested on OS X, iOS and Linux. Example usage let solver = Solver() let left

This is a Swift port of Ruby's Faker library that generates fake data.
This is a Swift port of Ruby's Faker library that generates fake data.

This is a Swift port of Ruby's Faker library that generates fake data. Are you still bothered with meaningless randomly character strings? Just relax

A Swift port of some of the original PersistentJXA projects by D00MFist

Persistent-Swift This repo is a Swift port of some of the original PersistentJXA projects by D00MFist (https://github.com/D00MFist/PersistentJXA). I p

ImagePalette - Swift/iOS port of Android's Palette

ImagePalette - Swift/iOS port of Android's Palette

A port of SwiftUILab's Advanced Animations that also supports macOS
A port of SwiftUILab's Advanced Animations that also supports macOS

SwiftUILab Advanced Animations on the Mac as well A port of SwiftUILab's Advanced Animations that also supports macOS Here's the Ghist of the original

Swift port of AnyPic project

SwiftAnyPic Swift port of AnyPic project https://github.com/ParsePlatform/Anypic Requirements This application requires Xcode 7 and the iOS SDK v9.0.

Native iOS port of KDE Connect

Welcome to KDE Connect iOS 2021's Testing Repository! This project is inteded to be the iOS version of the group of applications called KDE Connect, w

Debit/Credit card validation port of the Luhn Algorithm in Swift

SwiftLuhn Warning! This repository is no longer maintained. This is a port of the Luhn Algorithm, generally used for validating debit/credit card deta

iOS port from libphonenumber (Google's phone number handling library)

libPhoneNumber for iOS NBPhoneNumberUtil NBAsYouTypeFormatter ARC only Update Log https://github.com/iziz/libPhoneNumber-iOS/wiki/Update-Log Issue You

__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

SwiftOpenColor - Swift port of OpenColor

Using Swift Package Manager, add it as a Swift Package in Xcode 11.0 or later

nds4ios is a port of the multi-platform Nintendo DS emulator, DeSmuME to iOS.

nds4ios Supports iOS 6 to iOS 9. nds4ios is a port of the multi-platform Nintendo DS emulator, DeSmuME to iOS. Currently, emulation is powered by a th

iDOS - DOSBox port on iOS

dospad dosbox port for iOS, aka iDOS, based on dosbox v0.74-3 and SDL1.2. This is an all-in-one project, so the build process is just one simple click

iOS port of the Tachiyomi manga reader.

Tachiyomi iOS An iOS port of the popular Tachiyomi Manga Reader for Android. About the Project Hello fellow manga enthusiasts! For too long now Androi

Commands providing shortcuts to common Postgres introspection queries (Swift port of heroku-pg-extras)

Commands providing shortcuts to common Postgres introspection queries (Swift port of heroku-pg-extras)

Port of BetterPS to Apple WebKit for macOS.
Port of BetterPS to Apple WebKit for macOS.

BetterPS-Safari Port of BetterPS to Apple WebKit for macOS. Note: .xcodeproj file will not be uploaded for privacy reasons. Please initiate a new proj

A proof-of-concept WebURL domain renderer, using a port of Chromium's IDN spoof-checking logic to protect against confusable domains

WebURLSpoofChecking A proof-of-concept WebURL.Domain renderer which uses a port of Chromium's IDN spoof-checking logic (Overview, Implementation) to p

Owner
Andre
Andre
A library to simplify iOS animations in Swift.

Updated for Swift 4.2 Requires Xcode 10 and Swift 4.2. Installation Drop in the Spring folder to your Xcode project (make sure to enable "Copy items i

Meng To 14k Jan 3, 2023
Promises simplify asynchronous programming, freeing you up to focus on the more important things

Promises simplify asynchronous programming, freeing you up to focus on the more important things. They are easy to learn, easy to master and result in

Max Howell 14k Jan 5, 2023
Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS

Mockingbird Mockingbird was designed to simplify software testing, by easily mocking any system using HTTP/HTTPS, allowing a team to test and develop

FARFETCH 183 Dec 24, 2022
An UITextField subclass to simplify country code's picking. Swift 5.0

Preview Installation NKVPhonePicker is available through CocoaPods. To install it, simply add the following line to your Podfile: pod 'NKVPhonePicker'

Nike Kov 140 Nov 23, 2022
CompositionalLayoutDSL, library to simplify the creation of UICollectionViewCompositionalLayout. It wraps the UIKit API and makes the code shorter and easier to read.

CompositionalLayoutDSL CompositionalLayoutDSL is a Swift library. It makes easier to create compositional layout for collection view. Requirements Doc

FABERNOVEL 44 Dec 27, 2022
A set of UIKit helpers that simplify the usage of UIKit view's and controller's in SwiftUI.

A set of UIKit helpers that simplify the usage of UIKit view's and controller's in SwiftUI. Many of these helpers are useful even in a pure UIKit project.

SwiftUI+ 6 Oct 28, 2022
A collection of operators and utilities that simplify iOS layout code.

Anchorage A lightweight collection of intuitive operators and utilities that simplify Auto Layout code. Anchorage is built directly on top of the NSLa

Rightpoint 620 Jan 3, 2023
Simplify your iOS/Mac analytics

ARAnalytics v4 ARAnalytics is to iOS what Analytical is to ruby, or Analytics.js is to javascript. ARAnalytics is an analytics abstraction library off

Orta Therox 1.8k Dec 29, 2022
An iBeacon Manager library was created to simplify your interactions with iBeacons.

JMCiBeaconManager iBeacon is a name of technology that is enabling new location awareness possibilities for apps. "Leveraging Bluetooth Low Energy (BL

Izotx 146 Dec 17, 2022
LibAuthentication will simplify your code when if you want to use FaceID/TouchID in your tweaks.

LibAuthentication will simplify your code when if you want to use FaceID/TouchID in your tweaks.

Maximehip 6 Oct 3, 2022