当前位置: 代码迷 >> GIS >> ogr创办shp文件失败
  详细解决方案

ogr创办shp文件失败

热度:165   发布时间:2016-05-05 06:14:16.0
ogr创建shp文件失败
贴出我的代码如下:
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文件没有能创建成功
我哪里有问题,帮忙指导一下 
------解决方案--------------------
路径里面的斜杠写成两个,试试
string str_shp_new = "F:\\dianli_line.shp";
------解决方案--------------------
参考:

    OGR API 使用向导
  相关解决方案