资源简介
实现了道格拉斯普克算法的Python源代码,用于处理数据压缩
代码片段和文件信息
# -*- coding=utf-8 -*-
import gpxpy
import gpxpy.gpx
import math
from pyproj import Proj
#定义一个点类
class cPoint:
x=0.0
y=0.0
index=0
def __init__(selfxyindex):
self.x=x
self.y=y
self.index=index
#定义道格拉斯普克算法类
class Douglas:
cPoints=[] #存储点的列表
D=1 #在道格拉斯普克算法中需要自定义设置的阈值
def __init__(selfcPoints):
self.cPoints=cPoints
def compress(selfp1p2):
oPoints=[]
swichvalue=False
#判断是否需要进行抽稀算法
#直线一般式方程的3个系数
A=(p1.y-p2.y)/math.sqrt(math.pow(p1.y-p2.y2)+math.pow(p1.x-p2.x2))
B=(p2.x-p1.x)/math.sqrt(math.pow(p1.y-p2.y2)+math.pow(p1.x-p2.x2))
C=(p1.x*p2.y-p2.x*p1.y)/math.sqrt(math.pow(p1.y-p2.y2)+math.pow(p1.x-p2.x2))
m=self.cPoints.index(p1)
n=self.cPoints.index(p2)
#print m
#print n
distance=[]
middle=None
if(n==m+1): #判断起点和终点之间是否有点
return
#计算中间点到直线的距离
for i in range(m+1n):
d=abs(A*self.cPoints[i].x+B*self.cPoints[i].y+C)/math.sqrt(math.pow(A2)+math.pow(B2))
distance.append(d)
dmax=max(distance)
#print distance
if dmax>self.D:
swichvalue=True
else:
swichvalue=False
#for i in range(09):
#print self.cPoints[i].x
if(swichvalue==False):
for j in range(m+1n):
#del self.cPoints[j]
self.cPoints[j].x=0
else:
for h in range(m+1n):
if(abs(A*self.cPoints[h].x+B*self.cPoints[h].y+C)/math.sqrt(math.pow(A2)+math.pow(B2))==dmax):
middle=self.cPoints[h]
self.compress(p1middle)
self.compress(middlep2)
#for i in range(0len(self.cPoints)):
#if self.cPoints[i].x!=0:
#oPoints.append(self.cPoints[i])
return oPoints
def __init__(selfmpoin
- 上一篇:数据压缩DP算法源代码
- 下一篇:IEXPath.rar
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论