@@ -60,7 +60,7 @@ extern parseResultObj yypresult; /* result of parsing, true/false */
60
60
/* msGetClass_String() */
61
61
/************************************************************************/
62
62
63
- static int msGetClass_String ( layerObj * layer , colorObj * color , const char * pixel_value )
63
+ static int msGetClass_String ( layerObj * layer , colorObj * color , const char * pixel_value , int firstClassToTry )
64
64
65
65
{
66
66
int i ;
@@ -80,9 +80,18 @@ static int msGetClass_String( layerObj *layer, colorObj *color, const char *pixe
80
80
/* Setup values list for expressions. */
81
81
/* -------------------------------------------------------------------- */
82
82
numitems = 4 ;
83
- sprintf ( red_value , "%d" , color -> red );
84
- sprintf ( green_value , "%d" , color -> green );
85
- sprintf ( blue_value , "%d" , color -> blue );
83
+ if ( color -> red == -1 && color -> green == -1 && color -> blue == -1 )
84
+ {
85
+ strcpy (red_value , "-1" );
86
+ strcpy (green_value , "-1" );
87
+ strcpy (blue_value , "-1" );
88
+ }
89
+ else
90
+ {
91
+ sprintf ( red_value , "%d" , color -> red );
92
+ sprintf ( green_value , "%d" , color -> green );
93
+ sprintf ( blue_value , "%d" , color -> blue );
94
+ }
86
95
87
96
item_values [0 ] = (char * )pixel_value ;
88
97
item_values [1 ] = red_value ;
@@ -92,18 +101,24 @@ static int msGetClass_String( layerObj *layer, colorObj *color, const char *pixe
92
101
/* -------------------------------------------------------------------- */
93
102
/* Loop over classes till we find a match. */
94
103
/* -------------------------------------------------------------------- */
95
- for (i = 0 ; i < layer -> numclasses ; i ++ ) {
104
+ for (i = (firstClassToTry < 0 ) ? 0 : -1 ; i < layer -> numclasses ; i ++ ) {
105
+
106
+ int idx = i ;
107
+ if ( i < 0 )
108
+ idx = firstClassToTry ;
109
+ else if ( i == firstClassToTry )
110
+ continue ;
96
111
97
112
/* check for correct classgroup, if set */
98
- if ( layer -> class [i ]-> group && layer -> classgroup &&
99
- strcasecmp (layer -> class [i ]-> group , layer -> classgroup ) != 0 )
113
+ if ( layer -> class [idx ]-> group && layer -> classgroup &&
114
+ strcasecmp (layer -> class [idx ]-> group , layer -> classgroup ) != 0 )
100
115
continue ;
101
116
102
117
/* Empty expression - always matches */
103
- if (layer -> class [i ]-> expression .string == NULL )
118
+ if (layer -> class [idx ]-> expression .string == NULL )
104
119
return (i );
105
120
106
- switch (layer -> class [i ]-> expression .type ) {
121
+ switch (layer -> class [idx ]-> expression .type ) {
107
122
108
123
/* -------------------------------------------------------------------- */
109
124
/* Simple string match */
@@ -114,22 +129,22 @@ static int msGetClass_String( layerObj *layer, colorObj *color, const char *pixe
114
129
while ( * tmpstr1 == ' ' )
115
130
tmpstr1 ++ ;
116
131
117
- if (strcmp (layer -> class [i ]-> expression .string , tmpstr1 ) == 0 ) return (i ); /* matched */
132
+ if (strcmp (layer -> class [idx ]-> expression .string , tmpstr1 ) == 0 ) return (idx ); /* matched */
118
133
break ;
119
134
120
135
/* -------------------------------------------------------------------- */
121
136
/* Regular expression. Rarely used for raster. */
122
137
/* -------------------------------------------------------------------- */
123
138
case (MS_REGEX ):
124
- if (!layer -> class [i ]-> expression .compiled ) {
125
- if (ms_regcomp (& (layer -> class [i ]-> expression .regex ), layer -> class [i ]-> expression .string , MS_REG_EXTENDED |MS_REG_NOSUB ) != 0 ) { /* compile the expression */
139
+ if (!layer -> class [idx ]-> expression .compiled ) {
140
+ if (ms_regcomp (& (layer -> class [idx ]-> expression .regex ), layer -> class [idx ]-> expression .string , MS_REG_EXTENDED |MS_REG_NOSUB ) != 0 ) { /* compile the expression */
126
141
msSetError (MS_REGEXERR , "Invalid regular expression." , "msGetClass()" );
127
142
return (-1 );
128
143
}
129
- layer -> class [i ]-> expression .compiled = MS_TRUE ;
144
+ layer -> class [idx ]-> expression .compiled = MS_TRUE ;
130
145
}
131
146
132
- if (ms_regexec (& (layer -> class [i ]-> expression .regex ), pixel_value , 0 , NULL , 0 ) == 0 ) return (i ); /* got a match */
147
+ if (ms_regexec (& (layer -> class [idx ]-> expression .regex ), pixel_value , 0 , NULL , 0 ) == 0 ) return (idx ); /* got a match */
133
148
break ;
134
149
135
150
/* -------------------------------------------------------------------- */
@@ -139,7 +154,7 @@ static int msGetClass_String( layerObj *layer, colorObj *color, const char *pixe
139
154
int status ;
140
155
parseObj p ;
141
156
shapeObj dummy_shape ;
142
- expressionObj * expression = & (layer -> class [i ]-> expression );
157
+ expressionObj * expression = & (layer -> class [idx ]-> expression );
143
158
144
159
dummy_shape .numvalues = numitems ;
145
160
dummy_shape .values = item_values ;
@@ -160,7 +175,7 @@ static int msGetClass_String( layerObj *layer, colorObj *color, const char *pixe
160
175
}
161
176
162
177
if ( p .result .intval )
163
- return i ;
178
+ return idx ;
164
179
break ;
165
180
}
166
181
}
@@ -179,7 +194,7 @@ int msGetClass(layerObj *layer, colorObj *color, int colormap_index)
179
194
180
195
snprintf ( pixel_value , sizeof (pixel_value ), "%d" , colormap_index );
181
196
182
- return msGetClass_String ( layer , color , pixel_value );
197
+ return msGetClass_String ( layer , color , pixel_value , -1 );
183
198
}
184
199
185
200
/************************************************************************/
@@ -190,6 +205,13 @@ int msGetClass(layerObj *layer, colorObj *color, int colormap_index)
190
205
/************************************************************************/
191
206
192
207
int msGetClass_FloatRGB (layerObj * layer , float fValue , int red , int green , int blue )
208
+ {
209
+ return msGetClass_FloatRGB_WithFirstClassToTry (
210
+ layer , fValue , red , green , blue , -1 );
211
+ }
212
+
213
+
214
+ int msGetClass_FloatRGB_WithFirstClassToTry (layerObj * layer , float fValue , int red , int green , int blue , int firstClassToTry )
193
215
{
194
216
char pixel_value [100 ];
195
217
colorObj color ;
@@ -200,7 +222,7 @@ int msGetClass_FloatRGB(layerObj *layer, float fValue, int red, int green, int b
200
222
201
223
snprintf ( pixel_value , sizeof (pixel_value ), "%18g" , fValue );
202
224
203
- return msGetClass_String ( layer , & color , pixel_value );
225
+ return msGetClass_String ( layer , & color , pixel_value , firstClassToTry );
204
226
}
205
227
206
228
#if defined(USE_GDAL )
0 commit comments