GDAL C++ API 学习之路 (2)OGRFeature Style 样式管理器 OGRStyleMgr

OGRStyleMgr是一个用于管理和操作OGR样式的类,提供添加、修改、删除和查找样式的功能。它帮助用户在OGRFeature对象中设置和初始化样式字符串,并可以从样式表中获取样式名称和样式。此外,还支持通过AddStyle方法向样式表添加自定义样式。
摘要由CSDN通过智能技术生成

Class OGRStyleMgr        #include <ogr_featurestyle.h>

此类表示样式管理器

OGRStyleMgr 是一个用于管理和操作 OGR 样式的类。它提供了一种方便的方式来创建、修改和查找 OGR 样式。

它提供了一系列方法来添加、修改、删除和查找样式。它可以帮助用户有效地管理样式,并进行样式的选择和应用

Public Functions:

explicit OGRStyleMgr(OGRStyleTable *poDataSetStyleTable = nullptr)        构造函数

~OGRStyleMgr() 析构函数

SetFeatureStyleString

GBool SetFeatureStyleString(OGRFeature*, const char *pszStyleString = nullptrGBool bNoMatching = FALSE)

在要素中设置样式

参数:

  • poFeature -- 用于存储样式的特征对象

  • pszStyleString -- 要存储的样式

  • bNoMatch -- TRUE 表示在样式表中查找样式并将名称添加到要素中

返回: 成功时为TRUE,错误时为FALSE

// 创建一个 OGRFeature 对象
OGRFeature* feature = new OGRFeature(layerDefn);
​
// 创建一个 OGRStyleMgr 对象
OGRStyleMgr* styleMgr = new OGRStyleMgr();

// 设置要素的样式字符串
const char* styleString = "PEN(c:#FF0000,w:2px)";
GBool success = styleMgr->SetFeatureStyleString(feature, styleString);

InitFromFeature

const char *InitFromFeatureOGRFeature*)

从要素的样式字符串初始化样式管理器

参数:

poFeature -- 要从中读取样式的特征对象。

返回: 对从要素读取的样式字符串的引用,或在出现错误时为 NULL

// 创建一个 OGRFeature 对象
OGRFeature* feature = new OGRFeature(layerDefn);

// 创建一个 OGRStyleMgr 对象
OGRStyleMgr* styleMgr = new OGRStyleMgr();

// 从要素中初始化样式
const char* styleString = styleMgr->InitFromFeature(feature);

InitStyleString

GBool InitStyleStringconst char *pszStyleString = nullptr)

从样式字符串初始化样式管理器

参数:

pszStyleString -- 要使用的样式字符串(可以是 NULL)

返回:成功时为TRUE,错误时为FALSE

// 创建一个 OGRStyleMgr 对象
OGRStyleMgr* styleMgr = new OGRStyleMgr();

// 初始化样式字符串
const char* styleString = "PEN(c:#FF0000,w:2px);BRUSH(fc:#FFFF00)";
GBool success = styleMgr->InitStyleString(styleString);

GetStyleName

const char *GetStyleNameconst char *pszStyleString = nullptr)

从样式表中获取样式的名称

参数:

pszStyleString -- 要搜索的样式,或 NULL 以使用当前存储在管理器中的样式。

返回: 名称(如果找到)或出错时为 NULL

// 创建一个 OGRStyleMgr 对象
OGRStyleMgr* styleMgr = new OGRStyleMgr();

// 初始化样式字符串
const char* styleString = "PEN(c:#FF0000,w:2px)";
GBool success = styleMgr->InitStyleString(styleString);

// 获取样式名称
const char* styleName = styleMgr->GetStyleName(styleString);

GetStyleByName

const char *GetStyleByNameconst char *pszStyleName)

参数:

pszStyleName -- 要添加的样式的名称。

返回: 与名称匹配的样式字符串或 NULL(如果未找到或错误)

// 创建一个 OGRStyleMgr 对象
OGRStyleMgr* styleMgr = new OGRStyleMgr();

// 添加样式到样式管理器
const char* styleName = "Style1";
const char* styleString = "PEN(c:#FF0000,w:2px)";
GBool success = styleMgr->AddStyle(styleName, styleString);

