# OGRFeature Style C++ API

Simple feature style classes.

Typedefs

typedef enum ogr_style_type OGRSType

  OGR Style type.

Enums

enum ogr_style_type

  OGR Style type.

  Values:

  enumerator OGRSTypeUnused
  enumerator OGRSTypeString
  enumerator OGRSTypeDouble
  enumerator OGRSTypeInteger
  enumerator OGRSTypeBoolean

class OGRStyleTable
  #include <ogr_featurestyle.h>

  This class represents a style table.

  Public Functions

  OGRStyleTable()
  ~OGRStyleTable()
  GBool AddStyle(const char *pszName, const char *pszStyleString)

    Add a new style in the table.

    No comparison will be done on the Style string, only on the name.

    Parameters

      - pszName – the name the style to add.

      - pszStyleString – the style string to add.

    Returns

      TRUE on success, FALSE on error

  GBool RemoveStyle(const char *pszName)

    Remove a style in the table by its name.

    Parameters

      pszName – the name of the style to remove.

    Returns

      TRUE on success, FALSE on error

  GBool ModifyStyle(const char *pszName, const char *pszStyleString)

    Modify a style in the table by its name If the style does not exist, it will be added.

    Parameters

      - pszName – the name of the style to modify.

      - pszStyleString – the style string.

    Returns

      TRUE on success, FALSE on error

  GBool SaveStyleTable(const char *pszFilename)

    Save a style table to a file.

    Parameters

      pszFilename – the name of the file to save to.

    Returns

      TRUE on success, FALSE on error

  GBool LoadStyleTable(const char *pszFilename)

    Load a style table from a file.

    Parameters

      pszFilename – the name of the file to load from.

    Returns

      TRUE on success, FALSE on error

  const char *Find(const char *pszStyleString)

    Get a style string by name.

    Parameters

      pszName – the name of the style string to find.

    Returns

      the style string matching the name, NULL if not found or error.

  GBool IsExist(const char *pszName)

    Get the index of a style in the table by its name.

    Parameters

      pszName – the name to look for.

    Returns

      The index of the style if found, -1 if not found or error.

  const char *GetStyleName(const char *pszName)

    Get style name by style string.

    Parameters

      pszStyleString – the style string to look up.

    Returns

      the Name of the matching style string or NULL on error.

  void Print(FILE *fpOut)

    Print a style table to a FILE pointer.

    Parameters

      fpOut – the FILE pointer to print to.

  void Clear()

    Clear a style table.

  OGRStyleTable *Clone()

    Duplicate style table.

    The newly created style table is owned by the caller, and will have its own reference to the OGRStyleTable.

    Returns

      new style table, exactly matching this style table.

  void ResetStyleStringReading()

    Reset the next style pointer to 0.

  const char *GetNextStyle()

    Get the next style string from the table.

    Returns

      the next style string or NULL on error.

  const char *GetLastStyleName()

    Get the style name of the last style string fetched with OGR_STBL_GetNextStyle.

    Returns

      the Name of the last style string or NULL on error.

  Private Members

  char **m_papszStyleTable = nullptr
  CPLString osLastRequestedStyleName = {}
  int iNextStyle = 0

