?? ogrfeaturestyle.cpp
字號:
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 = 0;
nTransparance = 255;
// FIXME: should we really use sscanf here?
if( pszColor )
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]);
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;
case OGRSTCVector:
if (!EQUAL(papszToken[0],"VECTOR"))
{
CPLError(CE_Failure, CPLE_AppDefined,
"Error in the Type of StyleTool %s should be a VECTOR 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 );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -