⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogrfeaturestyle.cpp

📁 用于读取TAB、MIF、SHP文件的类
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    const char *pszOutput = NULL;    int nPos;    if ((nPos = IsExist(pszName)) != -1)    {        pszOutput = CSLGetField(m_papszStyleTable,nPos);                 pszDash = strstr(pszOutput,":");                if (pszDash)          return &pszDash[1];    }    return NULL;}   /****************************************************************************//*              OGRStyleTable::Print(FILE *fpOut)                           *//*                                                                          *//****************************************************************************/void OGRStyleTable::Print(FILE *fpOut){        VSIFPrintf(fpOut,"#OFS-Version: 1.0\n");    VSIFPrintf(fpOut,"#StyleField: style\n");    if (m_papszStyleTable)    {        CSLPrint(m_papszStyleTable,fpOut);    }}/****************************************************************************//*             GBool OGRStyleTable::IsExist(const char *pszName)            *//*                                                                          *//*   return a index of the style in the table otherwise return -1           *//****************************************************************************/int OGRStyleTable::IsExist(const char *pszName){    int i;    const char *pszNewString;    if (pszName == NULL)      return -1;    pszNewString = CPLSPrintf("%s:",pszName);    for (i=0;i<CSLCount(m_papszStyleTable);i++)    {        if (strstr(m_papszStyleTable[i],pszNewString) != NULL)        {            return i;                    }    }    return -1;}    /************************************************************************//*                               Clone()                                *//************************************************************************//** * Duplicate style table. * * The newly created style table is owned by the caller, and will have it's * own reference to the OGRStyleTable. * * This method is the same as the C function OGR_F_Clone(). * * @return new feature, exactly matching this feature. */OGRStyleTable *OGRStyleTable::Clone(){    OGRStyleTable *poNew = new OGRStyleTable();    poNew->m_papszStyleTable = CSLDuplicate( m_papszStyleTable );    return poNew;}/****************************************************************************//*                          OGRStyleTool::OGRStyleTool()                    *//*                                                                          *//****************************************************************************/OGRStyleTool::OGRStyleTool(OGRSTClassId eClassId){    m_eClassId = eClassId;     m_dfScale = 1.0;     m_eUnit = OGRSTUMM;    m_pszStyleString = NULL;    m_bModified = FALSE;    m_bParsed = FALSE;}/****************************************************************************//*                       OGRStyleTool::~OGRStyleTool()                      *//*                                                                          *//****************************************************************************/OGRStyleTool::~OGRStyleTool(){    CPLFree(m_pszStyleString);} /****************************************************************************//*      void OGRStyleTool::SetStyleString(const char *pszStyleString)       *//*                                                                          *//****************************************************************************/void OGRStyleTool::SetStyleString(const char *pszStyleString){    m_pszStyleString = CPLStrdup(pszStyleString);}/****************************************************************************//*const char *OGRStyleTool::GetStyleString( OGRStyleParamId *pasStyleParam ,*//*                          OGRStyleValue *pasStyleValue, int nSize)        *//*                                                                          *//****************************************************************************/const char *OGRStyleTool::GetStyleString( OGRStyleParamId *pasStyleParam ,                            OGRStyleValue *pasStyleValue, int nSize){    if (IsStyleModified())    {        int i;        GBool bFound;        const char *pszClass;        // FIXME: we should use CPLString instead of static buffer:        char szCurrent[8192];        szCurrent[0] = '\0';            CPLFree(m_pszStyleString);                switch (GetType())        {          case OGRSTCPen:            pszClass = "PEN(";            break;          case OGRSTCBrush:            pszClass = "BRUSH(";            break;          case OGRSTCSymbol:            pszClass = "SYMBOL(";            break;          case OGRSTCLabel:            pszClass = "LABEL(";            break;          case OGRSTCVector:            pszClass = "VECTOR(";            break;          default:            pszClass = "UNKNOWN(";        }        strcat(szCurrent,pszClass);        bFound = FALSE;        for (i=0;i< nSize;i++)        {            if (pasStyleValue[i].bValid == FALSE)              continue;            if (bFound)              strcat(szCurrent,",");            bFound = TRUE;                        strcat(szCurrent,pasStyleParam[i].pszToken);            switch (pasStyleParam[i].eType)            {              case OGRSTypeString:                strcat(szCurrent,":");                strcat(szCurrent,pasStyleValue[i].pszValue);                break;              case OGRSTypeDouble:                strcat(szCurrent,CPLSPrintf(":%f",pasStyleValue[i].dfValue));                break;              case OGRSTypeInteger:                strcat(szCurrent,CPLSPrintf(":%d",pasStyleValue[i].nValue));                break;              default:                break;            }                   if (pasStyleParam[i].bGeoref)              switch (pasStyleValue[i].eUnit)              {                case OGRSTUGround:                  strcat(szCurrent,"g");                  break;                case OGRSTUPixel:                  strcat(szCurrent,"px");                  break;                case OGRSTUPoints:                  strcat(szCurrent,"pt");                  break;                case OGRSTUCM:                  strcat(szCurrent,"cm");                  break;                case OGRSTUInches:                  strcat(szCurrent,"in");                  break;                case OGRSTUMM:                  //strcat(szCurrent,"mm");                default:                  break;    //imp              }        }        strcat(szCurrent,")");        m_pszStyleString = CPLStrdup(szCurrent);        m_bModified = FALSE;    }        return m_pszStyleString;}   /************************************************************************//*                          GetRGBFromString()                          *//************************************************************************/GBool OGRStyleTool::GetRGBFromString(const char *pszColor, int &nRed,                                      int &nGreen ,int & nBlue,                                      int &nTransparance){   int nCount;      nTransparance = 255;   // FIXME: should we really use sscanf here?   nCount  = sscanf(pszColor,"#%2x%2x%2x%2x",&nRed,&nGreen,&nBlue,                     &nTransparance);      if (nCount >=3)     return TRUE;   else     return FALSE;}/************************************************************************//*                           GetSpecificId()                            *//*                                                                      *//*      return -1, if the wanted type is not found, ex:                 *//*      if you want ogr-pen value, pszWanted should be ogr-pen(case     *//*      sensitive)                                                      *//************************************************************************/int OGRStyleTool::GetSpecificId(const char *pszId, const char *pszWanted){    const char *pszRealWanted = pszWanted;    const char *pszFound;    int nValue  = -1;    if (pszWanted == NULL || strlen(pszWanted) == 0)      pszRealWanted = "ogr-pen";    if (pszId == NULL)      return -1;        if ((pszFound = strstr(pszId, pszRealWanted)) != NULL)    {        // We found the string, it could be no value after it, use default one        nValue = 0;                if (pszFound[strlen(pszRealWanted)] == '-' )          nValue =atoi(&pszFound[strlen(pszRealWanted)+1]);    }        return nValue;}/************************************************************************//*                              GetType()                               *//************************************************************************/OGRSTClassId OGRStyleTool::GetType(){    return m_eClassId;}    /************************************************************************//*                              SetUnit()                               *//************************************************************************/void OGRStyleTool::SetUnit(OGRSTUnitId eUnit,double dfScale){    m_dfScale = dfScale;    m_eUnit = eUnit;}/************************************************************************//*                               Parse()                                *//************************************************************************/GBool OGRStyleTool::Parse(OGRStyleParamId *pasStyle,                          OGRStyleValue *pasValue,                          int nCount){    char **papszToken; // Token to contains StyleString Type and content    char **papszToken2; // Token that will contains StyleString elements    OGRSTUnitId  eLastUnit;        if (IsStyleParsed() == TRUE)      return TRUE;    StyleParsed();    if (m_pszStyleString == NULL)      return FALSE;        // Tokenize the String to get the Type and the content    // Example: Type(elem1:val2,elem2:val2)    papszToken  = CSLTokenizeString2(m_pszStyleString,"()",                                     CSLT_HONOURSTRINGS                                     | CSLT_PRESERVEQUOTES                                     | CSLT_PRESERVEESCAPES );    if (CSLCount(papszToken) > 2 || CSLCount(papszToken) == 0)    {        CSLDestroy( papszToken );        CPLError(CE_Failure, CPLE_AppDefined,                  "Error in the format of the StyleTool %s\n",m_pszStyleString);        return FALSE;    }        // Tokenize the content of the StyleString to get paired components in it.    papszToken2 = CSLTokenizeString2( papszToken[1], ",",                                      CSLT_HONOURSTRINGS                                      | CSLT_PRESERVEQUOTES                                      | CSLT_PRESERVEESCAPES );        // Valid that we have the right StyleString for this feature type.    switch (GetType())    {      case OGRSTCPen:        if (!EQUAL(papszToken[0],"PEN"))        {            CPLError(CE_Failure, CPLE_AppDefined,                      "Error in the Type of StyleTool %s should be a PEN Type\n",                     papszToken[0]);            CSLDestroy( papszToken );            CSLDestroy( papszToken2 );            return FALSE;        }        break;      case OGRSTCBrush:        if (!EQUAL(papszToken[0],"BRUSH"))        {            CPLError(CE_Failure, CPLE_AppDefined,                      "Error in the Type of StyleTool %s should be a BRUSH Type\n",                     papszToken[0]);

⌨️ 快捷键说明

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