Skip to content

Path optimization using the Douglas-Peucker Line Approximation Algorithm in Objective C

License

Notifications You must be signed in to change notification settings

tomislav/ShapeReducer-objc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShapeReducer (Objective-C)

Path optimization using the Ramer-Douglas-Peucker line simplification algorithm.

Written by Tomislav Filipčić tomislav@me.com

Installation

Add to your Podfile:

pod 'ShapeReducer', '~> 2.0'

Then run:

pod install

Usage

#import <ShapeReducer/ShapeReducer.h>

Shape *shape = [[[Shape alloc] init] autorelease];
[shape addPoint:[[[ShapePoint alloc] initWithLatitude:45.0000 longitude:15.0000 sequence:0] autorelease]];
[shape addPoint:[[[ShapePoint alloc] initWithLatitude:45.0100 longitude:15.0100 sequence:1] autorelease]];
[shape addPoint:[[[ShapePoint alloc] initWithLatitude:45.0200 longitude:15.0200 sequence:2] autorelease]];

ShapeReducer *reducer = [[[ShapeReducer alloc] init] autorelease];
Shape *reduced = [reducer reduce:shape tolerance:0.001];
NSArray<ShapePoint *> *points = [reduced points];

Tolerance Units

tolerance is measured in the same units as your input coordinates.

  • If you pass latitude/longitude degrees, tolerance is in degrees.
  • If you pass projected coordinates (for example meters), tolerance is in those units.

Behavior Notes

  • reduce:tolerance: always returns a new Shape instance.
  • Start and end points are always preserved for simplifiable paths.
  • Point ordering is based on each point's sequence.

Reference

Ramer-Douglas-Peucker algorithm

About

Path optimization using the Douglas-Peucker Line Approximation Algorithm in Objective C

Resources

License

Stars

Watchers

Forks

Packages

No packages published