#include "ogrsf_frmts.h"
bool LayerMethod(const char *pszSrcShp,const char *pszMethodShp,const char *pszDstShp,int iType)
{
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO");
//注:此处注册不是GDALAllRegister
OGRRegisterAll();
//打开数据
OGRDataSource *poSrcDS=OGRSFDriverRegistrar::Open(pszSrcShp,FALSE );
if( poSrcDS == NULL )
{
printf("打开文件 %s 失败.\n",pszSrcShp);
return false;
}
OGRDataSource *poMethodDS=OGRSFDriverRegistrar::Open(pszMethodShp,FALSE );
if( poMethodDS == NULL )
{
printf("打开文件 %s 失败.\n",poMethodDS);
OGRDataSource::DestroyDataSource(poSrcDS);
return false;
}
//创建数据
OGRSFDriver *poDriver=OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("ESRI Shapefile");
if( poDriver == NULL )
{
printf("格式%s不支持.\n","ESRI Shapefile");
OGRDataSource::DestroyDataSource(poSrcDS);
OGRDataSource::DestroyDataSource(poMethodDS);
return false;
}
OGRDataSource *poDstDS=poDriver->CreateDataSource(pszDstShp,NULL);
if( poDstDS == NULL )
{
printf("输出数据集失败.\n");
OGRDataSource::DestroyDataSource(poSrcDS);
OGRDataSource::DestroyDataSource(poMethodDS);
return false;
}
OGRLayer *poSrcLayer=poSrcDS->GetLayer(0);
if(poSrcLayer==NULL)
{
printf("创建图层失败.\n");
OGRDataSource::DestroyDataSource(poSrcDS);
OGRDataSource::DestroyDataSource(poMethodDS);
OGRDataSource::DestroyDataSource(poDstDS);
return false;
}
OGRLayer *poMethodLayer=poMethodDS->GetLayer(0);
if(poMethodLayer==NULL)
{
printf("创建图层失败.\n");
OGRDataSource::DestroyDataSource(poSrcDS);
OGRDataSource::DestroyDataSource(poMethodDS);
OGRDataSource::DestroyDataSource(poDstDS);
return false;
}
OGRSpatialReference *pSRS=poSrcLayer->GetSpatialRef();
OGRLayer *poDstLayer=poDstDS->CreateLayer("NewLayer",pSRS,wkbPolygon,NULL);
if(poDstLayer==NULL)
{
printf("创建图层失败.\n");
OGRDataSource::DestroyDataSource(poSrcDS);
OGRDataSource::DestroyDataSource(poMethodDS);
OGRDataSource::DestroyDataSource(poDstDS);
return false;
}
switch(iType)
{
case 0:
poSrcLayer->Intersection(poMethodLayer,poDstLayer,NULL,GDALTermProgress,NULL);
break;
case 1:
poSrcLayer->Union(poMethodLayer,poDstLayer,NULL,GDALTermProgress,NULL);
break;
case 2:
poSrcLayer->SymDifference(poMethodLayer,poDstLayer,NULL,GDALTermProgress,NULL);
break;
case 3:
poSrcLayer->Identity(poMethodLayer,poDstLayer,NULL,GDALTermProgress,NULL);
break;
case 4:
poSrcLayer->Update(poMethodLayer,poDstLayer,NULL,GDALTermProgress,NULL);
break;
case 5:
poSrcLayer->Clip(poMethodLayer,poDstLayer,NULL,GDALTermProgress,NULL);
break;
case 6:
poSrcLayer->Erase(poMethodLayer,poDstLayer,NULL,GDALTermProgress,NULL);
break;
default:break;
}
OGRDataSource::DestroyDataSource(poSrcDS);
OGRDataSource::DestroyDataSource(poMethodDS);
OGRDataSource::DestroyDataSource(poDstDS);
return true;
}
int main()
{
const char *pszSrcFile="D:\\Documents\\VS\\CreateIm\\shpManage\\SrcLayer.shp";
const char *pszMethodFile="D:\\Documents\\VS\\CreateIm\\shpManage\\MethodLayer.shp";
const char *pszOutFile0="D:\\Documents\\VS\\CreateIm\\shpManage\\Intersection.shp";
const char *pszOutFile1="D:\\Documents\\VS\\CreateIm\\shpManage\\Union.shp";
const char *pszOutFile2="D:\\Documents\\VS\\CreateIm\\shpManage\\SymDifference.shp";
const char *pszOutFile3="D:\\Documents\\VS\\CreateIm\\shpManage\\Identity.shp";
const char *pszOutFile4="D:\\Documents\\VS\\CreateIm\\shpManage\\Update.shp";
const char *pszOutFile5="D:\\Documents\\VS\\CreateIm\\shpManage\\Clip.shp";
const char *pszOutFile6="D:\\Documents\\VS\\CreateIm\\shpManage\\Erase.shp";
LayerMethod(pszSrcFile,pszMethodFile,pszOutFile0,0);
LayerMethod(pszSrcFile,pszMethodFile,pszOutFile1,1);
LayerMethod(pszSrcFile,pszMethodFile,pszOutFile2,2);
LayerMethod(pszSrcFile,pszMethodFile,pszOutFile3,3);
LayerMethod(pszSrcFile,pszMethodFile,pszOutFile4,4);
LayerMethod(pszSrcFile,pszMethodFile,pszOutFile5,5);
LayerMethod(pszSrcFile,pszMethodFile,pszOutFile6,6);
// CreateRasterFile();
// UpdateRasterFile();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
CreateIm.rar (76个子文件)
CreateIm
CreateIm.suo 15KB
shpManage
Identity.prj 402B
SrcLayer.shx 108B
Erase.shp 1KB
MethodLayer.shx 108B
Union.dbf 408B
Update.shx 116B
MethodLayer.sbx 116B
Erase.shx 108B
Intersection.shx 108B
Union.shx 124B
Intersection.prj 402B
Clip.shx 108B
Erase.prj 402B
SymDifference.dbf 347B
SrcLayer.shp 236B
SymDifference.shx 116B
Update.dbf 191B
SymDifference.shp 3KB
MethodLayer.sbn 132B
Intersection.dbf 286B
Identity.shx 116B
Identity.dbf 347B
SrcLayer.sbx 116B
Intersection.shp 1KB
Union.shp 4KB
MethodLayer.dbf 161B
Update.prj 402B
Union.prj 402B
MethodLayer.prj 400B
SrcLayer.dbf 161B
Clip.shp 1KB
MethodLayer.shp 3KB
Erase.dbf 160B
Clip.prj 402B
SrcLayer.sbn 132B
Identity.shp 2KB
SrcLayer.prj 400B
Clip.dbf 160B
Update.shp 4KB
SymDifference.prj 402B
CreateIm
CreateIm.vcxproj.filters 1KB
ShpLayerMethod.cpp 4KB
RasterManage.h 1015B
CreateUpdateData.h 4KB
CreateIm.vcxproj.user 143B
CreateIm.vcxproj 7KB
x64
Release
CL.write.1.tlog 2KB
mt.read.1.tlog 742B
CreateUpdateImage.obj 1.21MB
CreateIm.lastbuildstate 52B
link.command.1.tlog 3KB
vc100.pdb 436KB
CL.read.1.tlog 47KB
CreateIm.exe.intermediate.manifest 381B
mt.write.1.tlog 270B
CreateIm.write.1.tlog 4KB
.NETFramework,Version=v4.0.AssemblyAttributes.obj 3KB
ShpLayerTest.obj 1.5MB
mt.command.1.tlog 460B
link.write.1.tlog 696B
ShpLayerMethod.obj 1.52MB
cl.command.1.tlog 4KB
link.read.1.tlog 4KB
CreateIm.log 3KB
createImage.obj 1.21MB
CreateIm.sdf 9.33MB
x64
Release
CreateIm.exe 141KB
CreateIm.lib 177KB
gdal110.dll 11.26MB
CreateIm.exp 107KB
geos.dll 2.26MB
geos_c.dll 2MB
CreateIm.pdb 1.12MB
proj.dll 480KB
CreateIm.sln 1KB
共 76 条
- 1
h567125
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页