Skip to content
Permalink
Browse files
msSLDGenerateSLDLayer(): tidy-up. no functional change
  • Loading branch information
rouault committed Oct 24, 2019
1 parent 9bb3797 commit 2107829cdf61bca7faba0af54b28ecadaed3108d
Showing 1 changed file with 79 additions and 125 deletions.
@@ -4134,116 +4134,47 @@ char *msSLDGenerateTextSLD(classObj *psClass, layerObj *psLayer, int nVersion)
#endif
}

#if (defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR)) && defined(USE_OGR)

/************************************************************************/
/* msSLDGenerateSLDLayer */
/* */
/* Genrate an SLD XML string based on the layer's classes. */
/************************************************************************/
char *msSLDGenerateSLDLayer(layerObj *psLayer, int nVersion)
static void msSLDAppendName(msStringBuffer* sb, const char* pszName, int nVersion)
{
#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR)

#ifdef USE_OGR
char szTmp[100];
char *pszTmpName = NULL;
int i, j;
styleObj *psStyle = NULL;
char *pszFilter = NULL;
char *pszFinalSLD = NULL;
char *pszSLD = NULL;
const char *pszTmp = NULL;
double dfMinScale =-1, dfMaxScale = -1;
const char *pszWfsFilter= NULL;
char *pszEncoded = NULL, *pszWfsFilterEncoded=NULL;


if (psLayer &&
(psLayer->status == MS_ON || psLayer->status == MS_DEFAULT) &&
(psLayer->type == MS_LAYER_POINT ||
psLayer->type == MS_LAYER_LINE ||
psLayer->type == MS_LAYER_POLYGON )) {
snprintf(szTmp, sizeof(szTmp), "%s\n", "<NamedLayer>");
pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);

pszTmp = msOWSLookupMetadata(&(psLayer->metadata), "MO", "name");
if (pszTmp) {
pszEncoded = msEncodeHTMLEntities(pszTmp);
if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "<se:Name>%s</se:Name>\n", pszEncoded);
else
snprintf(szTmp, sizeof(szTmp), "<Name>%s</Name>\n", pszEncoded);
pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msFree(pszEncoded);
} else if (psLayer->name) {
pszEncoded = msEncodeHTMLEntities(psLayer->name);
pszTmpName = (char *)malloc(sizeof(char)*(strlen(pszEncoded)+100));
if (nVersion > OWS_1_0_0)
sprintf(pszTmpName, "<se:Name>%s</se:Name>\n", pszEncoded);
else
sprintf(pszTmpName, "<Name>%s</Name>\n", pszEncoded);


msFree(pszEncoded);
pszFinalSLD = msStringConcatenate(pszFinalSLD, pszTmpName);
msFree(pszTmpName);
pszTmpName=NULL;

} else {
if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "<se:Name>%s</se:Name>\n", "NamedLayer");
else
snprintf(szTmp, sizeof(szTmp), "<Name>%s</Name>\n", "NamedLayer");
pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
}

char* pszEncoded = msEncodeHTMLEntities(pszName);
msStringBufferAppend(sb, (nVersion > OWS_1_0_0) ? "<se:Name>" : "<Name>");
msStringBufferAppend(sb, pszEncoded);
msStringBufferAppend(sb, (nVersion > OWS_1_0_0) ? "</se:Name>\n" : "</Name>\n");
msFree(pszEncoded);
}

snprintf(szTmp, sizeof(szTmp), "%s\n", "<UserStyle>");
pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
static void msSLDGenerateUserStyle(msStringBuffer* sb, layerObj *psLayer, int nVersion)
{
const char* pszWfsFilter;

if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "%s\n", "<se:FeatureTypeStyle>");
else
snprintf(szTmp, sizeof(szTmp), "%s\n", "<FeatureTypeStyle>");
msStringBufferAppend(sb, "<UserStyle>\n");

pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msStringBufferAppend(sb, nVersion > OWS_1_0_0 ?
"<se:FeatureTypeStyle>\n" : "<FeatureTypeStyle>\n");

