首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络协议 >

ogr创设shp文件失败

2013-04-20 
ogr创建shp文件失败自己写的一个新建shp的line图层,并写入数据,有问题,请高手指点贴出我的代码如下:OGRSFD

ogr创建shp文件失败
自己写的一个新建shp的line图层,并写入数据,有问题,请高手指点
贴出我的代码如下:
OGRSFDriver *p_driver_new;
OGRDataSource *p_ds_new;
OGRLayer *p_layer_new;

string str_shp_new = "F:\dianli_line.shp";
//注册OGR驱动
const char *pszDriverName = "ESRI Shapefile";
OGRRegisterAll();
p_driver_new = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName );
if( p_driver_new == NULL )
{
return false;
}
//创建文件
if (access(str_shp_new.c_str(),6) != -1)
{
remove(str_shp_new.c_str());
}
p_ds_new = p_driver_new->CreateDataSource(str_shp_new.c_str(), NULL );
if( p_ds_new == NULL )
{
return false;
}
//空间参考
OGRSpatialReference oSRS;
//oSRS.SetGeogCS( "srs_EPSG:4326",  
//"WGS 84",  
//SRS_DN_WGS84,  
//SRS_WGS84_SEMIMAJOR, SRS_WGS84_INVFLATTENING,  
//SRS_PM_GREENWICH, 0.0,  
//SRS_UA_DEGREE, 0.0174532925199433 );
oSRS.SetWellKnownGeogCS( "WGS84" );

p_layer_new = p_ds_new->CreateLayer("dianli_line", &oSRS, wkbLineString,NULL );
if( p_layer_new == NULL )
{
return false;
}

OGRLineString oLine;
oLine.addPoint(116.39,39.52);
oLine.addPoint(117.385,41.263);

OGRFeature *p_fea_new;
p_fea_new = OGRFeature::CreateFeature(p_layer_new->GetLayerDefn());
p_fea_new->SetGeometryDirectly(&oLine);

if( p_layer_new->CreateFeature(p_fea_new) != OGRERR_NONE )
{
return false;
}
//OGRFeature::DestroyFeature(p_fea_new);
//delete p_fea_new;

最后两句一运行就报错,自己注掉了。不明白哪里有问题???

程序运行,shp文件没有能创建成功
我哪里有问题,帮忙指导一下 ogr?shp layer
[解决办法]
OGRFeature *p_fea_new;

你这个都用的指针。
你得看看OGRLineString的定义。

话说ogr还是挺好用的。

热点排行