GDAl C++ 创建Shp
用于GDAL,C++开发环境测试。
#include <iostream>
#include "gdal_priv.h"
#include "ogrsf_frmts.h"
#include "ogr_geometry.h"
#pragma comment (lib,"C:\\warmerda\\bld\\lib\\gdal_i.lib")
using namespace std; void CreateShapeFile()
{
const char *pszDriverName = "ESRI Shapefile";
OGRSFDriver *poDriver; OGRRegisterAll(); poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(
pszDriverName );
if( poDriver == NULL )
{
printf( "%s driver not available.\n", pszDriverName );
exit( );
} OGRDataSource *poDS; poDS = poDriver->CreateDataSource( "point_out.shp", NULL );
if( poDS == NULL )
{
printf( "Creation of output file failed.\n" );
exit( );
} OGRLayer *poLayer; poLayer = poDS->CreateLayer( "point_out", NULL, wkbPoint, NULL );
if( poLayer == NULL )
{
printf( "Layer creation failed.\n" );
exit( );
} OGRFieldDefn oField( "Name", OFTString ); oField.SetWidth(); if( poLayer->CreateField( &oField ) != OGRERR_NONE )
{
printf( "Creating Name field failed.\n" );
exit( );
} double x, y;
char szName[]; while( !feof(stdin)
&& fscanf( stdin, "%lf,%lf,%32s", &x, &y, szName ) == )
{
OGRFeature *poFeature; poFeature = new OGRFeature( poLayer->GetLayerDefn() );
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( );
}
OGRFeature::DestroyFeature( poFeature );
}
OGRDataSource::DestroyDataSource( poDS ); }
int main()
{
//CreateShapeFile();
//cout<<"创建成功"<<endl;
const char *pszDriverName="ESRI Shapefile";
OGRSFDriver *poDriver;
OGRRegisterAll();
poDriver=OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName);
if(poDriver==NULL)
{
cout<<"注册失败"<<endl;
}
OGRDataSource *poDS;
poDS=poDriver->CreateDataSource("point_out.shp",NULL);
if(poDS==NULL)
{
cout<<"创建驱动失败!"<<endl;
}
OGRLayer *poLayer;
poLayer=poDS->CreateLayer("point_out",NULL,wkbPoint,NULL);
if(poLayer==NULL)
{
cout<<"创建图层失败"<<endl;
}
OGRFieldDefn oField("Name",OFTString);
oField.SetWidth();
if(poLayer->CreateField(&oField)!=OGRERR_NONE)
{
cout<<"添加字段失败!"<<endl;
}
//下面从stdin中循环读取 “x,y,name”格式的点信息。
double x=,y=;
char szName[];
for(int a=;a!=;++a)
{
x+=a;
y+=a;
OGRFeature *poFeature;
poFeature=new OGRFeature(poLayer->GetLayerDefn());
poFeature->SetField("Name",szName);
OGRPoint pt;
pt.setX(x);
pt.setY(y);
poFeature->SetGeometry(&pt);
if(poLayer->CreateFeature(poFeature)!=OGRERR_NONE)
{
cout<<"创建要素失败"<<endl;
}
//OGRFeature::DestroyFeature(*poFeature);//创建一个feature.OGRLayer::CreateFeature() 只是重新复制了一个feature,因此操作完成后需要清除feature对象
}
//最后释放datasoure资源,刷新所有写的操作
OGRDataSource::DestroyDataSource(poDS);
cout<<"文件创建成功!"<<endl;
return ;
}
GDAl C++ 创建Shp的更多相关文章
- [转] arcgis Engine创建shp图层
小生 原文 arcgis Engine创建shp图层 以创建点图层为例.首先要得到保存文件的地址. SaveFileDialog saveFileDialog = new SaveFileDialog ...
- AE CreateFeatureClass 创建shp. 删除shp. 向shp中添加要素
/// <summary> /// 创建多边形shp /// </summary> /// <param name="pPolygon">< ...
- GDAL C#读取shp中文属性值乱码问题
GDAL的C#版本读取shp中,如果属性值中含有中文,读出来有可能是乱码的问题,根据SWIG生成的C#代码调试发现问题所在,在Ogr.cs文件中有这么一个函数,代码如下: internal stati ...
- arcEngine开发之根据点坐标创建Shp图层
思路 根据点坐标创建Shapefile文件大致思路是这样的: (1)创建表的工作空间,通过 IField.IFieldsEdit.IField 等接口创建属性字段,添加到要素集中. (2)根据获取点的 ...
- GDAL显示线性shp文件
http://pan.baidu.com/s/1qWIDphU (工程文件在vs2008中编写) 1.使用到的技术 GDAL:读取矢量数据 GDI: 绘制矢量数据 2.详细解释 GDI绘图: ...
- 【gdal】创建GeoTiff栅格数据
1 //定义转换参数 2 private readonly double[] d_transform = { 69.999999999999972, 0.01, 0.0, 44.99999999999 ...
- 结合C++和GDAL实现shapefile(shp)文件的创建和写入
工具:vs2012+GDAL 2.0 包含头文件: #include "ogrsf_frmts.h" int main() { const char *pszDriverName ...
- C#、C++用GDAL读shp文件(转载)
C#.C++用GDAL读shp文件 C#用GDAL读shp文件 (2012-08-14 17:09:45) 标签: 杂谈 分类: c#方面的总结 1.目前使用开发环境为VS2008+GDAL1.81 ...
- Android GIS开发系列-- 入门季(13)Gdal简单写个shp文件
Gdal是用来读写栅格与矢量数据的,在Gdal官网,可以下载相关的资源进行平台的编译.其实Arcgis底层也是用Gdal来读取shp文件的,那在Android中可以直接读写shp文件吗,是可以的.这里 ...
随机推荐
- jQuery中动态创建、添加元素的方法总结
<input type="button" value="创建元素" id="btn"> <div id="box ...
- Laravel修改配置后一定要清理缓存 "php artisan config:clear"!
用laravel踩到一个大坑... 需要使用laravel的队列(queue)功能, 设置 ".env"配置文件 QUEUE_DRIVER=database 按照文档,建立jobs ...
- 日历价差(calendar spread)
日历价差(calendar spread) 是指投资者买进到期日较远的期权 (简称远期期权),同时又卖出相同行权价格.相同数量但到期日较近的期权(简称近期期权),赚取两个不同期权隐含波动率的差价或者其 ...
- 小程序与HTML5的区别
小程序与传统HTML5还是有明显的区别,主要区别在于: 开发工具不同: 区别于H5的开发工具+浏览器Device Mode预览的模式,小程序的开发基于自己的开发者工具,可以实现同步本地文件+开发调试+ ...
- 2018-9-1-win2d-画出好看的图形
title author date CreateTime categories win2d 画出好看的图形 lindexi 2018-09-01 16:25:40 +0800 2018-2-13 17 ...
- zoj 4124 "Median" (思维?假的图论?)
传送门 来源:2019 年“浪潮杯”第十届山东省 ACM 省赛 题意: 对于一个包含n个数的(n为奇数)序列val[ ],排序后的 val[ (n+1) / 2 ] 定义为 median: 有 n 个 ...
- ioctl 命令的实现
ioctl 的 scull 实现只传递设备的配置参数, 并且象下面这样容易: switch(cmd) { case SCULL_IOCRESET: scull_quantum = SCULL_QUAN ...
- CF1088F Ehab and a weird weight formula
CF1088F Ehab and a weird weight formula 推性质猜结论题 第一步转化,考虑把点的贡献加到边里: $con=\sum (log_2(dis(a_u,a_b))\ti ...
- Jenkins+Git+Gitlab+Ansible实现持续集成自动化部署静态网站(一)
在之前已经写了关于Git,Gitlab以及Ansible的两篇博客<Git+Gitlab+Ansible剧本实现一键部署Nginx--技术流ken>,<Git+Gitlab+Ansi ...
- If条件语句实战
1.If条件判断语句 通常以if开头,fi结尾.也可加入else或者elif进行多条件的判断,if表达式如下: if (表达式) 语句1 else 语句2 fi 2.If常见判断逻辑运算符详解: -f ...