📄 ogrfeaturestyle.cpp
字号:
/****************************************************************************** * $Id: ogrfeaturestyle.cpp,v 1.23 2006/12/13 18:53:29 dron Exp $ * * Project: OpenGIS Simple Features Reference Implementation * Purpose: Feature Representation string API * Author: Stephane Villeneuve, stephane.v@videotron.ca * ****************************************************************************** * Copyright (c) 2000-2001, Stephane Villeneuve * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. ****************************************************************************** * * $Log: ogrfeaturestyle.cpp,v $ * Revision 1.23 2006/12/13 18:53:29 dron * Added OGRStyleTable::Clone() method. * * Revision 1.22 2006/12/12 17:14:29 dron * Fixed method names in OGRStyleVector interface. * * Revision 1.21 2006/11/16 18:57:24 dron * Make Parse() method private. * * Revision 1.20 2006/11/16 11:56:48 dron * Free the memory allocated in OGRStyleMgr::GetPart() method after usage * as per bug http://bugzilla.remotesensing.org/show_bug.cgi?id=1009 * * Revision 1.19 2006/10/09 12:52:30 dron * Style parsing logic in OGRStyleTool::Parse() was broken, rewrote it. * * Revision 1.18 2006/09/27 20:20:58 fwarmerdam * Extend szCurrent[] buffer size. I should use CPLString, but I can't * seem to form a test case to try out complex changes. (bug 1310) * * Revision 1.17 2006/09/26 09:49:17 dron * 'Stretch' parameter is not georeferenced. * * Revision 1.16 2006/09/23 15:27:52 dron * Added new label styles: 'w', 'st', 'h', 'm:h', 'm:a', 'p:{10,11,12}'. * * Revision 1.15 2006/03/03 20:39:31 fwarmerdam * Fixed memory leak in GetStyleString() * http://bugzilla.remotesensing.org/show_bug.cgi?id=1103 * * Revision 1.14 2005/10/12 19:16:59 jlacroix * Add comment in the OGRStyleTool::Parse function * * Revision 1.13 2004/12/02 18:24:12 fwarmerdam * added support for fontname on symbol, per bug 684 * * Revision 1.12 2004/05/11 00:39:43 warmerda * make asStyle*[] using methods non-inline * * Revision 1.11 2004/02/20 22:41:14 warmerda * Fixed GetRGBFromString() to use 255 as the default alpha value instead * of zero. Fixes: http://bugzilla.remotesensing.org/show_bug.cgi?id=306 * * Revision 1.10 2003/09/29 15:12:20 warmerda * Fixed memory leaks in the pszValue's of the m_pasStyleValue lists. * * Revision 1.9 2002/06/25 14:47:31 warmerda * CPL_DLL export style api * * Revision 1.8 2002/04/11 21:02:20 warmerda * Fix memory leak in case of parse error reported by Wanshou Jiang. * * Revision 1.7 2002/01/16 04:00:25 warmerda * use CSLTokenizeString2() and avoid discarding quotes when splitting stuff * * Revision 1.6 2001/07/18 05:03:05 warmerda * added CPL_CVSID * * Revision 1.5 2001/07/03 04:20:26 danmo * Allow empty strings in style string param values, and replaced printf messages * in the code with CPLError() calls. * * Revision 1.4 2001/07/03 03:20:55 danmo * Avoid losing Scale value during OGRStyleTool::Parse(). * * Revision 1.3 2001/01/19 21:10:47 warmerda * replaced tabs * * Revision 1.2 2000/12/07 03:52:47 danmo * Unix port - handle strstr() return value as const char * * * Revision 1.1 2000/08/18 21:26:01 svillene * OGR Representation * */#include "cpl_conv.h"#include "cpl_string.h"#include "ogr_feature.h"#include "ogr_featurestyle.h"CPL_CVSID("$Id: ogrfeaturestyle.cpp,v 1.23 2006/12/13 18:53:29 dron Exp $");CPL_C_STARTvoid OGRFeatureStylePuller() {}CPL_C_END/****************************************************************************//* Class Parameter (used in the String) *//* *//* The order of all parameter MUST be the same than in the definition *//****************************************************************************/OGRStyleParamId asStylePen[] = {{OGRSTPenColor,"c",FALSE,OGRSTypeString}, {OGRSTPenWidth,"w",TRUE,OGRSTypeDouble}, {OGRSTPenPattern,"p",TRUE,OGRSTypeString}, {OGRSTPenId,"id",FALSE,OGRSTypeString}, {OGRSTPenPerOffset,"dp",TRUE,OGRSTypeDouble}, {OGRSTPenCap,"cap",FALSE,OGRSTypeString}, {OGRSTPenJoin,"j",FALSE,OGRSTypeString}, {OGRSTPenPriority, "l", FALSE, OGRSTypeInteger }};OGRStyleParamId asStyleBrush[] = {{OGRSTBrushFColor,"fc",FALSE,OGRSTypeString}, {OGRSTBrushBColor,"bc",FALSE,OGRSTypeString}, {OGRSTBrushId,"id",FALSE,OGRSTypeString}, {OGRSTBrushAngle,"a",TRUE,OGRSTypeDouble}, {OGRSTBrushSize,"s",TRUE,OGRSTypeDouble}, {OGRSTBrushDx,"dx",TRUE,OGRSTypeDouble}, {OGRSTBrushDy,"dy",TRUE,OGRSTypeDouble}, {OGRSTBrushPriority,"l",FALSE,OGRSTypeInteger }};OGRStyleParamId asStyleSymbol[] = { {OGRSTSymbolId,"id",FALSE,OGRSTypeString}, {OGRSTSymbolAngle,"a",FALSE,OGRSTypeDouble}, {OGRSTSymbolColor,"c",FALSE,OGRSTypeString}, {OGRSTSymbolSize,"s",TRUE,OGRSTypeDouble}, {OGRSTSymbolDx,"dx",TRUE,OGRSTypeDouble}, {OGRSTSymbolDy,"dy",TRUE,OGRSTypeDouble}, {OGRSTSymbolStep,"ds",TRUE,OGRSTypeDouble}, {OGRSTSymbolPerp,"dp",TRUE,OGRSTypeDouble}, {OGRSTSymbolOffset,"di",TRUE,OGRSTypeDouble}, {OGRSTSymbolPriority,"l",FALSE,OGRSTypeInteger}, {OGRSTSymbolFontName,"f",FALSE,OGRSTypeString}};OGRStyleParamId asStyleLabel[] = {{OGRSTLabelFontName,"f",FALSE,OGRSTypeString}, {OGRSTLabelSize,"s",TRUE,OGRSTypeDouble}, {OGRSTLabelTextString,"t",FALSE, OGRSTypeString}, {OGRSTLabelAngle,"a",FALSE,OGRSTypeDouble}, {OGRSTLabelFColor,"c",FALSE,OGRSTypeString}, {OGRSTLabelBColor,"b",FALSE,OGRSTypeString}, {OGRSTLabelPlacement,"m",FALSE, OGRSTypeString}, {OGRSTLabelAnchor,"p",FALSE,OGRSTypeInteger}, {OGRSTLabelDx,"dx",TRUE,OGRSTypeDouble}, {OGRSTLabelDy,"dy",TRUE,OGRSTypeDouble}, {OGRSTLabelPerp,"dp",TRUE,OGRSTypeDouble}, {OGRSTLabelBold,"bo",FALSE,OGRSTypeBoolean}, {OGRSTLabelItalic,"it",FALSE,OGRSTypeBoolean}, {OGRSTLabelUnderline,"un",FALSE, OGRSTypeBoolean}, {OGRSTLabelPriority,"l",FALSE, OGRSTypeInteger}, {OGRSTLabelStrikeout,"st",FALSE, OGRSTypeBoolean}, {OGRSTLabelStretch,"w",FALSE, OGRSTypeDouble}, {OGRSTLabelAdjHor,"ah",FALSE, OGRSTypeString}, {OGRSTLabelAdjVert,"av",FALSE, OGRSTypeString}, {OGRSTLabelHColor,"h",FALSE,OGRSTypeString} };OGRStyleParamId asStyleVector[] = {{OGRSTVectorId,"id",FALSE,OGRSTypeString}, {OGRSTVectorNoCompress,"nc",FALSE, OGRSTypeInteger}, {OGRSTVectorSprain,"sp",FALSE, OGRSTypeInteger}, {OGRSTVectorNoSlope,"ns",FALSE, OGRSTypeInteger}, {OGRSTVectorMirroring,"m",FALSE, OGRSTypeInteger}, {OGRSTVectorCentering,"c",FALSE, OGRSTypeInteger}, {OGRSTVectorPriority,"l",FALSE, OGRSTypeInteger} };/* ======================================================================== *//* OGRStyleMgr *//* ======================================================================== *//****************************************************************************//* OGRStyleMgr::OGRStyleMgr(OGRStyleTable *poDataSetStyleTable) *//* *//****************************************************************************/OGRStyleMgr::OGRStyleMgr(OGRStyleTable *poDataSetStyleTable){ m_poDataSetStyleTable = poDataSetStyleTable; m_pszStyleString = NULL;}/****************************************************************************//* OGRStyleMgr::~OGRStyleMgr() *//* *//****************************************************************************/OGRStyleMgr::~OGRStyleMgr(){ if ( m_pszStyleString ) CPLFree(m_pszStyleString);}/****************************************************************************//* GBool OGRStyleMgr::SetFeatureStyleString(OGRFeature *poFeature, *//* char *pszStyleString, *//* GBool bNoMatching) *//* Set the gived representation to the feature, *//* if bNoMatching == TRUE, don't try to find it in the styletable *//* otherwize, we will use the name defined in the styletable *//****************************************************************************/GBool OGRStyleMgr::SetFeatureStyleString(OGRFeature *poFeature, const char *pszStyleString, GBool bNoMatching){ const char *pszName; if (poFeature == FALSE) return FALSE; if (pszStyleString == NULL) poFeature->SetStyleString(""); else if (bNoMatching == TRUE) poFeature->SetStyleString(pszStyleString); else if ((pszName = GetStyleName(pszStyleString)) != NULL) poFeature->SetStyleString(pszName); else poFeature->SetStyleString(pszStyleString); return TRUE;}/****************************************************************************//* const char *OGRStyleMgr::InitFromFeature(OGRFeature *) *//* *//****************************************************************************/const char *OGRStyleMgr::InitFromFeature(OGRFeature *poFeature){ CPLFree(m_pszStyleString); m_pszStyleString = NULL; if (poFeature) InitStyleString(poFeature->GetStyleString()); else m_pszStyleString = NULL; return m_pszStyleString;}/****************************************************************************//* GBool OGRStyleMgr::InitStyleString(char *pszStyleString) *//* *//****************************************************************************/GBool OGRStyleMgr::InitStyleString(const char *pszStyleString){ CPLFree(m_pszStyleString); m_pszStyleString = NULL; if (pszStyleString && pszStyleString[0] == '@') m_pszStyleString = CPLStrdup(GetStyleByName(pszStyleString)); else m_pszStyleString = NULL; if (m_pszStyleString == NULL && pszStyleString) m_pszStyleString = CPLStrdup(pszStyleString); return TRUE;} /****************************************************************************//* const char *OGRStyleMgr::GetStyleName(const char *pszStyleString) *//* *//****************************************************************************/const char *OGRStyleMgr::GetStyleName(const char *pszStyleString){ // SECURITY: the unit and the value for all parameter should be the same, // a text comparaison is executed . const char *pszStyle; if (pszStyleString) pszStyle = pszStyleString; else pszStyle = m_pszStyleString; if (pszStyle) { if (m_poDataSetStyleTable) return m_poDataSetStyleTable->GetStyleName(pszStyle); } return NULL;}/****************************************************************************//* const char *OGRStyleMgr::GetStyleByName(const char *pszStyleName) *//* *//****************************************************************************/const char *OGRStyleMgr::GetStyleByName(const char *pszStyleName){ if (m_poDataSetStyleTable) { return m_poDataSetStyleTable->Find(pszStyleName); } return NULL;} /****************************************************************************//* GBool OGRStyleMgr::AddStyle(char *pszStyleName, *//* char *pszStyleString) *//* *//****************************************************************************/GBool OGRStyleMgr::AddStyle(const char *pszStyleName, const char *pszStyleString){ const char *pszStyle; if (pszStyleString) pszStyle = pszStyleString; else pszStyle = m_pszStyleString; if (m_poDataSetStyleTable) { return m_poDataSetStyleTable->AddStyle(pszStyleName, pszStyle); } return FALSE;}/****************************************************************************//* const char *OGRStyleMgr::GetStyleString(OGRFeature *) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -