#include "ogrsf_frmts.h"
#include <iostream>
using namespace std;
int main()
{
const char *pszDriverName = "ESRI Shapefile";
OGRSFDriver *poDriver;
OGRRegisterAll();
poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
pszDriverName );
if( poDriver == NULL )
{
printf( "%s driver not available.\n", pszDriverName );
exit( 1 );
}
OGRDataSource *poDS;
poDS = poDriver->CreateDataSource( "point_out.shp", NULL );//但文件夹中以前存在point_out.shp文件时会报错;
if( poDS == NULL )
{
printf( "Creation of output file failed.\n" );
exit( 1 );
}
OGRLayer *poLayer;
poDS->CreateLayer( "point_out_layer", NULL, wkbPoint, NULL );
poLayer=NULL;
poLayer = poDS->GetLayer(0);//shp文件只有一个图层;
if( poLayer == NULL )
{
printf( "Layer creation failed.\n" );
exit( 1 );
}
OGRFieldDefn oField( "Name", OFTString );
oField.SetWidth(32);
if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
printf( "Creating Name field failed.\n" );
exit( 1 );
}
double x, y;
char szName[33];
cout<<"输入:x,y,name"<<"(Example:30,30,lu)"<<"逗号为英文下的逗号,否则按回车便结束程序"<<endl;
cout<<"要想结束输入,按ctrl+d,再按回车键"<<endl;
while( !feof(stdin) // stdin文件流的结束符按ctrl+d,这样便结束while循环;
&& fscanf( stdin, "%lf,%lf,%32s", &x, &y, szName ) == 3 )
{
OGRFeature *poFeature;
poFeature=OGRFeature::CreateFeature(poLayer->GetLayerDefn());//必须用CreateFeature来生成对象,用new生成对象出错
//poFeature = new OGRFeature( poLayer->GetLayerDefn() );//必须用CreateFeature来生成对象,用new生成对象出错
poFeature->SetField( "Name", szName );
OGRPoint pt;
pt.setX( x );
pt.setY( y );
poFeature->SetGeometry( &pt );
if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE )
{
printf( "Failed to create feature in shapefile.\n" );
exit( 1 );
}
OGRFeature::DestroyFeature( poFeature );
}
OGRDataSource::DestroyDataSource( poDS );
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
GDAL创建Shape文件.rar (99个子文件)
GDAL创建Shape文件
GDALOGR_CreateShapefile
GDALOGR_CreateShapefile
GDALOGR_CreateShapefile.vcxproj.filters 952B
Debug
cl.command.1.tlog 2KB
GDALOGR_CreateShapefile.exe.embed.manifest.res 472B
link.3680.write.1.tlog 2B
link.3680-cvtres.write.1.tlog 2B
rc.command.1.tlog 2KB
CL.read.1.tlog 23KB
vc100.idb 387KB
mt.read.1.tlog 1KB
GDALOGR_CreateShapefile.exe.embed.manifest 406B
link.5864-cvtres.read.1.tlog 2B
link-cvtres.read.1.tlog 2B
link.read.1.tlog 8KB
GDALOGR_CreateShapefile.Build.CppClean.log 4KB
link.3680-cvtres.read.1.tlog 2B
rc.read.1.tlog 1KB
link.write.1.tlog 3KB
WriteShapeFile.obj 660KB
CL.write.1.tlog 1KB
link.10096.read.1.tlog 2B
link.5864-cvtres.write.1.tlog 2B
GDALOGR_CreateShapefile.log 3KB
vc100.pdb 316KB
GDALOGR_CreateShapefile_manifest.rc 236B
link.10096-cvtres.write.1.tlog 2B
link.command.1.tlog 4KB
mt.write.1.tlog 610B
link.10096.write.1.tlog 2B
GDALOGR_CreateShapefile.lastbuildstate 99B
link.5864.write.1.tlog 2B
mt.command.1.tlog 1KB
GDALOGR_CreateShapefile.exe.intermediate.manifest 381B
link.10096-cvtres.read.1.tlog 2B
link.3680.read.1.tlog 2B
rc.write.1.tlog 1KB
link-cvtres.write.1.tlog 2B
GDALOGR_CreateShapefile.write.1.tlog 8KB
link.5864.read.1.tlog 2B
GDALOGR_CreateShapefile.vcxproj.user 143B
WriteShapeFile.cpp 2KB
point_out.shp 240B
point_out_.dbf 230B
GDALOGR_CreateShapefile.vcxproj 4KB
point_out_.evf 2KB
point_out.dbf 230B
point_out.shx 140B
Debug
GDALOGR_CreateShapefile.exe 203KB
GDALOGR_CreateShapefile.pdb 1.6MB
GDALOGR_CreateShapefile.ilk 1.78MB
gdal19.dll 6.61MB
GDALOGR_CreateShapefile.exp 104KB
GDALOGR_CreateShapefile.lib 179KB
ipch
gdalogr_createshapefile-100f8d5e
gdalogr_createshapefile-cb574990.ipch 16.44MB
GDALOGR_CreateShapefile.sln 936B
GDALOGR_CreateShapefile.sdf 6.64MB
GDALOGR_CreateShapefile.suo 17KB
GDAL_CreateShape
Debug
GDAL_CreateShape.ilk 2.14MB
GDAL_CreateShape.exp 116KB
GDAL_CreateShape.pdb 1.82MB
GDAL_CreateShape.lib 195KB
GDAL_CreateShape.exe 245KB
GDAL_CreateShape.suo 14KB
ipch
gdal_createshape-c35d0b49
gdal_createshape-24313e68.ipch 25MB
GDAL_CreateShape.sln 915B
GDAL_CreateShape
Debug
cl.command.1.tlog 850B
GDAL_CreateShape.exe.intermediate.manifest 381B
rc.command.1.tlog 790B
CL.read.1.tlog 14KB
vc100.idb 339KB
link.10080-cvtres.write.1.tlog 2B
mt.read.1.tlog 526B
link.10080-cvtres.read.1.tlog 2B
GDAL_CreateShape.Build.CppClean.log 524B
link-cvtres.read.1.tlog 2B
link.read.1.tlog 4KB
rc.read.1.tlog 498B
link.10080.read.1.tlog 2B
link.write.1.tlog 1KB
CL.write.1.tlog 622B
GDAL_CreateShape.write.1.tlog 2KB
vc100.pdb 356KB
link.command.1.tlog 2KB
GDAL_CreateShape.exe.embed.manifest 406B
mt.write.1.tlog 526B
GDAL_CreateShape.lastbuildstate 94B
GDAL_CreateShape.exe.embed.manifest.res 472B
CreateShape.obj 844KB
GDAL_CreateShape.log 3KB
link.10080.write.1.tlog 2B
mt.command.1.tlog 524B
GDAL_CreateShape_manifest.rc 222B
rc.write.1.tlog 506B
link-cvtres.write.1.tlog 2B
GDAL_CreateShape.vcxproj.filters 949B
GDAL_CreateShape.vcxproj.user 143B
CreateShape.cpp 2KB
gdal19.dll 6.61MB
GDAL_CreateShape.vcxproj 4KB
GDAL_CreateShape.sdf 8.52MB
共 99 条
- 1
IvanLJF
- 粉丝: 575
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页