// 根据样式名称获取样式字符串
const char* retrievedStyleString = styleMgr->GetStyleByName(styleName);

AddStyle

GBool AddStyle(const char *pszStyleName, const char *pszStyleString = nullptr)

向当前样式表添加样式

参数:

  • pszStyleName -- 要添加的样式的名称。

  • pszStyleString -- 要使用的样式字符串,或 NULL 以使用管理器中存储的样式。

返回: 成功时为TRUE,错误时为FALSE

// 创建一个 OGRStyleMgr 对象
OGRStyleMgr* styleMgr = new OGRStyleMgr();

// 添加样式到样式管理器
const char* styleName = "Style1";
const char* styleString = "PEN(c:#FF0000,w:2px)";
GBool success = styleMgr->AddStyle(styleName, styleString);

GetStyleString

const char *GetStyleStringOGRFeature* = nullptr)

从样式管理器获取样式字符串

参数:

poFeature -- 从中读取样式的特征对象,或从中读取样式或 NULL 以获取存储在管理器中的样式字符串。

返回: 存储在要素中的样式字符串或存储在样式管理器中的样式字符串(如果 poFeature 为 NULL)

// 创建一个 OGRStyleMgr 对象
OGRStyleMgr* styleMgr = new OGRStyleMgr();

// 创建一个 OGRFeature 对象
OGRFeature* feature = new OGRFeature();

// 设置要素对象的几何图形和属性值...

// 获取要素对象的样式字符串
const char* styleString = styleMgr->GetStyleString(feature);

 

AddPart

GBool AddPartOGRStyleTool*)

参数:

poStyleTool -- 定义要添加的部件的样式工具。

返回: 成功时为TRUE,错误时为FALSE

关于部件的样式工具OGRStyleTool类,在第三章有讲解:

传送门

// 创建一个 OGRStyle 对象
OGRStyle* style = new OGRStyle();

// 创建一个 OGRStyleTool 对象
OGRStyleTool* styleTool = new OGRStyleTool();
styleTool->SetSymbol("SYMBOL(d:0x0033FF)");

// 添加样式工具到样式对象
GBool success = style->AddPart(styleTool);

AddPart

GBool AddPartconst char*)

将部件(样式字符串)添加到当前样式

参数:

pszPart -- 定义要添加的部分的样式字符串。

返回:成功时为TRUE,错误时为FALSE

// 创建一个 OGRStyle 对象
OGRStyle* style = new OGRStyle();

// 添加样式工具到样式对象
const char* styleString = "SYMBOL(d:0x0033FF)";
GBool success = style->AddPart(styleString);

GetPartCount

int GetPartCountconst char *pszStyleString = nullptr)

获取样式中的零件数

参数:

pszStyleString -- (可选)要操作的样式字符串。如果为 NULL,则使用存储在样式管理器中的当前样式字符串。

返回: 样式中的零件(样式工具)数

// 创建一个 OGRStyle 对象
OGRStyle* style = new OGRStyle();

// 添加样式工具到样式对象
const char* styleString = "SYMBOL(d:0x0033FF);BRUSH(fc:#FF0000)";
style->AddPart(styleString);

// 获取样式字符串中的样式工具数量
int partCount = style->GetPartCount();

GetPart

OGRStyleTool *GetPart(int hPartId, const char *pszStyleString = nullptr)

从当前样式中获取零件(样式工具)

参数:

  • nPartId -- 部件号(从 0 开始的索引)。

  • pszStyleString -- (可选)要操作的样式字符串。如果为 NULL,则使用存储在样式管理器中的当前样式字符串。

返回: 所请求零件的OGRStyle工具(样式工具)或错误时的NULL

// 创建一个 OGRStyle 对象
OGRStyle* style = new OGRStyle();

// 添加样式工具到样式对象
const char* styleString = "SYMBOL(d:0x0033FF);BRUSH(fc:#FF0000)";
style->AddPart(styleString);

// 获取样式工具对象
int partId = 0; // 样式工具的索引
OGRStyleTool* styleTool = style->GetPart(partId);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

场主不吃鍋巴

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

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

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

打赏作者

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

抵扣说明:

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

余额充值