Comments (5)
I had the same problem, so I translated the code in the previous link to Python. You are free to use it.
from math import sqrt
import numpy as np
def _DouglasPeucker(points, startIndex, lastIndex, epsilon):
stk = []
stk.append([startIndex, lastIndex])
globalStartIndex = startIndex
bitArray = np.ones(lastIndex-startIndex+1, dtype=bool)
while len(stk) > 0:
startIndex = stk[-1][0]
lastIndex = stk[-1][1]
stk.pop()
dmax = 0.
index = startIndex
for i in xrange(index+1, lastIndex):
if bitArray[i - globalStartIndex]:
d = PointLineDistance(points[i], points[startIndex], points[lastIndex])
if d > dmax:
index = i
dmax = d
if dmax > epsilon:
stk.append([startIndex, index])
stk.append([index, lastIndex])
else:
for i in xrange(startIndex + 1, lastIndex):
bitArray[i - globalStartIndex] = False
return bitArray
def DouglasPeucker(points, epsilon):
bitArray = _DouglasPeucker(points, 0, len(points)-1, epsilon)
resList = []
for i in xrange(len(points)):
if bitArray[i]:
resList.append(points[i])
return np.array(resList)
def PointLineDistance(point, start, end):
if np.all(np.equal(start, end)) :
return np.linalg.norm(point, start)
n = abs((end[0] - start[0]) * (start[1] - point[1]) - (start[0] - point[0]) * (end[1] - start[1]))
d = sqrt((end[0] - start[0]) * (end[0] - start[0]) + (end[1] - start[1]) * (end[1] - start[1]))
return n/d
from rdp.
@sebacastroh Wow, thanks, I just wanted to start with it but it's definitely better this way 👍
@fhirschmann Do you need help with integrating that code? Since your package seems to be the most popular Python package for RDP I guess it's good to include it. Maybe even someone wants to add a Cython version based on that code later on.
from rdp.
Sorry for the long delay!
I agree that without tail call optimization in Python, an iterative version is better suited.
I will start integrating the code of @sebacastroh and also quickcheck it against the recursive version.
@Namek, are you fine with integrating the above code which is based on your code to the Python rdp library?
from rdp.
@Namek, are you fine with integrating the above code which is based on your code to the Python rdp library?
@fhirschmann Sure! It's open source and has no specific license. If it's properly done and works for you then just take it.
from rdp.
Iterative version added in v0.7. Thanks!
from rdp.
Related Issues (12)
- Makes no difference in reducing the number of points HOT 1
- simplify_coords function causes unexpected exit
- Wrong calculation of pldist HOT 3
- Link to blog post in docs gets redirected to blog front page HOT 2
- epsilon is int type HOT 1
- A c++ (speed up) version of Ramer-Douglas-Peucker with python binding of identical interface HOT 1
- Can you put a new release? HOT 1
- Bizarre np.linalg.norm error HOT 6
- unoptimized for loop HOT 5
- keeping track of the index element output from rdp HOT 3
- limiting number of points HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rdp.