资源简介
GDAL进行shapefile数据栅格化,将shapefile中第一个多边形读取出来栅格化,根据“ID”字段
代码片段和文件信息
#include
#include “gdal_priv.h“
#include “gdal_alg.h“
#include “ogrsf_frmts.h“
#include “ogr_core.h“
using namespace std;
int main()
{
GDALAllRegister();
OGRRegisterAll();
OGRDataSource *poDS;
char* shpName;
shpName = “..\\testRes\\SW_UTM.shp“;
poDS = OGRSFDriverRegistrar::Open(shpName FALSE );
if( poDS == NULL )
{
cout<<“Open “< return 0;
}
OGRlayer* polayer;
polayer = poDS->Getlayer(0);
OGRFeature * poFeature = polayer->GetFeature(0);
OGRGeometry * poGeometry = poFeature->GetGeometryRef();
const char * pszOutFileName = “.\\src2_out.tif“;
char * pszProjection;
OGRSpatialReference * poSRS = polayer->GetSpatialRef();
OGREnvelope psExtent;
poGeometry->getEnvelope(&psExtent);
int m_nImageWidth = (int)((psExtent.MaxX - psExtent.MinX)/500.0+0.5);
int m_nImageHeight =(int)((psExtent.MaxY - psExtent.MinY)/500.0+0.5);
if ( !poSRS )
{
cout<<“Can‘t open the “< m_nImageWidth = psExtent.MaxX;
m_nImageHeight = psExtent.MaxY;
}
else
{
poSRS->exportToWkt( &pszProjection );
}
const char *pszFormat = “GTiff“;
GDALDriver *poDriver;
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
GDALDataset *poNewDS = poDriver->Create( pszOutFileName m_nImageWidthm_nImageHeight1 GDT_Byte NULL );
if ( !poSRS )
{
double adfGeoTransform[6];
adfGeoTransform[0] = psExtent.MinX;
adfGeoTransform[1] = 500.0;
adfGeoTransform[2] = 0;
adfGeoTransform[3] = psExtent.MaxY;
adfGeoTransform[4] = 0;
adfGeoTransform[5] = -500.0;
GDALSetGeoTransform( poNewDS adfGeoTransform );
OGRSpatialReference * poOGRSR = NULL;
poOGRSR->SetUTM(50);
poSRS->exportToWkt(&pszProjection);
poNewDS->SetProjection(pszProjection);
- 上一篇:获取系统安装软件(vc++源码)
- 下一篇:二项堆Binomial Heap
相关资源
- VC读取shapefile文件源码,处理点线面
- 基于GDAL VC6.0的遥感影像K均值分类程序
- GDAL2.1.0 X86和X64编译好的库 C++
- gdal-1.9.2基于vs2010已编译好的c++
- 已编译的GDAL gdal111
- GDAL-2.3.3-cp35-cp35m-win_amd64.whl
- GDAL图片裁剪程序
- 编译好的GDAL库,含GEOS和PROJ,以及C
- GDAL 2.4.4 and MapServer 7.4.3 编译库 vs201
- GDAL3编译版本c++版本的编译.rar
- GDAL遥感影像处理
- c++GDAL读取显示shp数据
- C++ 坐标点数据转shp矢量数据
- ShpView ---- Arcgis Shapefile 文件的浏览、
- GDAL读取矢量数据的点坐标集.txt
- GDAL1111源码
- c++解析并显示shape(.shp)文件源码
评论
共有 条评论