• 大小: 2.63MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-09
  • 语言: C/C++
  • 标签:

资源简介

打开txt文件,读取其中的坐标数据,并利用DP算法进行简化。其中,txt文件是由shp文件转化而来,有不同的线对象,每个线对象有各自的很多坐标点,简化时是根据每个线对象进行简化,输出的数据与原数据格式相同,可转化回shp数据进行显示。shp、txt格式之间相互转换的工具在CSDN上面有,用户可另行下载,亲测可以用,程序运行所需的相关数据已一并打包。有任何问题欢迎留言。

资源截图

代码片段和文件信息

// DP.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

int _tmain(int argc _TCHAR* argv[])
{
return 0;
}

const int LineMax=7120;//线对象数目的最大值
const int PointMax=120;//每个线对象中点数目的最大值
double torelance=1.0;//阈值

typedef struct point
{
int i;
long double x;
long double y;
}POINT;

long double datax[LineMax][PointMax]={0.0000000};
long double datay[LineMax][PointMax]={0.0000000};
int t;//记录txt数据有多少个线段
int pin[250]={0};//记录每条线段分别有多少个点;

int TAG[LineMax][PointMax]={0};
//////////////////////////////////////////////////////////////////////////
int Readdata(string );
void DouglasPeuker(int int int double);
double cacuDistance(int int int int);
void Writedata(string );

//////////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc char* argv[])
{
//char path1[]=“F:\\DATA\\Result\\WR.txt“;//打开文件的路径
//char path2[]=“F:\\DATA\\Result\\WRDP.txt“;//输出文件的路径
string path1=“F:\\DATA\\Result\\WR.txt“;//打开文件的路径
//string path2=“F:\\DATA\\Result\\WRDP2.txt“;//打开文件的路径
char buffer[100];
sprintf(buffer“F:\\DATA\\Result\\WRDP2_%f.txt“torelance);
string path2(buffer);


t=Readdata(path1);
cout<<“线对象总数为:“<
cout<<“阈值为:tolerance=“< for(int i=0;i DouglasPeuker(0pin[i]-1itorelance);
Writedata(path2);
return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
int Readdata(string filename)
{
ifstream fin0;
POINT point0;
point0.x=0.0;//启用浮点库,不加报错
point0.y=0.0;

int i=0j=0;//i为线段数目,最后赋给t;j为每条线段的点数;

string  line;
fin0.open(filename);
if (!fin0.is_open())
{
cout<<“Can‘t open the txt!\n“;
exit(EXIT_FAILURE);
}
getline(fin0line);
getline(fin0line);
getline(fin0line);
cout< while (fin0.good())
{
while(line.size()>5)
{
istringstream is(line);//使用构造函数,把str转化成输入流  
is>>point0.i;
is>>point0.x;
is>>point0.y;
//cout< datax[i][j]=point0.x;
datay[i][j]=point0.y;
j++;
getline(fin0line);
}
if(fin0.eof())
{
pin[i]=j;
i++;
j=0;
break;
}
else
{
pin[i]=j;
i++;
j=0;
getline(fin0line);

}

}
fin0.close();
return i;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
void DouglasPeuker(int leftpointint rightpointint ydouble tolerance)
{
int imaxindex=0;
double dismaxdis=0.0;
for (i=leftpoint;i {
dis=cacuDistance(leftpointrightpointyi);
if (dis>maxdis)
{
maxdis=dis;
maxindex=i;
}
}

if (maxdis>tolerance)
{
TAG[y][maxindex]=1;
DouglasPeuker(le

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     121344  2016-05-05 20:59  DP\DP-完成版 - 优化版\Debug\DP.exe

     文件    1076172  2016-05-05 20:59  DP\DP-完成版 - 优化版\Debug\DP.ilk

     文件    1248256  2016-05-05 20:59  DP\DP-完成版 - 优化版\Debug\DP.pdb

     文件         10  2016-05-05 19:44  DP\DP-完成版 - 优化版\DP\DATAResultWRCDP.txt

     文件         10  2016-05-05 19:42  DP\DP-完成版 - 优化版\DP\DATAResultW_RDP.txt

     文件       3994  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\cl.command.1.tlog

     文件      20118  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\CL.read.1.tlog

     文件       1756  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\CL.write.1.tlog

     文件        406  2016-04-14 10:20  DP\DP-完成版 - 优化版\DP\Debug\DP.exe.embed.manifest

     文件        472  2016-05-05 20:40  DP\DP-完成版 - 优化版\DP\Debug\DP.exe.embed.manifest.res

     文件        381  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\DP.exe.intermediate.manifest

     文件         89  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\DP.lastbuildstate

     文件       2537  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\DP.log

     文件     290697  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\DP.obj

     文件    1179648  2016-05-05 20:39  DP\DP-完成版 - 优化版\DP\Debug\DP.pch

     文件        713  2016-04-14 09:42  DP\DP-完成版 - 优化版\DP\Debug\DP.vcxprojResolveAssemblyReference.cache

     文件          0  2016-04-14 09:42  DP\DP-完成版 - 优化版\DP\Debug\DP.write.1.tlog

     文件        194  2016-04-14 10:20  DP\DP-完成版 - 优化版\DP\Debug\DP_manifest.rc

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link-cvtres.read.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link-cvtres.write.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.11420-cvtres.read.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.11420-cvtres.write.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.11420.read.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.11420.write.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.1164-cvtres.read.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.1164-cvtres.write.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.1164.read.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.1164.write.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.3108-cvtres.read.1.tlog

     文件          2  2016-05-05 20:59  DP\DP-完成版 - 优化版\DP\Debug\link.3108-cvtres.write.1.tlog

............此处省略70个文件信息

评论

共有 条评论