pszWfsFilter = msLookupHashTable(&(psLayer->metadata), "wfs_filter");
if (pszWfsFilter)
pszWfsFilterEncoded = msEncodeHTMLEntities(pszWfsFilter);
if (psLayer->numclasses > 0) {
int i;
for (i=0; i<psLayer->numclasses; i++) {
if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "%s\n", "<se:Rule>");
else
snprintf(szTmp, sizeof(szTmp), "%s\n", "<Rule>");
char* pszFilter;
double dfMinScale =-1, dfMaxScale = -1;

pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msStringBufferAppend(sb, nVersion > OWS_1_0_0 ? "<se:Rule>\n" : "<Rule>\n" );

/* if class has a name, use it as the RULE name */
if (psLayer->class[i]->name) {
pszEncoded = msEncodeHTMLEntities(psLayer->class[i]->name);
pszTmpName = (char *)malloc(sizeof(char)*(strlen(pszEncoded)+100));

if (nVersion > OWS_1_0_0)
sprintf(pszTmpName, "<se:Name>%s</se:Name>\n", pszEncoded);
else
sprintf(pszTmpName, "<Name>%s</Name>\n", pszEncoded);

msFree(pszEncoded);

pszFinalSLD = msStringConcatenate(pszFinalSLD, pszTmpName);
msFree(pszTmpName);
pszTmpName=NULL;
msSLDAppendName(sb, psLayer->class[i]->name, nVersion);
}
/* -------------------------------------------------------------------- */
/* get the Filter if there is a class expression. */
/* -------------------------------------------------------------------- */
pszFilter = msSLDGetFilter(psLayer->class[i] ,
pszWfsFilter);/* pszWfsFilterEncoded); */
pszWfsFilter);

if (pszFilter) {
pszFinalSLD = msStringConcatenate(pszFinalSLD, pszFilter);
msStringBufferAppend(sb, pszFilter);
free(pszFilter);
}
/* -------------------------------------------------------------------- */
@@ -4257,14 +4188,15 @@ char *msSLDGenerateSLDLayer(layerObj *psLayer, int nVersion)
else if (psLayer->map && psLayer->map->web.minscaledenom > 0)
dfMinScale = psLayer->map->web.minscaledenom;
if (dfMinScale > 0) {
char szTmp[100];
if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "<se:MinScaleDenominator>%f</se:MinScaleDenominator>\n",
dfMinScale);
else
snprintf(szTmp, sizeof(szTmp), "<MinScaleDenominator>%f</MinScaleDenominator>\n",
dfMinScale);

pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msStringBufferAppend(sb, szTmp);
}

dfMaxScale = -1.0;
@@ -4275,14 +4207,15 @@ char *msSLDGenerateSLDLayer(layerObj *psLayer, int nVersion)
else if (psLayer->map && psLayer->map->web.maxscaledenom > 0)
dfMaxScale = psLayer->map->web.maxscaledenom;
if (dfMaxScale > 0) {
char szTmp[100];
if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "<se:MaxScaleDenominator>%f</se:MaxScaleDenominator>\n",
dfMaxScale);
else
snprintf(szTmp, sizeof(szTmp), "<MaxScaleDenominator>%f</MaxScaleDenominator>\n",
dfMaxScale);

pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msStringBufferAppend(sb, szTmp);
}