class OGRStyleMgr
  #include <ogr_featurestyle.h>

  This class represents a style manager.

  Public Functions

  explicit OGRStyleMgr(OGRStyleTable *poDataSetStyleTable = nullptr)

    Constructor.

    This method is the same as the C function OGR_SM_Create()

    Parameters

      poDataSetStyleTable – (currently unused, reserved for future use), pointer to OGRStyleTable. Pass NULL for now.

  ~OGRStyleMgr()

    Destructor.

    This method is the same as the C function OGR_SM_Destroy()

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

    Set a style in a feature.

    Parameters

      - poFeature – the feature object to store the style in

      - pszStyleString – the style to store

      - bNoMatching – TRUE to lookup the style in the style table and add the name to the feature

    Returns

      TRUE on success, FALSE on error.

  const char *InitFromFeature(OGRFeature*)

    Initialize style manager from the style string of a feature.

    This method is the same as the C function OGR_SM_InitFromFeature().

    Parameters

      poFeature – feature object from which to read the style.

    Returns

      a reference to the style string read from the feature, or NULL in case of error..

  GBool InitStyleString(const char *pszStyleString = nullptr)

    Initialize style manager from the style string.

    Style string can be an expanded style string (e.g. “PEN(c:#FF0000,w:5px)”), or (starting with GDAL 3.5.1), a reference to a style name starting with @ (e.g. “@my_style”) registered in the associated style table.

    This method is the same as the C function OGR_SM_InitStyleString().

    Parameters

      pszStyleString – the style string to use (can be NULL).

    Returns

      TRUE on success, FALSE on errors.

  const char *GetStyleName(const char *pszStyleString = nullptr)

    Get the name of a style from the style table.

    Parameters

      pszStyleString – the style to search for, or NULL to use the style currently stored in the manager.

    Returns

      The name if found, or NULL on error.

  const char *GetStyleByName(const char *pszStyleName)

    find a style in the current style table.

    Parameters

      pszStyleName – the name of the style to add.

    Returns

      the style string matching the name or NULL if not found or error.

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

    Add a style to the current style table.

    This method is the same as the C function OGR_SM_AddStyle().

    Parameters

      - pszStyleName – the name of the style to add.

      - pszStyleString – the style string to use, or NULL to use the style stored in the manager.

    Returns

      TRUE on success, FALSE on errors.

  const char *GetStyleString(OGRFeature* = nullptr)

    Get the style string from the style manager.

    NOTE: this method will call OGRStyleMgr::InitFromFeature() if poFeature is not NULL and replace the style string stored in the style manager

    Parameters

      poFeature – feature object from which to read the style or NULL to get the style string stored in the manager.

    Returns

      the style string stored in the feature or the style string stored in the style manager if poFeature is NULL

  GBool AddPart(OGRStyleTool*)

    Add a part (style tool) to the current style.

    This method is the same as the C function OGR_SM_AddPart().

    Parameters

      poStyleTool – the style tool defining the part to add.

    Returns

      TRUE on success, FALSE on errors.

  GBool AddPart(const char*)

    Add a part (style string) to the current style.

    Parameters

      pszPart – the style string defining the part to add.

    Returns

      TRUE on success, FALSE on errors.

  int GetPartCount(const char *pszStyleString = nullptr)

    Get the number of parts in a style.

    This method is the same as the C function OGR_SM_GetPartCount().

    Parameters

      pszStyleString – (optional) the style string on which to operate. If NULL then the current style string stored in the style manager is used.

    Returns

      the number of parts (style tools) in the style.

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

    Fetch a part (style tool) from the current style.

    This method is the same as the C function OGR_SM_GetPart().

    This method instantiates a new object that should be freed with OGR_ST_Destroy().

    Parameters

      - nPartId – the part number (0-based index).

      - pszStyleString – (optional) the style string on which to operate. If NULL then the current style string stored in the style manager is used.

    Returns

      OGRStyleTool of the requested part (style tools) or NULL on error.

  Private Members

  OGRStyleTable *m_poDataSetStyleTable = nullptr
  char *m_pszStyleString = nullptr

class OGRStyleTool
  #include <ogr_featurestyle.h>

  This class represents a style tool.

  Public Functions

  inline OGRStyleTool()
  explicit OGRStyleTool(OGRSTClassId eClassId)

    Constructor.

  virtual ~OGRStyleTool()
  OGRSTClassId GetType()

    Determine type of Style Tool.

    Returns

      the style tool type, one of OGRSTCPen (1), OGRSTCBrush (2), OGRSTCSymbol (3) or OGRSTCLabel (4). Returns OGRSTCNone (0) if the OGRStyleToolH is invalid.

  void SetUnit(OGRSTUnitId, double dfScale = 1.0)

    Set Style Tool units.

    Parameters

      - eUnit – the new unit.

      - dfGroundPaperScale – ground to paper scale factor.

  inline OGRSTUnitId GetUnit()

    Get Style Tool units.

    Returns

      the style tool units.

  virtual const char *GetStyleString() = 0

    Get the style string for this Style Tool.

    Maps to the OGRStyleTool subclasses’ GetStyleString() methods.

    Returns

      the style string for this style tool or “” if the hST is invalid.

  void SetStyleString(const char *pszStyleString)

    Undocumented.

    Parameters

      pszStyleString – undocumented.

  const char *GetStyleString(const OGRStyleParamId *pasStyleParam, OGRStyleValue *pasStyleValue, int nSize)

    Undocumented.

    Parameters

      - pasStyleParam – undocumented.

      - pasStyleValue – undocumented.

      - nSize – undocumented.

    Returns

      undocumented.

  const char *GetParamStr(const OGRStyleParamId &sStyleParam, OGRStyleValue &sStyleValue, GBool &bValueIsNull)

    Undocumented.

    Parameters

      - sStyleParam – undocumented.

      - sStyleValue – undocumented.

      - bValueIsNull – undocumented.

    Returns

      Undocumented.

  int GetParamNum(const OGRStyleParamId &sStyleParam, OGRStyleValue &sStyleValue, GBool &bValueIsNull)

    Undocumented.

    Parameters

      - sStyleParam – undocumented.

      - sStyleValue – undocumented.

      - bValueIsNull – undocumented.

    Returns

      Undocumented.

  double GetParamDbl(const OGRStyleParamId &sStyleParam, OGRStyleValue &sStyleValue, GBool &bValueIsNull)

    Undocumented.

    Parameters

      - sStyleParam – undocumented.

      - sStyleValue – undocumented.

      - bValueIsNull – undocumented.

    Returns

      Undocumented.

  void SetParamStr(const OGRStyleParamId &sStyleParam, OGRStyleValue &sStyleValue, const char *pszParamString)

    Undocumented.

    Parameters

      - sStyleParam – undocumented.

      - sStyleValue – undocumented.

      - pszParamString – undocumented.

  void SetParamNum(const OGRStyleParamId &sStyleParam, OGRStyleValue &sStyleValue, int nParam)

    Undocumented.

    Parameters

      - sStyleParam – undocumented.

      - sStyleValue – undocumented.

      - nParam – undocumented.

  void SetParamDbl(const OGRStyleParamId &sStyleParam, OGRStyleValue &sStyleValue, double dfParam)

    Undocumented.

    Parameters

      - sStyleParam – undocumented.

      - sStyleValue – undocumented.

      - dfParam – undocumented.

  Public Static Functions

  static GBool GetRGBFromString(const char *pszColor, int &nRed, int &nGreen, int &nBlue, int &nTransparence)

    Return the r,g,b,a components of a color encoded in #RRGGBB[AA] format.

    Maps to OGRStyleTool::GetRGBFromString().

    Parameters

      - pszColor – the color to parse

      - nRed – reference to an int in which the red value will be returned.

      - nGreen – reference to an int in which the green value will be returned.

      - nBlue – reference to an int in which the blue value will be returned.

      - nTransparance – reference to an int in which the (optional) alpha value will be returned.

    Returns

      TRUE if the color could be successfully parsed, or FALSE in case of errors.

  static int GetSpecificId(const char *pszId, const char *pszWanted)

    Undocumented.

    Parameters

      - pszId – Undocumented

      - pszWanted – Undocumented

    Returns

      Undocumented

  Private Functions

  virtual GBool Parse() = 0

  Private Members

  GBool m_bModified = false
  GBool m_bParsed = false
  double m_dfScale = 1.0
  OGRSTUnitId m_eUnit = OGRSTUMM
  OGRSTClassId m_eClassId = OGRSTCNone
  char *m_pszStyleString = nullptr