ogrfeaturestyle.cpp
来自「在linux环境下」· C++ 代码 · 共 1,732 行 · 第 1/5 页
CPP
1,732 行
{ return i; } } return -1;} /****************************************************************************//* 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); // Parse();}/****************************************************************************//*const char *OGRStyleTool::GetStyleString( OGRStyleParamId *pasStyleParam ,*//* OGRStyleValue *pasStyleValue, int nSize) *//* *//****************************************************************************/const char *OGRStyleTool::GetStyleString( OGRStyleParamId *pasStyleParam , OGRStyleValue *pasStyleValue, int nSize){ int i; GBool bFound; char *pszCurrent = NULL; const char *pszClass; pszCurrent = (char *)CPLCalloc(nSize, 20 * sizeof(char)); if (IsStyleModified()) { 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; default: pszClass = "UNKNOWN("; } strcat(pszCurrent,pszClass); bFound = FALSE; for (i=0;i< nSize;i++) { if (pasStyleValue[i].bValid == FALSE) continue; if (bFound) strcat(pszCurrent,","); bFound = TRUE; strcat(pszCurrent,pasStyleParam[i].pszToken); strcat(pszCurrent,":"); switch (pasStyleParam[i].eType) { case OGRSTypeString: strcat(pszCurrent,pasStyleValue[i].pszValue); break; case OGRSTypeDouble: strcat(pszCurrent,CPLSPrintf("%f",pasStyleValue[i].dfValue)); break; case OGRSTypeInteger: strcat(pszCurrent,CPLSPrintf("%d",pasStyleValue[i].nValue)); break; default: break; } if (pasStyleParam[i].bGeoref) switch (pasStyleValue[i].eUnit) { case OGRSTUGround: strcat(pszCurrent,"g"); break; case OGRSTUPixel: strcat(pszCurrent,"px"); break; case OGRSTUPoints: strcat(pszCurrent,"pt"); break; case OGRSTUCM: strcat(pszCurrent,"cm"); break; case OGRSTUInches: strcat(pszCurrent,"in"); break; case OGRSTUMM: //strcat(pszCurrent,"mm"); default: break; //imp } } strcat(pszCurrent,")"); m_pszStyleString = CPLStrdup(pszCurrent); m_bModified = FALSE; } return m_pszStyleString;} /****************************************************************************//* int OGRStyleTool::GetRGBFromString() *//* *//****************************************************************************/GBool OGRStyleTool::GetRGBFromString(const char *pszColor, int &nRed, int &nGreen ,int & nBlue, int &nTransparance){ int nCount; nTransparance = 255; nCount = sscanf(pszColor,"#%2x%2x%2x%2x",&nRed,&nGreen,&nBlue, &nTransparance); if (nCount >=3) return TRUE; else return FALSE;}/****************************************************************************//* OGRSTClassId OGRStyleTool::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;}/****************************************************************************//* OGRSTClassId OGRStyleTool::GetType() *//* *//****************************************************************************/OGRSTClassId OGRStyleTool::GetType(){ return m_eClassId;} /****************************************************************************//* void OGRStyleTool::SetUnit(OGRSTUnitId,double dfScale) *//* *//****************************************************************************/void OGRStyleTool::SetUnit(OGRSTUnitId eUnit,double dfScale){ m_dfScale = dfScale; m_eUnit = eUnit;}/****************************************************************************//* GBool OGRStyleTool::Parse(OGRStyleParamId *pasStyle, *//* OGRStyleValue *pasValue, *//* int nCount) *//* *//****************************************************************************/GBool OGRStyleTool::Parse(OGRStyleParamId *pasStyle, OGRStyleValue *pasValue, int nCount){ int i,j; char **papszToken; char **papszToken2; OGRSTUnitId eLastUnit; if (IsStyleParsed() == TRUE) return TRUE; StyleParsed(); if (m_pszStyleString == NULL) return FALSE; 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; } papszToken2 = CSLTokenizeString2(papszToken[1],":,", CSLT_HONOURSTRINGS | CSLT_ALLOWEMPTYTOKENS ); if (CSLCount(papszToken2) %2 != 0) { CSLDestroy( papszToken ); CSLDestroy( papszToken2 ); CPLError(CE_Failure, CPLE_AppDefined, "Error in the StyleTool String %s\n",m_pszStyleString); return FALSE; } 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]); CSLDestroy( papszToken ); CSLDestroy( papszToken2 ); return FALSE; } break; case OGRSTCSymbol: if (!EQUAL(papszToken[0],"SYMBOL")) { CPLError(CE_Failure, CPLE_AppDefined, "Error in the Type of StyleTool %s should be a SYMBOL Type\n", papszToken[0]); CSLDestroy( papszToken ); CSLDestroy( papszToken2 ); return FALSE; } break; case OGRSTCLabel: if (!EQUAL(papszToken[0],"LABEL")) { CPLError(CE_Failure, CPLE_AppDefined, "Error in the Type of StyleTool %s should be a LABEL Type\n", papszToken[0]); CSLDestroy( papszToken ); CSLDestroy( papszToken2 ); return FALSE; } break; default: CPLError(CE_Failure, CPLE_AppDefined, "Error in the Type of StyleTool, Type undetermined\n"); CSLDestroy( papszToken ); CSLDestroy( papszToken2 ); return FALSE; break; } i=0; // Save Scale and output Units because the parsing code will alter // the values eLastUnit = m_eUnit; double dSavedScale = m_dfScale; while (i < CSLCount(papszToken2)) { for (j=0;j<nCount;j++) if (EQUAL(pasStyle[j].pszToken,papszToken2[i])) { if (pasStyle[j].bGeoref == TRUE) SetInternalInputUnitFromParam(papszToken2[i+1]); OGRStyleTool::SetParamStr(pasStyle[j] , pasValue[j], papszToken2[i+1]); break; } i+=2; } m_eUnit = eLastUnit; m_dfScale = dSavedScale;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?