@@ -4295,69 +4228,90 @@ char *msSLDGenerateSLDLayer(layerObj *psLayer, int nVersion)
/* Lines using symbols TODO (specially for dash lines) */
/* -------------------------------------------------------------------- */
if (psLayer->type == MS_LAYER_LINE) {
int j;
for (j=0; j<psLayer->class[i]->numstyles; j++) {
psStyle = psLayer->class[i]->styles[j];
pszSLD = msSLDGenerateLineSLD(psStyle, psLayer, nVersion);
styleObj* psStyle = psLayer->class[i]->styles[j];
char* pszSLD = msSLDGenerateLineSLD(psStyle, psLayer, nVersion);
if (pszSLD) {
pszFinalSLD = msStringConcatenate(pszFinalSLD, pszSLD);
msStringBufferAppend(sb, pszSLD);
free(pszSLD);
}
}

} else if (psLayer->type == MS_LAYER_POLYGON) {
int j;
for (j=0; j<psLayer->class[i]->numstyles; j++) {
psStyle = psLayer->class[i]->styles[j];
pszSLD = msSLDGeneratePolygonSLD(psStyle, psLayer, nVersion);
styleObj* psStyle = psLayer->class[i]->styles[j];
char* pszSLD = msSLDGeneratePolygonSLD(psStyle, psLayer, nVersion);
if (pszSLD) {
pszFinalSLD = msStringConcatenate(pszFinalSLD, pszSLD);
msStringBufferAppend(sb, pszSLD);
free(pszSLD);
}
}

} else if (psLayer->type == MS_LAYER_POINT) {
int j;
for (j=0; j<psLayer->class[i]->numstyles; j++) {
psStyle = psLayer->class[i]->styles[j];
pszSLD = msSLDGeneratePointSLD(psStyle, psLayer, nVersion);
styleObj* psStyle = psLayer->class[i]->styles[j];
char* pszSLD = msSLDGeneratePointSLD(psStyle, psLayer, nVersion);
if (pszSLD) {
pszFinalSLD = msStringConcatenate(pszFinalSLD, pszSLD);
msStringBufferAppend(sb, pszSLD);
free(pszSLD);
}
}

}
/* label if it exists */
pszSLD = msSLDGenerateTextSLD(psLayer->class[i], psLayer, nVersion);
if (pszSLD) {
pszFinalSLD = msStringConcatenate(pszFinalSLD, pszSLD);
free(pszSLD);
{
/* label if it exists */
char* pszSLD = msSLDGenerateTextSLD(psLayer->class[i], psLayer, nVersion);
if (pszSLD) {
msStringBufferAppend(sb, pszSLD);
free(pszSLD);
}
}
if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "%s\n", "</se:Rule>");
else
snprintf(szTmp, sizeof(szTmp), "%s\n", "</Rule>");
msStringBufferAppend(sb, nVersion > OWS_1_0_0 ? "</se:Rule>\n" : "</Rule>\n");
}
}

pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msStringBufferAppend(sb, nVersion > OWS_1_0_0 ? "</se:FeatureTypeStyle>\n" : "</FeatureTypeStyle>\n");
msStringBufferAppend(sb, "</UserStyle>\n");
}

#endif

}
}
if (pszWfsFilterEncoded)
msFree(pszWfsFilterEncoded);
if (nVersion > OWS_1_0_0)
snprintf(szTmp, sizeof(szTmp), "%s\n", "</se:FeatureTypeStyle>");
else
snprintf(szTmp, sizeof(szTmp), "%s\n", "</FeatureTypeStyle>");
/************************************************************************/
/* msSLDGenerateSLDLayer */
/* */
/* Genrate an SLD XML string based on the layer's classes. */
/************************************************************************/
char *msSLDGenerateSLDLayer(layerObj *psLayer, int nVersion)
{
#if defined(USE_WMS_SVR) || defined (USE_WFS_SVR) || defined (USE_WCS_SVR) || defined(USE_SOS_SVR)

#ifdef USE_OGR
const char *pszWMSLayerName = NULL;
msStringBuffer* sb = msStringBufferAlloc();

if (psLayer &&
(psLayer->status == MS_ON || psLayer->status == MS_DEFAULT) &&
(psLayer->type == MS_LAYER_POINT ||
psLayer->type == MS_LAYER_LINE ||
psLayer->type == MS_LAYER_POLYGON )) {

pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msStringBufferAppend(sb, "<NamedLayer>\n");

snprintf(szTmp, sizeof(szTmp), "%s\n", "</UserStyle>");
pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
pszWMSLayerName = msOWSLookupMetadata(&(psLayer->metadata), "MO", "name");
msSLDAppendName(sb,
pszWMSLayerName ? pszWMSLayerName :
psLayer->name ? psLayer->name :
"NamedLayer",
nVersion);

snprintf(szTmp, sizeof(szTmp), "%s\n", "</NamedLayer>");
pszFinalSLD = msStringConcatenate(pszFinalSLD, szTmp);
msSLDGenerateUserStyle(sb, psLayer, nVersion);

msStringBufferAppend(sb, "</NamedLayer>\n");
}
return pszFinalSLD;
return msStringBufferReleaseStringAndFree(sb);


#else

0 comments on commit 2107829

Please sign in to comment.