OGRGeomFieldDefn Class “ogrsf_frmts.h”
OGRGeomFieldDefn是OGR库中的一个类,用于表示OGR图层中的空间几何图形字段的定义
每个OGRGeomFieldDefn对象表示一个空间几何图形字段的定义,它包括字段名、几何类型、坐标系等信息。在OGR中,一个图层可以有多个属性字段和一个空间几何图形字段,每个空间几何图形字段对应一个OGRGeomFieldDefn对象
几何字段描述如下:
一个名字。参见 SetName() / GetNameRef()
类型: wkbPoint, wkbLineString, ...参见 SetType() / GetType()
空间参考系统(可选)。参见 SetSpatialRef() / GetSpatialRef()
一个非空约束(可选)。请参阅 SetNullable() / IsNullable()
一个布尔值,用于指示在检索要素时是否应忽略它。参见 SetIgnored() / IsIgnored()
OGRGeomFieldDefn
OGRGeomFieldDefn(const 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 SetName(const 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 SetType(OGRwkbGeometryType 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 SetSpatialRef(const 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");
}