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文件吗,是可以的.这里 ...
随机推荐
- JS 复制文本兼容移动端 iOS & android
有几个需要注意的地方. 首先文本只有选中才可以复制,所以简单的做法就是创建一个隐藏的 input,然后绑定需要复制的文本. 另外如果将 input 设置为 `type="hidden&quo ...
- 【t092】迷之阶梯
Time Limit: 1 second Memory Limit: 128 MB [问题描述] 在经过地球防卫小队的数学家连续多日的工作之后,外星人发的密码终于得以破解.它告诉我们在地球某一处的古老 ...
- JUnit4---Hamcrest匹配器常用方法总结
一.Hamcrest是什么? Hamcrest is a library of matchers, which can be combined in to create flexible expres ...
- 用C++获取屏幕上某点的颜色
假定坐标点 x=50,y=50. 输出 RGB 用 16 进制数.Afxwin.h 你建项目时可得.#include <Afxwin.h>#include <Windows.h> ...
- webpack+babel+react+antd技术栈的基础配置
webpack+babel+react+antd技术栈的基础配置 前段时间使用webpack+babel+react+antd做了一套后台管理系统,刚开始被一大堆的新知识压的喘不过气来,压力挺大的.还 ...
- 【矩阵乘法优化dp】[Codeforces 621E] Wet Shark and Blocks
http://codeforces.com/problemset/problem/621/E E. Wet Shark and Blocks time limit per test 2 seconds ...
- mangoDB 储存 id为objectid
- Dart常见类型转换 Int String Double
int -> string age.toString() string -> int int.parse('100'); String -> double var onePointO ...
- CString 的成员函数详解
CSTRING的成员函数详解 typedef ATL::CStringT< TCHAR, StrTraitMFC_DLL< TCHAR > > CString;CStrin ...
- CUBA 框架2019年回顾
对于 CUBA 框架,2019年最重要的事件应该是 CUBA 7 的发布, 这是 CUBA 框架的一次巨大进化,CUBA 7 引入了一系列全新的 UI 和更灵活的数据访问机制,并且发布了基于 Inte ...