GDAL OGR C++ API 学习之路 OGRGeomFieldDefn篇

OGRGeomFieldDefn Class        “ogrsf_frmts.h”

OGRGeomFieldDefn是OGR库中的一个类,用于表示OGR图层中的空间几何图形字段的定义

每个OGRGeomFieldDefn对象表示一个空间几何图形字段的定义,它包括字段名、几何类型、坐标系等信息。在OGR中,一个图层可以有多个属性字段和一个空间几何图形字段,每个空间几何图形字段对应一个OGRGeomFieldDefn对象

几何字段描述如下:

OGRGeomFieldDefn

OGRGeomFieldDefnconst char *pszNameIn, OGRwkbGeometryType eGeomTypeIn) 

构造函数

参数:

  • pszNameIn – 新字段的名称。

  • eGeomTypeIn – 新字段的类型。

OGRGeomFieldDefn geomField("geometry", wkbPoint);

OGRwkbGeometryType

  • wkbUnknown:未知几何类型
  • wkbPoint:点
  • wkbLineString:线
  • wkbPolygon:面
  • wkbMultiPoint:多点
  • wkbMultiLineString:多线
  • wkbMultiPolygon:多面
  • wkbGeometryCollection:几何集合
  • wkbNone:无几何类型

OGRGeomFieldDefn

explicit OGRGeomFieldDefn(const OGRGeomFieldDefn )

构造函数

通过克隆现有几何字段定义进行创建

参数:

poPrototype – 要克隆的几何字段定义

OGRGeomFieldDefn existingGeomField("my_geom", OGRwkbGeometryType::wkbPoint);
OGRGeomFieldDefn newGeomField(&existingGeomField);

SetName

void SetNameconst char*)        此方法与 C 函数 OGR_GFld_SetName() 相同

重置此字段的名称

参数:

pszNameIn – 要应用的新名称

GetNameRef

inline const char *GetNameRef() const         此方法与 C 函数 OGR_GFld_GetNameRef() 相同

获取此字段的名称

返回: 指向不应释放或修改的内部名称字符串的指针

// 创建一个新的 OGRGeomFieldDefn 对象
OGRGeomFieldDefn geomField("new_field", OGRwkbGeometryType::wkbPoint);

// 设置字段名称
geomField.SetName("new_name");

// 获取字段名称
const char* name = geomField.GetNameRef();

GetType

inline OGRwkbGeometryType GetType() const        此方法与 C 函数 OGR_GFld_GetType() 相同

获取此字段的几何类型

返回:字段几何类型

SetType

void SetTypeOGRwkbGeometryType eTypeIn)        此方法与 C 函数 OGR_GFld_SetType() 相同

绝对不能对已经是OGRFeatureDefn一部分的OGRGeomFieldDefn执行此操作

设置此字段的几何类型

参数:

eTypeIn – 新的字段几何类型

// 创建一个新的 OGRGeomFieldDefn
OGRGeomFieldDefn geomField("my_geom_field", wkbPoint);

// 获取 OGRGeomFieldDefn 的类型
OGRwkbGeometryType geomType = geomField.GetType();

// 设置 OGRGeomFieldDefn 的类型为 wkbPolygon
geomField.SetType(wkbPolygon);

GetSpatialRef

virtual const OGRSpatialReference *GetSpatialRef() const        此方法与 C 函数 OGR_GFld_GetSpatialRef() 相同

获取此字段的空间参考系统

返回: 字段的空间参考系统

SetSpatialRef

void SetSpatialRefconst OGRSpatialReference *poSRSIn)        此方法与 C 函数 OGR_GFld_SetSpatialRef() 相同

设置此字段的空间参考        

参数:

poSRSIn – 要应用的新空间参考

OGRGeomFieldDefn::SetSpatialRef(const OGRSpatialReference *poSRSIn)

const OGRSpatialReference* OGRGeomFieldDefn::GetSpatialRef() const

IsIgnored

inline int IsIgnored() const

SetIgnored

inline void SetIgnored(int bIgnoreIn)

IsNullable

inline int IsNullable() const

SetNullable

inline void SetNullable(int bNullableIn)

四个方法与OGRFieldDefn一样:https://mp.csdn.net/mp_blog/creation/editor/130447604

IsSame

int IsSame(const OGRGeomFieldDefn*) const

测试几何字段定义是否与其他几何字段定义相同

参数:

poOtherFieldDefn – 要比较的另一个字段定义。

返回: 如果几何字段定义与其他几何字段定义相同,则为 TRUE

此方法用于比较两个OGRGeomFieldDefn对象是否相同,即它们的名称、类型、坐标参考系是否相同。具体来说,该方法会依次比较两个对象的名称、几何类型、坐标参考系(如果有的话),如果这些属性都相同,则返回1,否则返回0

int result = existingGeomFieldDefn.IsSame(&newGeomFieldDefn);
if(result == 1) {
    printf("The two OGRGeomFieldDefn objects are the same.\n");
} else {
    printf("The two OGRGeomFieldDefn objects are different.\n");
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

场主不吃鍋巴

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值