GDAL官网 OGR API Tutorial学习笔记三:Writting To OGR(2)

//OGR 1.11版本之后,一些geometry fields可以和a feature关联在一起

//这只限于几种文件格式,例如PostGIS

//要创建这样的数据源datasources,首先创建geometry fields,

//同时控件参考系统spatial reference system objects可以和每一个图形字段关联起来

 OGRGeomFieldDefn oPointField( "PointField", wkbPoint ); 

OGRSpatialReference *poSRS = new OGRSpatialReference();

poSRS->importFromEPSG( 4326 );

oPointField.SetSpatialRef( poSRS );

poSRS->Release();

if( poLayer->CreateGeomField( &oPointField ) != OGRERR_NONE )

{

printf( "Creating field PointField failed.\n" );

exit( 1 );

}

OGRGeomFieldDefn oFieldPoint2( "PointField2", wkbPoint );

poSRS = new OGRSpatialReference();

poSRS->importFromEPSG( 32631 );

oPointField2.SetSpatialRef( poSRS );

poSRS->Release();

if( poLayer->CreateGeomField( &oPointField2 ) != OGRERR_NONE )

{

printf( "Creating field PointField2 failed.\n" );

exit( 1 );

}
//要将a feature 写进磁盘,首先创建本地OGRFeature,用layer关联的OGRFeatureDefn构造OGRFeature,

//为其设置属性,添加geometries,再写入layer

OGRFeature *poFeature;

OGRGeometry *poGeometry;

char* pszWKT;

poFeature = OGRFeature::CreateFeature( poLayer->GetLayerDefn() );

pszWKT = ( char* ) "POINT(2 49)";

OGRGeometryFactory::createFromWkt( &pszWKT, NULL, &poGeometry );

poFeature->SetGeomFieldDirectly( "PointField", poGeometry );

pszWKT = (char*) "POINT(500000  4500000)";

OGRGeometryFactory::createFromWkt( &pszWKT, NULL, &poGeometry );

poFeature->SetGeomFieldDirectly( "PointField2", poGeometry );

if( poLayer->CreateFeature(poFeature) != OGRERR_NONE )

{

printf( "Failed to create feature.\n" );

exit( 1 );

}

OGRFeature::DestroyFeature( poFeature );





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值