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

OGRRangeFieldDomain Class        “ogr_core.h”

OGRRangeFieldDomain是OGRFieldDomain的子类,表示一个数值范围。该类的实例由最小值和最大值组成,可用于定义数值型字段的范围

OGRRangeFieldDomain

OGRRangeFieldDomain(const std::string &osName, const std::string &osDescription, OGRFieldType eFieldType, OGRFieldSubType eFieldSubType , const OGRField &sMin, bool bMinIsInclusive, const OGRField &sMax, bool bMaxIsInclusive)                与 C 函数 OGR_RangeFldDomain_Create() 相同

构造函数

参数:

  • osName – 域名。

  • osDescription – 域描述。

  • eFieldType – 字段类型。OFTInteger,OFTInteger64,OFTReal或OFTDateTime中的一个

  • eFieldSubType – 字段子类型。

  • sMin – 最小值。必须读取 OGRField枚举中的哪个成员取决于字段类型。如果未设置最小值(并非所有后端都支持),则使用 OGR_RawField_SetUnset() 初始化值。

  • bMinIsInclusive – 最小值是否包含在范围内。

  • sMax – 最大值。必须读取 OGRField枚举中的哪个成员取决于字段类型。如果未设置最大值(并非所有后端都支持),则使用 OGR_RawField_SetUnset() 初始化该值。

  • bMaxIsInclusive – 最大值是否包含在范围内

OGRField sMin, sMax;
sMin.Double = 1.0;
sMax.Double = 10.0;
OGRRangeFieldDomain* poRangeDomain = new OGRRangeFieldDomain("MyDomain", "My domain description",
    OFTReal, OFSTNone, sMin, true, sMax, false);

OGR_RawField_SetUnset() 是 OGR 库中的一个函数,用于将一个未设置过的字段(如整数类型的字段)设置为其类型的默认值(通常为0)。在 OGRRangeFieldDomain 中,如果用户未指定最大值,则会使用 OGR_RawField_SetUnset() 函数将其初始化为默认值

Clone

inline virtual OGRRangeFieldDomain *Clone() const override

克隆                返回克隆的对象,或在出现错误时返回 nullptr

GetMin

inline const OGRField &GetMin(bool &bIsInclusiveOut) const         与 C 函数 OGR_RangeFldDomain_GetMin() 相同

获取最小值

参数:

bIsInclusiveOut – 如果最小值包含在范围内,则设置为 true

GetMax

inline const OGRField &GetMax(bool & bIsInclusiveOut) const         与 C 函数 OGR_RangeFldDomain_GetMax() 相同

获取最大值

参数:

bIsInclusiveOut – 如果最大值包含在范围内,则设置为 true

bool bMaxIsInclusive;
const OGRField& sMax = rangeDomain->GetMax(bMaxIsInclusive);
if (bMaxIsInclusive) {
    cout << "Maximum value is inclusive: " << sMax.Double() << endl;
} else {
    cout << "Maximum value is exclusive: " << sMax.Double() << endl;
}
OGRField sMin, sMax;
    sMin.SetDouble(-10.0);
    sMax.SetDouble(10.0);

    OGRRangeFieldDomain oDomain("myDomain", "description", OFTReal, OFSTNone, sMin, true, sMax, true);

bool bMaxIsInclusive, bMinIsInclusive;
    const OGRField& minField = oDomain.GetMin(bMinIsInclusive);
    const OGRField& maxField = oDomain.GetMax(bMaxIsInclusive);

    double dMinValue = minField.GetDouble();
    double dMaxValue = maxField.GetDouble();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

场主不吃鍋巴

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

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

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

打赏作者

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

抵扣说明:

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

余额充值