📄 ogr_feature_style.html
字号:
<TD><B>Priority Level</B> - Numeric value defining the order in which styleparts should be drawn. Lower priority style parts are drawn first, andhigher priority ones are drawn on top.<BR> If priority level is unspecified, the default is 1.</TD> </TR></TABLE><H2>2.7 Styles Table Format</H2>For file formats that support tables of styles, then the predefined styleswould be stored in that format.<P>For file formats that do not support tables of styles, then we mightwant to store them in a text file with a .ofs (OGR Feature Styles) extension and the same basename as the dataset.This would apply to formats like ArcView Shapes.<P>Here is what one of those .OFS files could look like:<PRE> OFS-Version: 1.0 StyleField: "style" DefaultStyle: PEN(C:#000000FF) road: PEN(c:#FF0000,w:5px) lake: BRUSH(fc:#0000FF);LINE(c:#000000) campsite: SYMBOL(c:#00FF00,id:"points.sym-45,ogr-sym-7") label: LABEL(f:"Times New Roman",s:12pt,t:{text_string})</PRE><P><P>The first line is a signature with a version number. Must be present<P>The second line (StyleField: "style") is the name of the attribute field in which the Feature Style String is stored for each object in the corresponding layer. This is optional, if not set, then the objects in the layer will all share the same style defined in DefaultStyle.<P>The third line (DefaultStyle:...) defines the default style that applies by default to all objects that have no explicit style.<P>Then the list of style definitions follow.<P> <H2>2.8 Suggestions, possible extensions</H2><P><B>2.8.1 Gloal list of ids for pen, brush, and symbol ids</B></P><P>There have been discussions about defining a global list of pen, brush, and symbol ids together with a table containing the definition of each code. This would work similarily to the EPSG projection codes, where the table is updated when new codes are added. This would have had some advantages, mainly to provide a common set of codes to replace the vendor-dependent pen, brush and symbol ids. However on the other hand, this mechanism would be redundent with the current approach which is to use a feature style definition language.</P><P><B>2.8.2 Use of custom brushes in pen definitions</B></P><P>In some cases one might want a pen's pattern to be a brush. To achieve this, a PEN() definition would have to contain a BRUSH() definition (e.g. PEN(c:"#FF00FFFF",BRUSH(id:"ogr-brush-4")) or PEN(c:"#FF00FFFF",pen-brush,id:"ogr-brush-4") or ???) but this is currently impossible with the current specs.<P>Since there is no current need for custom brush patterns in pen (no file formats that we know of support that), we won't include it now but may do it later. In the meantime, one can use the "gp" (geometric pattern) pen parameter to allow specifying one of the OGR brushes as a pen brush pattern.<P> <P><HR WIDTH=50%><H2>3. OGR Support Classes</H2>The complete set of classes/API functions is still to be determined.<P>Here are some rough ideas:<UL><LI>Add a 'char *pszStyleString;' member to the OGRFeature, together with OGRFeature::GetStyleString()and SetStyleString() methods.</LI><LI>Add a OGRStyleTable in the Dataset and in the Layer, The both areusing StringList to store the StyleTable, ex of a entry "@name, "PEN(color:#122334)"</LI><LI>Add a char **GetStyleTable() and GBool SetStyleTable(char **) in Datasetand in Layer</LI><LI>The OGRStyle class knows how to parse a style string,</LI></UL><PRE> typedef enum ogr_style_tool_class_id { OGRSTCNone, OGRSTCPen, OGRSTCBrush, OGRSTCSymbol, OGRSTCLabel } OGRSTClassId; typedef enum ogr_style_tool_units_id { OGRSTUGround, OGRSTUPixel, OGRSTUPoints, OGRSTUMM, OGRSTUCM, OGRSTUInches } OGRSTUnitId; typedef enum ogr_style_tool_param_pen_id { OGRSTPenColor = 0, OGRSTPenWidth, OGRSTPenPattern, OGRSTPenId, OGRSTPenPerOffset, OGRSTPenCap, OGRSTPenJoin, OGRSTPenPriority, OGRSTPenLast } OGRSTPenParam; typedef enum ogr_style_tool_param_brush_id { OGRSTBrushFColor = 0, OGRSTBrushBColor, OGRSTBrushId, OGRSTBrushAngle, OGRSTBrushSize, OGRSTBrushDx, OGRSTBrushDy, OGRSTBrushPriority, OGRSTBrushLast } OGRSTBrushParam; typedef enum ogr_style_tool_param_symbol_id { OGRSTSymbolId = 0, OGRSTSymbolAngle, OGRSTSymbolColor, OGRSTSymbolSize, OGRSTSymbolDx, OGRSTSymbolDy, OGRSTSymbolStep, OGRSTSymbolPerp, OGRSTSymbolOffset, OGRSTSymbolPriority, OGRSTSymbolLast } OGRSTSymbolParam; typedef enum ogr_style_tool_param_label_id { OGRSTLabelFontName = 0, OGRSTLabelSize, OGRSTLabelTextString, OGRSTLabelAngle, OGRSTLabelFColor, OGRSTLabelBColor, OGRSTLabelPlacement, OGRSTLabelAnchor, OGRSTLabelDx, OGRSTLabelDy, OGRSTLabelPerp, OGRSTLabelBold, OGRSTLabelItalic, OGRSTLabelUnderline, OGRSTLabelPriority, OGRSTLabelLast } OGRSTLabelParam; //Everytime a pszStyleString gived in parameter is NULL, the StyleString defined in the Mgr will be use.class OGRStyleMgr{ OGRStyleMgr(OGRStyleTable *poDataSetStyleTable =NULL); GBool SetFeatureStyleString(OGRFeature *,const char *pszStyleString=NULL, GBool bNoMatching = FALSE); /*it will set in the gived feature the pszStyleString with the style or will set the style name found in dataset StyleTable (if bNoMatching == FALSE)*/ const char *InitFromFeature(OGRFeature *); GBool InitStyleString(const char *pszStyleString = NULL); const char *GetStyleName(const char *pszStyleString= NULL); const char *GetStyleByName(const char *pszStyleName); GBool AddStyle(const char *pszStyleName, const char *pszStyleString=NULL); const char *GetStyleString(OGRFeature * = NULL); GBool AddPart(OGRStyleTool *); GBool AddPart(const char *); int GetPartCount(const char *pszStyleString = NULL); OGRStyleTool *GetPart(int hPartId, const char *pszStyleString = NULL); OGRStyleTable *GetDataSetStyleTable(){return m_poDataSetStyleTable;} OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString);}; class OGRStyleTool{ OGRStyleTool(OGRSTClassId eClassId); GBool GetRGBFromString(const char *pszColor, int &nRed, int &nGreen, int &nBlue); int GetSpecificId(const char *pszId, const char *pszWanted); OGRSTClassId GetType(); void SetUnit(OGRSTUnitId,double dfScale = 1.0); //the dfScale will be //used if we are working with Ground Unit ( ground = paper * scale); OGRSTUnitId GetUnit(){return m_eUnit;} void SetStyleString(const char *pszStyleString);};class OGRStylePen : public OGRStyleTool{ /**********************************************************************/ /* Explicite fct for all parameters defined in the Drawing tools Pen */ /**********************************************************************/ const char *Color(GBool &bDefault) void SetColor(const char *pszColor) double Width(GBool &bDefault) void SetWidth(double dfWidth) const char *Pattern(GBool &bDefault) void SetPattern(const char *pszPattern) const char *Id(GBool &bDefault) void SetId(const char *pszId) double PerpendicularOffset(GBool &bDefault) void SetPerpendicularOffset(double dfPerp) const char *Cap(GBool &bDefault) void SetCap(const char *pszCap) const char *Join(GBool &bDefault) void SetJoin(const char *pszJoin) int Priority(GBool &bDefault) void SetPriority(int nPriority) /*****************************************************************/ inline const char *GetParamStr(OGRSTPenParam eParam, GBool &bValueIsNull) inline int GetParamNum(OGRSTPenParam eParam,GBool &bValueIsNull) inline double GetParamDbl(OGRSTPenParam eParam,GBool &bValueIsNull) inline void SetParamStr(OGRSTPenParam eParam, const char *pszParamString) inline void SetParamNum(OGRSTPenParam eParam, int nParam) inline void SetParamDbl(OGRSTPenParam eParam, double dfParam) };class OGRStyleBrush : public OGRStyleTool{ /*a Explicite fct for all parameters defined in the Drawing tools Brush */ const char *ForeColor(GBool &bDefault) void SetForeColor(const char *pszColor) const char *BackColor(GBool &bDefault) void SetBackColor(const char *pszColor) const char *Id(GBool &bDefault) void SetId(const char *pszId) double Angle(GBool &bDefault) void SetAngle(double dfAngle) double Size(GBool &bDefault) void SetSize(double dfSize) double SpacingX(GBool &bDefault) void SetSpacingX(double dfX) double SpacingY(GBool &bDefault) void SetSpacingY(double dfY) int Priority(GBool &bDefault) void SetPriority(int nPriority) /*****************************************************************/ };class OGRStyleSymbol : public OGRStyleTool{ /*****************************************************************/ /* Explicite fct for all parameters defined in the Drawing tools */ /*****************************************************************/ const char *Id(GBool &bDefault) void SetId(const char *pszId) double Angle(GBool &bDefault) void SetAngle(double dfAngle) const char *Color(GBool &bDefault) void SetColor(const char *pszColor) double Size(GBool &bDefault) void SetSize(double dfSize) double SpacingX(GBool &bDefault) void SetSpacingX(double dfX) double SpacingY(GBool &bDefault) void SetSpacingY(double dfY) double Step(GBool &bDefault) void SetStep(double dfStep) double Offset(GBool &bDefault) void SetOffset(double dfOffset) double Perp(GBool &bDefault) void SetPerp(double dfPerp) int Priority(GBool &bDefault) void SetPriority(int nPriority) /*****************************************************************/ };class OGRStyleLabel : public OGRStyleTool{ /*****************************************************************/ /* Explicite fct for all parameters defined in the Drawing tools */ /*****************************************************************/ const char *FontName(GBool &bDefault) void SetFontName(const char *pszFontName) double Size(GBool &bDefault) void SetSize(double dfSize) const char *TextString(GBool &bDefault) void SetTextString(const char *pszTextString) double Angle(GBool &bDefault) void SetAngle(double dfAngle) const char *ForeColor(GBool &bDefault) void SetForColor(const char *pszForColor) const char *BackColor(GBool &bDefault) void SetBackColor(const char *pszBackColor) const char *Placement(GBool &bDefault) void SetPlacement(const char *pszPlacement) int Anchor(GBool &bDefault) void SetAnchor(int nAnchor) double SpacingX(GBool &bDefault) void SetSpacingX(double dfX) double SpacingY(GBool &bDefault) void SetSpacingY(double dfY) double Perp(GBool &bDefault) void SetPerp(double dfPerp) GBool Bold(GBool &bDefault) void SetBold(GBool bBold) GBool Italic(GBool &bDefault) void SetItalic(GBool bItalic) GBool Underline(GBool &bDefault) void SetUnderline(GBool bUnderline) int Priority(GBool &bDefault) void SetPriority(int nPriority) /*****************************************************************/ };class OGRStyleTable{ OGRStyleTable(); GBool AddStyle(const char *pszName,const char *pszStyleString); GBool RemoveStyle(const char *pszName); GBool ModifyStyle(const char *pszName, const char *pszStyleString); GBool SaveStyleTable(const char *pszFilename); GBool LoadStyleTable(const char *pszFilename); const char *Find(const char *pszStyleString); GBool IsExist(const char *pszName); const char *GetStyleName(const char *pszName); void Print(FILE *fpOut); void Clear();};Usage examples: OGRStyleTable oStyleTable; OGRStyleMgr *poStyleMgr = new OGRStyleMgr(&oStyleTable); // Create a New style in the style table if (poStyleMgr->AddStyle("@Name","PEN(c:#123456;w:10px);BRUSH(c:345678)")) { poStyleMgr->SetFeatureStyleString(poFeature,"@Name",TRUE) or poStyleMgr->SetFeatureStyleString(poFeature,"PEN(c:#123456,w:10px);BRUSH(c:345678)",FALSE) } oStyleTable->SaveStyleTable("ttt.tbl"); // Create a New style in the style table poStyleMgr->InitStyleString(); poStyleMgr->AddPart("PEN(c:#123456,w:10px)"); poStyleMgr->AddPart("BRUSH(c:345678)"); poStyleMgr->AddStyle("@Name"); poStyleMgr->SetFeatureStyleString(poFeature,"@Name",TRUE); oStyleTable->SaveStyleTable("ttt.tbl"); // Create a New style in the style table OGRStyleTool *poStylePen = new OGRStylePen; poStylePen->SetColor("#123456"); poStylePen->SetUnit(OGRSTUPixel); poStylePen->SetWidth(10.0); poStyleMgr->AddPart(poStylePen); delete poStylePen; // Reading a style; OGRStyleTool *poStyleTool; poStyleMgr->GetStyleString(poFeature); for (i=0;i<poStyleMgr->GetPartCount();i++) { poStyleTool = GetPart(i); switch(poStyleTool->GetType()) { case OGRSTCPen: poStylePen = (OGRStylePen *)poStyleTool; pszColor = poStylePen->Color(bDefault); if (bDefault == FALSE) poStylePen->GetRGBFromString(pszColor, nRed, nGree, nBlue, nTrans); else // Color not defined; dfWidth = poStylePen->Width(bDefault); if (bDefault == FALSE) // Use dfWidth else // dfWidth not defined : : } }</PRE><P> </P><P><HR WIDTH=50%></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -