ogrfeaturestyle.cpp

来自「用于读取TAB、MIF、SHP文件的类」· C++ 代码 · 共 1,754 行 · 第 1/5 页

CPP
1,754
字号
/*                                                                          *//****************************************************************************/const char *OGRStyleMgr::GetStyleString(OGRFeature *poFeature){    if (poFeature == NULL)      return m_pszStyleString;    else      return InitFromFeature(poFeature);}GBool OGRStyleMgr::AddPart(const char *pszPart){    char *pszTmp;     if (pszPart)    {        if (m_pszStyleString)        {            pszTmp = CPLStrdup(CPLSPrintf("%s;%s",m_pszStyleString,                                          pszPart));            CPLFree(m_pszStyleString);            m_pszStyleString = pszTmp;        }        else        {              pszTmp= CPLStrdup(CPLSPrintf("%s",pszPart));              CPLFree(m_pszStyleString);              m_pszStyleString = pszTmp;        }        return TRUE;    }    return FALSE;}/****************************************************************************//*            GBool OGRStyleMgr::AddPart(OGRStyleTool *)                    *//*            Add a new part in the current style                           *//****************************************************************************/GBool OGRStyleMgr::AddPart(OGRStyleTool *poStyleTool){    char *pszTmp;    if (poStyleTool)    {        if (m_pszStyleString)        {            pszTmp = CPLStrdup(CPLSPrintf("%s;%s",m_pszStyleString,                                        poStyleTool->GetStyleString()));            CPLFree(m_pszStyleString);            m_pszStyleString = pszTmp;        }        else        {              pszTmp= CPLStrdup(CPLSPrintf("%s",                                        poStyleTool->GetStyleString()));              CPLFree(m_pszStyleString);              m_pszStyleString = pszTmp;        }        return TRUE;    }    return FALSE;}    /****************************************************************************//*            int OGRStyleMgr::GetPartCount(const char *pszStyleString)     *//*            return the number of part in the stylestring                  *//****************************************************************************/int OGRStyleMgr::GetPartCount(const char *pszStyleString){    const char *pszPart;    int nPartCount = 1;    const char *pszString;    const char *pszStrTmp;    if (pszStyleString != NULL)      pszString = pszStyleString;    else      pszString = m_pszStyleString;    if (pszString == NULL)      return 0;    pszStrTmp = pszString;    while ((pszPart = strstr(pszStrTmp,";")) != NULL)    {        pszStrTmp = &pszPart[1];        nPartCount++;    }    return nPartCount;}/****************************************************************************//*            OGRStyleTool *OGRStyleMgr::GetPart(int hPartId,               *//*                                 const char *pszStyleString)              *//*                                                                          *//*     Return a StyleTool of the type of the wanted part, could return NULL *//****************************************************************************/OGRStyleTool *OGRStyleMgr::GetPart(int hPartId,                                    const char *pszStyleString){    char **papszStyleString;    const char *pszStyle;    const char *pszString;    OGRStyleTool    *poStyleTool;    if (pszStyleString)      pszStyle = pszStyleString;     else      pszStyle = m_pszStyleString;    if (pszStyle == NULL)      return NULL;    papszStyleString = CSLTokenizeString2(pszStyle, ";",                                          CSLT_HONOURSTRINGS                                          | CSLT_PRESERVEQUOTES                                          | CSLT_PRESERVEESCAPES );    pszString = CSLGetField( papszStyleString, hPartId );        if ( pszString || strlen(pszString) > 0 )    {        poStyleTool = CreateStyleToolFromStyleString(pszString);        if ( poStyleTool )            poStyleTool->SetStyleString(pszString);        CSLDestroy( papszStyleString );        return poStyleTool;    }     else    {        CSLDestroy(papszStyleString);        return NULL;    }} /****************************************************************************//* OGRStyleTool *CreateStyleToolFromStyleString(const char *pszStyleString) *//*                                                                          *//* create a Style tool from the gived StyleString, it should contain only a *//* part of a StyleString                                                    *//****************************************************************************/OGRStyleTool *OGRStyleMgr::CreateStyleToolFromStyleString(const char *                                                          pszStyleString){    char **papszToken = CSLTokenizeString2(pszStyleString,"();",                                           CSLT_HONOURSTRINGS                                           | CSLT_PRESERVEQUOTES                                           | CSLT_PRESERVEESCAPES );    OGRStyleTool   *poStyleTool;            if (CSLCount(papszToken) <2)        poStyleTool = NULL;    else if (EQUAL(papszToken[0],"PEN"))        poStyleTool = new OGRStylePen();    else if (EQUAL(papszToken[0],"BRUSH"))        poStyleTool = new OGRStyleBrush();    else if (EQUAL(papszToken[0],"SYMBOL"))        poStyleTool = new OGRStyleSymbol();    else if (EQUAL(papszToken[0],"LABEL"))        poStyleTool = new OGRStyleLabel();    else if (EQUAL(papszToken[0],"VECTOR"))        poStyleTool = new OGRStyleVector();    else         poStyleTool = NULL;    CSLDestroy( papszToken );    return poStyleTool;}/* ======================================================================== *//*                OGRStyleTable                                             *//*     Object Used to manage and store a styletable                         *//* ======================================================================== *//****************************************************************************//*              OGRStyleTable::OGRStyleTable()                              *//*                                                                          *//****************************************************************************/OGRStyleTable::OGRStyleTable(){    m_papszStyleTable = NULL;}/****************************************************************************//*          OGRStyleTable::~OGRStyleTable()                                 *//*                                                                          *//****************************************************************************/OGRStyleTable::~OGRStyleTable(){    Clear();}/****************************************************************************//*                void OGRStyleTable::Clear()                               *//*                                                                          *//****************************************************************************/void OGRStyleTable::Clear(){    if (m_papszStyleTable)      CSLDestroy(m_papszStyleTable);    m_papszStyleTable = NULL;}/****************************************************************************//*    const char *OGRStyleTable::GetStyleName(const char *pszStyleString)   *//*                                                                          *//*    return the Name of a gived stylestring otherwise NULL                 *//****************************************************************************/const char *OGRStyleTable::GetStyleName(const char *pszStyleString){    int i;    const char *pszStyleStringBegin;    static char *pszName  = NULL;    char *pszTmp;        if (pszName)      CPLFree(pszName);    pszName = NULL;    for (i=0;i<CSLCount(m_papszStyleTable);i++)    {        pszStyleStringBegin = strstr(m_papszStyleTable[i],":");        if (pszStyleStringBegin && EQUAL(&pszStyleStringBegin[1],                                         pszStyleString))        {            pszName = CPLStrdup(m_papszStyleTable[i]);            pszTmp = strstr(pszName,":");            if (pszTmp)              pszTmp[0] = '\0';            break;        }    }            return pszName;}/****************************************************************************//*            GBool OGRStyleTable::AddStyle(char *pszName,                  *//*                                          char *pszStyleString)           *//*                                                                          *//*   Add a new style in the table, no comparaison will be done on the       *//*   Style string, only on the name, TRUE success, FALSE error              *//****************************************************************************/GBool OGRStyleTable::AddStyle(const char *pszName, const char *pszStyleString){    int nPos;    const char *pszNewString = NULL;        if (pszName && pszStyleString)    {        if ((nPos = IsExist(pszName)) != -1)          return FALSE;                pszNewString = CPLSPrintf("%s:%s",pszName,pszStyleString);                m_papszStyleTable = CSLAddString(m_papszStyleTable,pszNewString);        return TRUE;    }    return FALSE;}/****************************************************************************//*            GBool OGRStyleTable::RemoveStyle(char *pszName)               *//*                                                                          *//*    Remove the gived style in the table based on the name, return TRUE    *//*    on success otherwise FALSE                                            *//****************************************************************************/GBool OGRStyleTable::RemoveStyle(const char *pszName){    int nPos;    if ((nPos = IsExist(pszName)) != -1)    {        m_papszStyleTable = CSLRemoveStrings(m_papszStyleTable,nPos,1,NULL);        return TRUE;    }    return FALSE;}/****************************************************************************//*            GBool OGRStyleTable::ModifyStyle(char *pszName,               *//*                                             char *pszStyleString)        *//*                                                                          *//*    Modify the gived style, if the style doesn't exist, it will be added  *//*    return TRUE on success otherwise return FALSE                         *//****************************************************************************/GBool OGRStyleTable::ModifyStyle(const char *pszName,                                  const char * pszStyleString){    if (pszName == NULL || pszStyleString == NULL)      return FALSE;    RemoveStyle(pszName);    return AddStyle(pszName, pszStyleString);}    /****************************************************************************//*            GBool OGRStyleTable::SaveStyleTable(char *)                   *//*                                                                          *//*    Save the StyleTable in the gived file, return TRUE on success         *//*    otherwise return FALSE                                                *//****************************************************************************/GBool OGRStyleTable::SaveStyleTable(const char *pszFilename){    if (pszFilename == NULL)      return FALSE;    if (CSLSave(m_papszStyleTable,pszFilename) == 0)      return FALSE;    else      return TRUE;}/****************************************************************************//*            GBool OGRStyleTable::LoadStyleTable(char *)                   *//*                                                                          *//*            Read the Style table from a file, return TRUE on success      *//*            otherwise return FALSE                                        *//****************************************************************************/GBool OGRStyleTable::LoadStyleTable(const char *pszFilename){    if (pszFilename == NULL)      return FALSE;    CSLDestroy(m_papszStyleTable);            m_papszStyleTable = CSLLoad(pszFilename);       if (m_papszStyleTable == NULL)      return FALSE;    else      return TRUE;}/****************************************************************************//*             const char *OGRStyleTable::Find(const char *pszName)         *//*                                                                          *//*             return the StyleString based on the gived name,              *//*             otherwise return NULL                                        *//****************************************************************************/const char *OGRStyleTable::Find(const char *pszName){    const char *pszDash = NULL;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?