1 /******************************************************************************
2  * $Id$
3  *
4  * Project:  MapServer
5  * Purpose:  Primary MapServer include file.
6  * Author:   Steve Lime and the MapServer team.
7  *
8  ******************************************************************************
9  * Copyright (c) 1996-2005 Regents of the University of Minnesota.
10  *
11  * copy of this software and associated documentation files (the "Software"),
12  * to deal in the Software without restriction, including without limitation
13  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  * and/or sell copies of the Software, and to permit persons to whom the
15  * Software is furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies of this Software or works derived from this Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  * DEALINGS IN THE SOFTWARE.
27  *****************************************************************************/
28 
29 #ifndef MAP_H
30 #define MAP_H
31 
32 #include "mapserver-config.h"
33 
34 /*
35 ** Main includes. If a particular header was needed by several .c files then
36 ** I just put it here. What the hell, it works and it's all right here. -SDL-
37 */
38 #if defined(HAVE_STRCASESTR) && !defined(_GNU_SOURCE)
39 #define _GNU_SOURCE /* Required for <string.h> strcasestr() defn */
40 #endif
41 
42 #include <stdio.h>
43 #include <stdlib.h>
44 #include <string.h>
45 #include <math.h>
46 #include <time.h>
47 
48 #if defined(_WIN32) && !defined(__CYGWIN__)
49 #include <direct.h>
50 #include <memory.h>
51 #include <malloc.h>
52 #include <process.h>
53 #include <float.h>
54 #else
55 #include <unistd.h>
56 #endif
57 
58 #if defined(_WIN32) && !defined(__CYGWIN__)
59 #  define MS_DLL_EXPORT     __declspec(dllexport)
60 #define USE_MSFREE
61 #else
62 #define  MS_DLL_EXPORT
63 #endif
64 
65 #if defined(__GNUC__)
66 #define WARN_UNUSED __attribute__((warn_unused_result))
67 #define LIKELY(x)   __builtin_expect((x),1)
68 #define UNLIKELY(x) __builtin_expect((x),0)
69 #else
70 #define WARN_UNUSED
71 #define LIKELY(x) (x)
72 #define UNLIKELY(x) (x)
73 #endif
74 
75 /* definition of  ms_int32/ms_uint32 */
76 #include <limits.h>
77 #ifndef _WIN32
78 #include <stdint.h>
79 #endif
80 
81 #ifdef _WIN32
82 #ifndef SIZE_MAX
83 #ifdef _WIN64
84 #define SIZE_MAX _UI64_MAX
85 #else
86 #define SIZE_MAX UINT_MAX
87 #endif
88 #endif
89 #endif
90 
91 #if ULONG_MAX == 0xffffffff
92 typedef long            ms_int32;
93 typedef unsigned long   ms_uint32;
94 #elif UINT_MAX == 0xffffffff
95 typedef int             ms_int32;
96 typedef unsigned int    ms_uint32;
97 #else
98 typedef int32_t         ms_int32;
99 typedef uint32_t        ms_uint32;
100 #endif
101 
102 #if defined(_WIN32) && !defined(__CYGWIN__)
103 /* Need to use _vsnprintf() with VS2003 */
104 #define vsnprintf _vsnprintf
105 #endif
106 
107 #include "mapserver-api.h"
108 
109 #ifndef SWIG
110 /*forward declaration of rendering object*/
111 typedef struct rendererVTableObj rendererVTableObj;
112 typedef struct tileCacheObj tileCacheObj;
113 typedef struct textPathObj textPathObj;
114 typedef struct textRunObj textRunObj;
115 typedef struct glyph_element glyph_element;
116 typedef struct face_element face_element;
117 #endif
118 
119 
120 /* ms_bitarray is used by the bit mask in mapbit.c */
121 typedef ms_uint32 *     ms_bitarray;
122 typedef const ms_uint32 *ms_const_bitarray;
123 
124 #include "maperror.h"
125 #include "mapprimitive.h"
126 #include "mapshape.h"
127 #include "mapsymbol.h"
128 #include "maptree.h" /* quadtree spatial index */
129 #include "maphash.h"
130 #include "mapio.h"
131 #include <assert.h>
132 #include "mapproject.h"
133 #include "cgiutil.h"
134 
135 
136 #include <sys/types.h> /* regular expression support */
137 
138 /* The regex lib from the system and the regex lib from PHP needs to
139  * be separated here. We separate here via its directory location.
140  */
141 #include "mapregex.h"
142 
143 
144 #define CPL_SUPRESS_CPLUSPLUS
145 #include "ogr_api.h"
146 
147 
148 /* EQUAL and EQUALN are defined in cpl_port.h, so add them in here if ogr was not included */
149 
150 #ifndef EQUAL
151 #if defined(WIN32) || defined(WIN32CE)
152 #  define EQUAL(a,b)              (stricmp(a,b)==0)
153 #else
154 #  define EQUAL(a,b)              (strcasecmp(a,b)==0)
155 #endif
156 #endif
157 
158 #ifndef EQUALN
159 #if defined(WIN32) || defined(WIN32CE)
160 #  define EQUALN(a,b,n)           (strnicmp(a,b,n)==0)
161 #else
162 #  define EQUALN(a,b,n)           (strncasecmp(a,b,n)==0)
163 #endif
164 #endif
165 
166 
167 #if defined(_WIN32) && !defined(__CYGWIN__)
168 #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || !defined(_MSC_VER)
169 #define snprintf _snprintf
170 #endif
171 #endif
172 
173 #ifdef __cplusplus
174 extern "C" {
175 #endif
176 
177 // hide from swig or ruby will choke on the __FUNCTION__ name
178 #ifndef SWIG
179   /* Memory allocation check utility */
180 #ifndef __FUNCTION__
181 #   define __FUNCTION__ "MapServer"
182 #endif
183 #endif
184 
185 #define MS_CHECK_ALLOC(var, size, retval)     \
186     if (!var) {   \
187         msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", __FUNCTION__, \
188                    __FILE__, __LINE__, (unsigned int)(size));  \
189         return retval;                         \
190     }
191 
192 #define MS_CHECK_ALLOC_NO_RET(var, size)                                   \
193     if (!var) {                                                       \
194         msSetError(MS_MEMERR, "%s: %d: Out of memory allocating %u bytes.\n", __FUNCTION__, \
195                    __FILE__, __LINE__, (unsigned int)(size));                           \
196         return;                                                         \
197     }
198 
199   /* General defines, wrapable */
200 
201 #define MS_TRUE 1 /* logical control variables */
202 #define MS_FALSE 0
203 #define MS_UNKNOWN -1
204 #define MS_ON 1
205 #define MS_OFF 0
206 #define MS_DEFAULT 2
207 #define MS_EMBED 3
208 #define MS_DELETE 4
209 #define MS_YES 1
210 #define MS_NO 0
211 
212 
213   /* Number of layer, class and style ptrs to alloc at once in the
214      corresponding msGrow...() functions. Replaces former MS_MAXLAYERS,
215      MS_MAXCLASSES and MS_MAXSTYLES with dynamic allocation (see RFC-17). */
216 #define MS_LAYER_ALLOCSIZE 64
217 #define MS_CLASS_ALLOCSIZE 8
218 #define MS_STYLE_ALLOCSIZE 4
219 #define MS_LABEL_ALLOCSIZE 2 /* not too common */
220 
221 #define MS_MAX_LABEL_PRIORITY     10
222 #define MS_MAX_LABEL_FONTS     5
223 #define MS_DEFAULT_LABEL_PRIORITY 1
224 #define MS_LABEL_FORCE_GROUP 2 /* other values are MS_ON/MS_OFF */
225 
226   /* General defines, not wrapable */
227 #ifndef SWIG
228 #ifdef USE_XMLMAPFILE
229 #define MS_DEFAULT_MAPFILE_PATTERN "\\.(map|xml)$"
230 #define MS_DEFAULT_XMLMAPFILE_PATTERN "\\.xml$"
231 #else
232 #define MS_DEFAULT_MAPFILE_PATTERN "\\.map$"
233 #endif
234 #define MS_TEMPLATE_MAGIC_STRING "MapServer Template"
235 #define MS_TEMPLATE_EXPR "\\.(xml|wml|html|htm|svg|kml|gml|js|tmpl)$"
236 
237 #define MS_INDEX_EXTENSION ".qix"
238 
239 #define MS_QUERY_RESULTS_MAGIC_STRING "MapServer Query Results"
240 #define MS_QUERY_PARAMS_MAGIC_STRING "MapServer Query Params"
241 #define MS_QUERY_EXTENSION ".qy"
242 
243 #define MS_DEG_TO_RAD .0174532925199432958
244 #define MS_RAD_TO_DEG   57.29577951
245 
246 #define MS_DEFAULT_RESOLUTION 72
247 
248 #define MS_RED 0
249 #define MS_GREEN 1
250 #define MS_BLUE 2
251 
252 #define MS_MAXCOLORS 256
253 
254 #define MS_MISSING_DATA_IGNORE 0
255 #define MS_MISSING_DATA_FAIL 1
256 #define MS_MISSING_DATA_LOG 2
257 
258 #define MS_BUFFER_LENGTH 2048 /* maximum input line length */
259 #define MS_URL_LENGTH 1024
260 #define MS_MAXPATHLEN 1024
261 
262 #define MS_MAXIMAGESIZE_DEFAULT 4096
263 
264 #define MS_MAXPROJARGS 20
265 #define MS_MAXJOINS 20
266 #define MS_ITEMNAMELEN 32
267 #define MS_NAMELEN 20
268 
269 #define MS_MINSYMBOLSIZE 0   /* in pixels */
270 #define MS_MAXSYMBOLSIZE 500
271 
272 #define MS_MINSYMBOLWIDTH 0   /* in pixels */
273 #define MS_MAXSYMBOLWIDTH 32
274 
275 #define MS_URL 0 /* template types */
276 #define MS_FILE 1
277 
278 #define MS_MINFONTSIZE 4
279 #define MS_MAXFONTSIZE 256
280 
281 #define MS_LABELCACHEINITSIZE 100
282 #define MS_LABELCACHEINCREMENT 10
283 
284 #define MS_RESULTCACHEINITSIZE 10
285 #define MS_RESULTCACHEINCREMENT 10
286 
287 #define MS_FEATUREINITSIZE 10 /* how many points initially can a feature have */
288 #define MS_FEATUREINCREMENT 10
289 
290 #define MS_EXPRESSION 2000 /* todo: make this an enum */
291 #define MS_REGEX 2001
292 #define MS_STRING 2002
293 #define MS_NUMBER 2003
294 #define MS_COMMENT 2004
295 #define MS_IREGEX 2005
296 #define MS_ISTRING 2006
297 #define MS_BINDING 2007
298 #define MS_LIST 2008
299 
300   /* string split flags */
301 #define MS_HONOURSTRINGS      0x0001
302 #define MS_ALLOWEMPTYTOKENS   0x0002
303 #define MS_PRESERVEQUOTES     0x0004
304 #define MS_PRESERVEESCAPES    0x0008
305 #define MS_STRIPLEADSPACES    0x0010
306 #define MS_STRIPENDSPACES     0x0020
307 
308   /* boolean options for the expression object. */
309 #define MS_EXP_INSENSITIVE 1
310 
311   /* General macro definitions */
312 #define MS_MIN(a,b) (((a)<(b))?(a):(b))
313 #define MS_MAX(a,b) (((a)>(b))?(a):(b))
314 #define MS_ABS(a) (((a)<0) ? -(a) : (a))
315 #define MS_SGN(a) (((a)<0) ? -1 : 1)
316 
317 #define MS_STRING_IS_NULL_OR_EMPTY(s) ((!s || s[0] == '\0') ? MS_TRUE:MS_FALSE)
318 
319 #define MS_NINT_GENERIC(x) ((x) >= 0.0 ? ((long) ((x)+.5)) : ((long) ((x)-.5)))
320 
321 #ifdef _MSC_VER
322 #define msIsNan(x) _isnan(x)
323 #else
324 #define msIsNan(x) isnan(x)
325 #endif
326 
327   /* see http://mega-nerd.com/FPcast/ for some discussion of fast
328      conversion to nearest int.  We avoid lrint() for now because it
329      would be hard to include math.h "properly". */
330 
331 #if defined(HAVE_LRINT) && !defined(USE_GENERIC_MS_NINT)
332 #   define MS_NINT(x) lrint(x)
333   /*#   define MS_NINT(x) lround(x) */
334 /* note that lrint rounds .5 to the nearest *even* integer, i.e. lrint(0.5)=0,lrint(1.5)=2 */
335 #elif defined(_MSC_VER) && defined(_WIN32) && !defined(USE_GENERIC_MS_NINT)
336   static __inline long int MS_NINT (double flt)
337   {
338     int intgr;
339 
340     _asm {
341       fld flt
342       fistp intgr
343     } ;
344 
345     return intgr ;
346   }
347 #elif defined(i386) && defined(__GNUC_PREREQ) && !defined(USE_GENERIC_MS_NINT)
348   static __inline long int MS_NINT( double __x )
349   {
350     long int __lrintres;
351     __asm__ __volatile__
352     ("fistpl %0"
353      : "=m" (__lrintres) : "t" (__x) : "st");
354     return __lrintres;
355   }
356 #else
357 #  define MS_NINT(x)      MS_NINT_GENERIC(x)
358 #endif
359 
360 
361   /* #define MS_VALID_EXTENT(minx, miny, maxx, maxy)  (((minx<maxx) && (miny<maxy))?MS_TRUE:MS_FALSE) */
362 #define MS_VALID_EXTENT(rect)  (((rect.minx < rect.maxx && rect.miny < rect.maxy))?MS_TRUE:MS_FALSE)
363 
364 #define MS_INIT_COLOR(color,r,g,b,a) { (color).red = r; (color).green = g; (color).blue = b; (color).alpha=a; }
365 #define MS_VALID_COLOR(color) (((color).red==-1 || (color).green==-1 || (color).blue==-1)?MS_FALSE:MS_TRUE)
366 #define MS_COMPARE_COLOR(color1, color2) (((color2).red==(color1).red && (color2).green==(color1).green && (color2).blue==(color1).blue)?MS_TRUE:MS_FALSE)
367 #define MS_TRANSPARENT_COLOR(color) (((color).alpha==0 || (color).red==-255 || (color).green==-255 || (color).blue==-255)?MS_TRUE:MS_FALSE)
368 #define MS_COMPARE_COLORS(a,b) (((a).red!=(b).red || (a).green!=(b).green || (a).blue!=(b).blue)?MS_FALSE:MS_TRUE)
369 #define MS_COLOR_GETRGB(color) (MS_VALID_COLOR(color)?((color).red *0x10000 + (color).green *0x100 + (color).blue):-1)
370 
371 #define MS_IMAGE_MIME_TYPE(format) (format->mimetype ? format->mimetype : "unknown")
372 #define MS_IMAGE_EXTENSION(format)  (format->extension ? format->extension : "unknown")
373 #define MS_DRIVER_SWF(format) (strncasecmp((format)->driver,"swf",3)==0)
374 #define MS_DRIVER_GDAL(format)  (strncasecmp((format)->driver,"gdal/",5)==0)
375 #define MS_DRIVER_IMAGEMAP(format)  (strncasecmp((format)->driver,"imagemap",8)==0)
376 #define MS_DRIVER_AGG(format) (strncasecmp((format)->driver,"agg/",4)==0)
377 #define MS_DRIVER_MVT(format) (strncasecmp((format)->driver,"mvt",3)==0)
378 #define MS_DRIVER_CAIRO(format) (strncasecmp((format)->driver,"cairo/",6)==0)
379 #define MS_DRIVER_OGL(format) (strncasecmp((format)->driver,"ogl/",4)==0)
380 #define MS_DRIVER_TEMPLATE(format) (strncasecmp((format)->driver,"template",8)==0)
381 
382 #endif /*SWIG*/
383 
384 #define MS_RENDER_WITH_SWF      2
385 #define MS_RENDER_WITH_RAWDATA  3
386 #define MS_RENDER_WITH_IMAGEMAP 5
387 #define MS_RENDER_WITH_TEMPLATE 8 /* query results only */
388 #define MS_RENDER_WITH_OGR 16
389 
390 #define MS_RENDER_WITH_PLUGIN 100
391 #define MS_RENDER_WITH_CAIRO_RASTER   101
392 #define MS_RENDER_WITH_CAIRO_PDF 102
393 #define MS_RENDER_WITH_CAIRO_SVG 103
394 #define MS_RENDER_WITH_OGL      104
395 #define MS_RENDER_WITH_AGG 105
396 #define MS_RENDER_WITH_KML 106
397 #define MS_RENDER_WITH_UTFGRID 107
398 #define MS_RENDER_WITH_MVT 108
399 
400 #ifndef SWIG
401 
402 #define MS_RENDERER_SWF(format) ((format)->renderer == MS_RENDER_WITH_SWF)
403 #define MS_RENDERER_RAWDATA(format) ((format)->renderer == MS_RENDER_WITH_RAWDATA)
404 #define MS_RENDERER_IMAGEMAP(format) ((format)->renderer == MS_RENDER_WITH_IMAGEMAP)
405 #define MS_RENDERER_TEMPLATE(format) ((format)->renderer == MS_RENDER_WITH_TEMPLATE)
406 #define MS_RENDERER_KML(format) ((format)->renderer == MS_RENDER_WITH_KML)
407 #define MS_RENDERER_OGR(format) ((format)->renderer == MS_RENDER_WITH_OGR)
408 #define MS_RENDERER_MVT(format) ((format)->renderer == MS_RENDER_WITH_MVT)
409 
410 #define MS_RENDERER_PLUGIN(format) ((format)->renderer > MS_RENDER_WITH_PLUGIN)
411 
412 #define MS_CELLSIZE(min,max,d) (((max) - (min))/((d)-1)) /* where min/max are from an MapServer pixel center-to-pixel center extent */
413 #define MS_OWS_CELLSIZE(min,max,d) (((max) - (min))/(d)) /* where min/max are from an OGC pixel outside edge-to-pixel outside edge extent */
414 #define MS_MAP2IMAGE_X(x,minx,cx) (MS_NINT(((x) - (minx))/(cx)))
415 #define MS_MAP2IMAGE_Y(y,maxy,cy) (MS_NINT(((maxy) - (y))/(cy)))
416 #define MS_IMAGE2MAP_X(x,minx,cx) ((minx) + (cx)*(x))
417 #define MS_IMAGE2MAP_Y(y,maxy,cy) ((maxy) - (cy)*(y))
418 
419   /* these versions of MS_MAP2IMAGE takes 1/cellsize and is much faster */
420 #define MS_MAP2IMAGE_X_IC(x,minx,icx) (MS_NINT(((x) - (minx))*(icx)))
421 #define MS_MAP2IMAGE_Y_IC(y,maxy,icy) (MS_NINT(((maxy) - (y))*(icy)))
422 #define MS_MAP2IMAGE_XCELL_IC(x,minx,icx) ((int)(((x) - (minx))*(icx)))
423 #define MS_MAP2IMAGE_YCELL_IC(y,maxy,icy) ((int)(((maxy) - (y))*(icy)))
424 
425 #define MS_MAP2IMAGE_X_IC_DBL(x,minx,icx) (((x) - (minx))*(icx))
426 #define MS_MAP2IMAGE_Y_IC_DBL(y,maxy,icy) (((maxy) - (y))*(icy))
427 
428 #define MS_MAP2IMAGE_X_IC_SNAP(x,minx,icx,res) ((MS_NINT(((x) - (minx))*(icx)*(res)))/(res))
429 #define MS_MAP2IMAGE_Y_IC_SNAP(y,maxy,icy,res) ((MS_NINT(((maxy) - (y))*(icy)*(res)))/(res))
430 
431   /* For CARTO symbols */
432 #define MS_PI    3.14159265358979323846
433 #define MS_PI2   1.57079632679489661923  /* (MS_PI / 2) */
434 #define MS_3PI2  4.71238898038468985769  /* (3 * MS_PI2) */
435 #define MS_2PI   6.28318530717958647693  /* (2 * MS_PI) */
436 
437 #define MS_ENCRYPTION_KEY_SIZE  16   /* Key size: 128 bits = 16 bytes */
438 
439 #define GET_LAYER(map, pos) map->layers[pos]
440 #define GET_CLASS(map, lid, cid) map->layers[lid]->class[cid]
441 
442 #ifdef USE_THREAD
443 #if defined(HAVE_SYNC_FETCH_AND_ADD)
444 #define MS_REFCNT_INCR(obj) __sync_fetch_and_add(&obj->refcount, +1)
445 #define MS_REFCNT_DECR(obj) __sync_sub_and_fetch(&obj->refcount, +1)
446 #define MS_REFCNT_INIT(obj) obj->refcount=1, __sync_synchronize()
447 #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64))
448 #include <intrin.h>
449 #pragma intrinsic (_InterlockedExchangeAdd)
450 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
451 #define MS_REFCNT_INCR(obj) ( _InterlockedExchangeAdd((long*)(&obj->refcount), (long)(+1)) +1 )
452 #define MS_REFCNT_DECR(obj) ( _InterlockedExchangeAdd((long*)(&obj->refcount), (long)(-1)) -1 )
453 #define MS_REFCNT_INIT(obj) obj->refcount=1
454 #else
455 #define MS_REFCNT_INCR(obj) ( _InterlockedExchangeAdd((volatile long*)(&obj->refcount), (long)(+1)) +1 )
456 #define MS_REFCNT_DECR(obj) ( _InterlockedExchangeAdd((volatile long*)(&obj->refcount), (long)(-1)) -1 )
457 #define MS_REFCNT_INIT(obj) obj->refcount=1
458 #endif
459 #elif defined(__MINGW32__) && defined(__i386__)
460 #define MS_REFCNT_INCR(obj) ( InterlockedExchangeAdd((long*)(&obj->refcount), (long)(+1)) +1 )
461 #define MS_REFCNT_DECR(obj) ( InterlockedExchangeAdd((long*)(&obj->refcount), (long)(-1)) -1 )
462 #define MS_REFCNT_INIT(obj) obj->refcount=1
463 #else
464   // unsafe fallback
465 #define MS_REFCNT_INCR(obj) obj->refcount++
466 #define MS_REFCNT_DECR(obj) (--(obj->refcount))
467 #define MS_REFCNT_INIT(obj) obj->refcount=1
468 #endif // close if defined(_MSC..
469 #else /*USE_THREAD*/
470 #define MS_REFCNT_INCR(obj) obj->refcount++
471 #define MS_REFCNT_DECR(obj) (--(obj->refcount))
472 #define MS_REFCNT_INIT(obj) obj->refcount=1
473 #endif /*USE_THREAD*/
474 
475 #define MS_REFCNT_DECR_IS_NOT_ZERO(obj) (MS_REFCNT_DECR(obj))>0
476 #define MS_REFCNT_DECR_IS_ZERO(obj) (MS_REFCNT_DECR(obj))<=0
477 
478 #define MS_IS_VALID_ARRAY_INDEX(index, size) ((index<0 || index>=size)?MS_FALSE:MS_TRUE)
479 
480 #define MS_CONVERT_UNIT(src_unit, dst_unit, value) (value * msInchesPerUnit(src_unit,0) / msInchesPerUnit(dst_unit,0))
481 
482 #define MS_INIT_INVALID_RECT { -1e300, -1e300, 1e300, 1e300 }
483 
484 #endif
485 
486   /* General enumerated types - needed by scripts */
487   enum MS_FILE_TYPE {MS_FILE_MAP, MS_FILE_SYMBOL};
488   enum MS_UNITS {MS_INCHES, MS_FEET, MS_MILES, MS_METERS, MS_KILOMETERS, MS_DD, MS_PIXELS, MS_PERCENTAGES, MS_NAUTICALMILES};
489   enum MS_SHAPE_TYPE {MS_SHAPE_POINT, MS_SHAPE_LINE, MS_SHAPE_POLYGON, MS_SHAPE_NULL};
490   enum MS_LAYER_TYPE {MS_LAYER_POINT, MS_LAYER_LINE, MS_LAYER_POLYGON, MS_LAYER_RASTER, MS_LAYER_ANNOTATION /* only used for parser backwards compatibility */, MS_LAYER_QUERY, MS_LAYER_CIRCLE, MS_LAYER_TILEINDEX, MS_LAYER_CHART};
491   enum MS_FONT_TYPE {MS_TRUETYPE, MS_BITMAP};
492   enum MS_RENDER_MODE {MS_FIRST_MATCHING_CLASS, MS_ALL_MATCHING_CLASSES};
493 
494 #define MS_POSITIONS_LENGTH 14
495   enum MS_POSITIONS_ENUM {MS_UL=101, MS_LR, MS_UR, MS_LL, MS_CR, MS_CL, MS_UC, MS_LC, MS_CC, MS_AUTO, MS_XY, MS_NONE, MS_AUTO2,MS_FOLLOW};
496 #define MS_TINY 5
497 #define MS_SMALL 7
498 #define MS_MEDIUM 10
499 #define MS_LARGE 13
500 #define MS_GIANT 16
501   enum MS_QUERYMAP_STYLES {MS_NORMAL, MS_HILITE, MS_SELECTED};
502   enum MS_CONNECTION_TYPE {MS_INLINE, MS_SHAPEFILE, MS_TILED_SHAPEFILE, MS_UNUSED_2, MS_OGR, MS_UNUSED_1, MS_POSTGIS, MS_WMS, MS_ORACLESPATIAL, MS_WFS, MS_GRATICULE, MS_MYSQL, MS_RASTER, MS_PLUGIN, MS_UNION, MS_UVRASTER, MS_CONTOUR, MS_KERNELDENSITY };
503 #define IS_THIRDPARTY_LAYER_CONNECTIONTYPE(type) ((type) == MS_UNION || (type) == MS_KERNELDENSITY)
504   enum MS_JOIN_CONNECTION_TYPE {MS_DB_XBASE, MS_DB_CSV, MS_DB_MYSQL, MS_DB_ORACLE, MS_DB_POSTGRES};
505   enum MS_JOIN_TYPE {MS_JOIN_ONE_TO_ONE, MS_JOIN_ONE_TO_MANY};
506 
507 #define MS_SINGLE 0 /* modes for searching (spatial/database) */
508 #define MS_MULTIPLE 1
509 
510   enum MS_QUERY_MODE {MS_QUERY_SINGLE, MS_QUERY_MULTIPLE};
511   enum MS_QUERY_TYPE {MS_QUERY_IS_NULL, MS_QUERY_BY_POINT, MS_QUERY_BY_RECT, MS_QUERY_BY_SHAPE, MS_QUERY_BY_ATTRIBUTE, MS_QUERY_BY_INDEX, MS_QUERY_BY_FILTER};
512 
513   enum MS_ALIGN_VALUE {MS_ALIGN_DEFAULT, MS_ALIGN_LEFT, MS_ALIGN_CENTER, MS_ALIGN_RIGHT};
514 
515   enum MS_CAPS_JOINS_AND_CORNERS {MS_CJC_NONE, MS_CJC_BEVEL, MS_CJC_BUTT, MS_CJC_MITER, MS_CJC_ROUND, MS_CJC_SQUARE, MS_CJC_TRIANGLE};
516 
517 #define MS_CJC_DEFAULT_CAPS MS_CJC_ROUND
518 #define MS_CJC_DEFAULT_JOINS MS_CJC_NONE
519 #define MS_CJC_DEFAULT_JOIN_MAXSIZE 3
520 
521   enum MS_RETURN_VALUE {MS_SUCCESS, MS_FAILURE, MS_DONE};
522   enum MS_IMAGEMODE { MS_IMAGEMODE_PC256, MS_IMAGEMODE_RGB, MS_IMAGEMODE_RGBA, MS_IMAGEMODE_INT16, MS_IMAGEMODE_FLOAT32, MS_IMAGEMODE_BYTE, MS_IMAGEMODE_FEATURE, MS_IMAGEMODE_NULL };
523 
524   enum MS_GEOS_OPERATOR {MS_GEOS_EQUALS, MS_GEOS_DISJOINT, MS_GEOS_TOUCHES, MS_GEOS_OVERLAPS, MS_GEOS_CROSSES, MS_GEOS_INTERSECTS, MS_GEOS_WITHIN, MS_GEOS_CONTAINS, MS_GEOS_BEYOND, MS_GEOS_DWITHIN};
525 #define MS_FILE_DEFAULT MS_FILE_MAP
526 
527 #if defined(_MSC_VER) && (_MSC_VER <= 1310)
528 #define MS_DEBUG msDebug2
529 #else
530 #ifdef USE_EXTENDED_DEBUG
531 #define MS_DEBUG(level,elt,fmt, ...) if((elt)->debug >= (level)) msDebug(fmt,##__VA_ARGS__)
532 #else
533 #define MS_DEBUG(level,elt,fmt, ...) /* no-op */
534 #endif
535 #endif
536 
537   /* coordinate to pixel simplification modes, used in msTransformShape */
538   enum MS_TRANSFORM_MODE {
539     MS_TRANSFORM_NONE, /* no geographic to pixel transformation */
540     MS_TRANSFORM_ROUND, /* round to integer, might create degenerate geometries (used for GD)*/
541     MS_TRANSFORM_SNAPTOGRID, /* snap to a grid, should be user configurable in the future*/
542     MS_TRANSFORM_FULLRESOLUTION, /* keep full resolution */
543     MS_TRANSFORM_SIMPLIFY /* keep full resolution */
544   };
545 
546   typedef enum {
547         MS_COMPOP_CLEAR,
548         MS_COMPOP_SRC,
549         MS_COMPOP_DST,
550         MS_COMPOP_SRC_OVER,
551         MS_COMPOP_DST_OVER,
552         MS_COMPOP_SRC_IN,
553         MS_COMPOP_DST_IN,
554         MS_COMPOP_SRC_OUT,
555         MS_COMPOP_DST_OUT,
556         MS_COMPOP_SRC_ATOP,
557         MS_COMPOP_DST_ATOP,
558         MS_COMPOP_XOR,
559         MS_COMPOP_PLUS,
560         MS_COMPOP_MINUS,
561         MS_COMPOP_MULTIPLY,
562         MS_COMPOP_SCREEN,
563         MS_COMPOP_OVERLAY,
564         MS_COMPOP_DARKEN,
565         MS_COMPOP_LIGHTEN,
566         MS_COMPOP_COLOR_DODGE,
567         MS_COMPOP_COLOR_BURN,
568         MS_COMPOP_HARD_LIGHT,
569         MS_COMPOP_SOFT_LIGHT,
570         MS_COMPOP_DIFFERENCE,
571         MS_COMPOP_EXCLUSION,
572         MS_COMPOP_CONTRAST,
573         MS_COMPOP_INVERT,
574         MS_COMPOP_INVERT_RGB
575   } CompositingOperation;
576 
577   typedef struct _CompositingFilter{
578     char *filter;
579     struct _CompositingFilter *next;
580   } CompositingFilter;
581 
582   typedef struct _LayerCompositer{
583     CompositingOperation comp_op;
584     int opacity;
585     CompositingFilter *filter;
586     struct _LayerCompositer *next;
587   } LayerCompositer;
588 
589 #ifndef SWIG
590   /* Filter object */
591   typedef enum {
592     FILTER_NODE_TYPE_UNDEFINED = -1,
593     FILTER_NODE_TYPE_LOGICAL = 0,
594     FILTER_NODE_TYPE_SPATIAL = 1,
595     FILTER_NODE_TYPE_COMPARISON = 2,
596     FILTER_NODE_TYPE_PROPERTYNAME = 3,
597     FILTER_NODE_TYPE_BBOX = 4,
598     FILTER_NODE_TYPE_LITERAL = 5,
599     FILTER_NODE_TYPE_BOUNDARY = 6,
600     FILTER_NODE_TYPE_GEOMETRY_POINT = 7,
601     FILTER_NODE_TYPE_GEOMETRY_LINE = 8,
602     FILTER_NODE_TYPE_GEOMETRY_POLYGON = 9,
603     FILTER_NODE_TYPE_FEATUREID = 10,
604     FILTER_NODE_TYPE_TEMPORAL = 11,
605     FILTER_NODE_TYPE_TIME_PERIOD = 12
606   } FilterNodeType;
607 
608 
609   /************************************************************************/
610   /*                          FilterEncodingNode                          */
611   /************************************************************************/
612 
613   typedef struct _FilterNode {
614     FilterNodeType      eType;
615     char                *pszValue;
616     void                *pOther;
617     char                *pszSRS;
618     struct _FilterNode  *psLeftNode;
619     struct _FilterNode  *psRightNode;
620   } FilterEncodingNode;
621 #endif /*SWIG*/
622 
623   /* Define supported bindings here (only covers existing bindings at first). Not accessible directly using MapScript. */
624 #define MS_STYLE_BINDING_LENGTH 12
625   enum MS_STYLE_BINDING_ENUM { MS_STYLE_BINDING_SIZE, MS_STYLE_BINDING_WIDTH, MS_STYLE_BINDING_ANGLE, MS_STYLE_BINDING_COLOR, MS_STYLE_BINDING_OUTLINECOLOR, MS_STYLE_BINDING_SYMBOL, MS_STYLE_BINDING_OUTLINEWIDTH, MS_STYLE_BINDING_OPACITY, MS_STYLE_BINDING_OFFSET_X, MS_STYLE_BINDING_OFFSET_Y, MS_STYLE_BINDING_POLAROFFSET_PIXEL, MS_STYLE_BINDING_POLAROFFSET_ANGLE };
626 #define MS_LABEL_BINDING_LENGTH 12
627   enum MS_LABEL_BINDING_ENUM { MS_LABEL_BINDING_SIZE, MS_LABEL_BINDING_ANGLE, MS_LABEL_BINDING_COLOR, MS_LABEL_BINDING_OUTLINECOLOR, MS_LABEL_BINDING_FONT, MS_LABEL_BINDING_PRIORITY, MS_LABEL_BINDING_POSITION, MS_LABEL_BINDING_SHADOWSIZEX, MS_LABEL_BINDING_SHADOWSIZEY, MS_LABEL_BINDING_OFFSET_X, MS_LABEL_BINDING_OFFSET_Y,MS_LABEL_BINDING_ALIGN };
628 
629   /************************************************************************/
630   /*                         attributeBindingObj                          */
631   /************************************************************************/
632 #ifndef SWIG
633   typedef struct {
634     char *item;
635     int index;
636   } attributeBindingObj;
637 #endif /*SWIG*/
638 
639   /************************************************************************/
640   /*                             labelPathObj                             */
641   /*                                                                      */
642   /*      Label path object - used to hold path and bounds of curved      */
643   /*      labels - Bug #1620 implementation.                              */
644   /************************************************************************/
645 #ifndef SWIG
646   typedef struct {
647     multipointObj path;
648     shapeObj bounds;
649     double *angles;
650   } labelPathObj;
651 #endif /*SWIG*/
652 
653   /************************************************************************/
654   /*                              fontSetObj                              */
655   /*                                                                      */
656   /*      used to hold aliases for TRUETYPE fonts                         */
657   /************************************************************************/
658 
659   typedef struct {
660 #ifdef SWIG
661     %immutable;
662 #endif
663     char *filename;
664     int numfonts;
665     hashTableObj fonts;
666 #ifdef SWIG
667     %mutable;
668 #endif
669 
670 #ifndef SWIG
671     struct mapObj *map;
672 #endif
673   } fontSetObj;
674 
675   /************************************************************************/
676   /*                         featureListNodeObj                           */
677   /*                                                                      */
678   /*      for inline features, shape caches and queries                   */
679   /************************************************************************/
680 #ifndef SWIG
681   typedef struct listNode {
682     shapeObj shape;
683     struct listNode *next;
684     struct listNode *tailifhead; /* this is the tail node in the list, if this is the head element, otherwise NULL */
685   } featureListNodeObj;
686 
687   typedef featureListNodeObj * featureListNodeObjPtr;
688 #endif
689 
690   /************************************************************************/
691   /*                              paletteObj                              */
692   /*                                                                      */
693   /*      used to hold colors while a map file is read                    */
694   /************************************************************************/
695 #ifndef SWIG
696   typedef struct {
697     colorObj colors[MS_MAXCOLORS-1];
698     int      colorvalue[MS_MAXCOLORS-1];
699     int numcolors;
700   } paletteObj;
701 #endif
702 
703   /************************************************************************/
704   /*                     expressionObj & tokenObj                         */
705   /************************************************************************/
706 
707   enum MS_TOKEN_LOGICAL_ENUM { MS_TOKEN_LOGICAL_AND=300, MS_TOKEN_LOGICAL_OR, MS_TOKEN_LOGICAL_NOT };
708   enum MS_TOKEN_LITERAL_ENUM { MS_TOKEN_LITERAL_NUMBER=310, MS_TOKEN_LITERAL_STRING, MS_TOKEN_LITERAL_TIME, MS_TOKEN_LITERAL_SHAPE, MS_TOKEN_LITERAL_BOOLEAN };
709   enum MS_TOKEN_COMPARISON_ENUM {
710     MS_TOKEN_COMPARISON_EQ=320, MS_TOKEN_COMPARISON_NE, MS_TOKEN_COMPARISON_GT, MS_TOKEN_COMPARISON_LT, MS_TOKEN_COMPARISON_LE, MS_TOKEN_COMPARISON_GE, MS_TOKEN_COMPARISON_IEQ,
711     MS_TOKEN_COMPARISON_RE, MS_TOKEN_COMPARISON_IRE,
712     MS_TOKEN_COMPARISON_IN, MS_TOKEN_COMPARISON_LIKE,
713     MS_TOKEN_COMPARISON_INTERSECTS, MS_TOKEN_COMPARISON_DISJOINT, MS_TOKEN_COMPARISON_TOUCHES, MS_TOKEN_COMPARISON_OVERLAPS, MS_TOKEN_COMPARISON_CROSSES, MS_TOKEN_COMPARISON_WITHIN, MS_TOKEN_COMPARISON_CONTAINS, MS_TOKEN_COMPARISON_EQUALS, MS_TOKEN_COMPARISON_BEYOND, MS_TOKEN_COMPARISON_DWITHIN
714   };
715   enum MS_TOKEN_FUNCTION_ENUM {
716     MS_TOKEN_FUNCTION_LENGTH=350, MS_TOKEN_FUNCTION_TOSTRING, MS_TOKEN_FUNCTION_COMMIFY, MS_TOKEN_FUNCTION_AREA, MS_TOKEN_FUNCTION_ROUND, MS_TOKEN_FUNCTION_FROMTEXT,
717     MS_TOKEN_FUNCTION_BUFFER, MS_TOKEN_FUNCTION_DIFFERENCE, MS_TOKEN_FUNCTION_SIMPLIFY, MS_TOKEN_FUNCTION_SIMPLIFYPT, MS_TOKEN_FUNCTION_GENERALIZE, MS_TOKEN_FUNCTION_SMOOTHSIA, MS_TOKEN_FUNCTION_JAVASCRIPT,
718     MS_TOKEN_FUNCTION_UPPER, MS_TOKEN_FUNCTION_LOWER, MS_TOKEN_FUNCTION_INITCAP, MS_TOKEN_FUNCTION_FIRSTCAP
719   };
720   enum MS_TOKEN_BINDING_ENUM { MS_TOKEN_BINDING_DOUBLE=370, MS_TOKEN_BINDING_INTEGER, MS_TOKEN_BINDING_STRING, MS_TOKEN_BINDING_TIME, MS_TOKEN_BINDING_SHAPE, MS_TOKEN_BINDING_MAP_CELLSIZE, MS_TOKEN_BINDING_DATA_CELLSIZE };
721   enum MS_PARSE_TYPE_ENUM { MS_PARSE_TYPE_BOOLEAN, MS_PARSE_TYPE_STRING, MS_PARSE_TYPE_SHAPE };
722 
723 #ifndef SWIG
724   typedef union {
725     int intval;
726     char *strval;
727     shapeObj *shpval;
728   } parseResultObj;
729 
730   typedef union {
731     double dblval;
732     int intval;
733     char *strval;
734     struct tm tmval;
735     shapeObj *shpval;
736     attributeBindingObj bindval;
737   } tokenValueObj;
738 
739   typedef struct tokenListNode {
740     int token;
741     tokenValueObj tokenval;
742     char *tokensrc; /* on occassion we may want to access to the original source string (e.g. date/time) */
743     struct tokenListNode *next;
744     struct tokenListNode *tailifhead; /* this is the tail node in the list if this is the head element, otherwise NULL */
745   } tokenListNodeObj;
746 
747   typedef tokenListNodeObj * tokenListNodeObjPtr;
748 
749   typedef struct {
750     char *string;
751     int type;
752     /* container for expression options such as case-insensitiveness */
753     /* This is a boolean container. */
754     int flags;
755 
756     /* logical expression options */
757     tokenListNodeObjPtr tokens;
758     tokenListNodeObjPtr curtoken;
759 
760     /* regular expression options */
761     ms_regex_t regex; /* compiled regular expression to be matched */
762     int compiled;
763 
764     char *native_string; /* RFC 91 */
765   } expressionObj;
766 
767   typedef struct {
768     colorObj *pixel; /* for raster layers */
769     shapeObj *shape; /* for vector layers */
770     double dblval; /* for map cellsize used by simplify */
771     double dblval2; /* for data cellsize */
772     expressionObj *expr; /* expression to be evaluated (contains tokens) */
773     int type; /* type of parse: boolean, string/text or shape/geometry */
774     parseResultObj result; /* parse result */
775   } parseObj;
776 #endif
777 
778   /* MS RFC 69*/
779   typedef struct {
780     double maxdistance; /* max distance between clusters */
781     double buffer;      /* the buffer size around the selection area */
782     char* region;       /* type of the cluster region (rectangle or ellipse) */
783 #ifndef SWIG
784     expressionObj group; /* expression to identify the groups */
785     expressionObj filter; /* expression for filtering the shapes */
786 #endif
787   } clusterObj;
788 
789   /************************************************************************/
790   /*                               joinObj                                */
791   /*                                                                      */
792   /*      simple way to access other XBase files, one-to-one or           */
793   /*      one-to-many supported                                           */
794   /************************************************************************/
795 
796 #ifndef SWIG
797   typedef struct {
798     char *name;
799     char **items, **values; /* items/values (process 1 record at a time) */
800     int numitems;
801 
802     char *table;
803     char *from, *to; /* item names */
804 
805     void *joininfo; /* vendor specific (i.e. XBase, MySQL, etc.) stuff to allow for persistant access */
806 
807     char *header, *footer;
808 #ifndef __cplusplus
809     char *template;
810 #else
811     char *_template;
812 #endif
813 
814     enum MS_JOIN_TYPE type;
815     char *connection;
816     enum MS_JOIN_CONNECTION_TYPE connectiontype;
817   } joinObj;
818 #endif
819 
820   /************************************************************************/
821   /*                           outputFormatObj                            */
822   /*                                                                      */
823   /*      see mapoutput.c for most related code.                          */
824   /************************************************************************/
825 
826   typedef struct {
827 #ifndef SWIG
828     int refcount;
829     char **formatoptions;
830 #endif /* SWIG */
831 #ifdef SWIG
832     %immutable;
833 #endif /* SWIG */
834     int  numformatoptions;
835 #ifdef SWIG
836     %mutable;
837 #endif /* SWIG */
838     char *name;
839     char *mimetype;
840     char *driver;
841     char *extension;
842     int  renderer;  /* MS_RENDER_WITH_* */
843     int  imagemode; /* MS_IMAGEMODE_* value. */
844     int  transparent;
845     int  bands;
846     int inmapfile; /* boolean value for writing */
847 #ifndef SWIG
848     rendererVTableObj *vtable;
849     void *device; /* for supporting direct rendering onto a device context */
850 #endif
851   } outputFormatObj;
852 
853   /* The following is used for "don't care" values in transparent, interlace and
854      imagequality values. */
855 #define MS_NOOVERRIDE  -1111
856 
857   /************************************************************************/
858   /*                             queryObj                                 */
859   /*                                                                      */
860   /*      encapsulates the information necessary to perform a query       */
861   /************************************************************************/
862 #ifndef SWIG
863   typedef struct {
864     int type; /* MS_QUERY_TYPE */
865     int mode; /* MS_QUERY_MODE */
866 
867     int layer;
868 
869     pointObj point; /* by point */
870     double buffer;
871     int maxresults;
872 
873     rectObj rect; /* by rect */
874     shapeObj *shape; /* by shape & operator (OGC filter) */
875 
876     long shapeindex; /* by index */
877     long tileindex;
878     int clear_resultcache;
879 
880     int  maxfeatures; /* global maxfeatures */
881     int  startindex;
882     int  only_cache_result_count; /* set to 1 sometimes by WFS 2.0 GetFeature request */
883 
884     expressionObj filter; /* by filter */
885     char *filteritem;
886 
887     int slayer; /* selection layer, used for msQueryByFeatures() (note this is not a query mode per se) */
888 
889     int cache_shapes; /* whether to cache shapes in resultCacheObj */
890     int max_cached_shape_count; /* maximum number of shapes cached in the total number of resultCacheObj */
891     int max_cached_shape_ram_amount; /* maximum number of bytes taken by shapes cached in the total number of resultCacheObj */
892   } queryObj;
893 #endif
894 
895   /************************************************************************/
896   /*                             queryMapObj                              */
897   /*                                                                      */
898   /*      used to visualize query results                                 */
899   /************************************************************************/
900   typedef struct {
901     int height, width;
902     int status;
903     int style; /* HILITE, SELECTED or NORMAL */
904     colorObj color;
905   } queryMapObj;
906 
907   /************************************************************************/
908   /*                                webObj                                */
909   /*                                                                      */
910   /*      holds parameters for a mapserver/mapscript interface            */
911   /************************************************************************/
912 
913   typedef struct {
914     char *log;
915     char *imagepath, *imageurl, *temppath;
916 
917 #ifdef SWIG
918     %immutable;
919 #endif /* SWIG */
920     struct mapObj *map;
921 #ifdef SWIG
922     %mutable;
923 #endif /* SWIG */
924 
925 #ifndef __cplusplus
926     char *template;
927 #else
928     char *_template;
929 #endif
930 
931     char *header, *footer;
932     char *empty, *error; /* error handling */
933     rectObj extent; /* clipping extent */
934     double minscaledenom, maxscaledenom;
935     char *mintemplate, *maxtemplate;
936 
937     char *queryformat; /* what format is the query to be returned, given as a MIME type */
938     char *legendformat;
939     char *browseformat;
940 
941 #ifdef SWIG
942     %immutable;
943 #endif /* SWIG */
944     hashTableObj metadata;
945     hashTableObj validation;
946 #ifdef SWIG
947     %mutable;
948 #endif /* SWIG */
949 
950   } webObj;
951 
952   /************************************************************************/
953   /*                               styleObj                               */
954   /*                                                                      */
955   /*      holds parameters for symbolization, multiple styles may be      */
956   /*      applied within a classObj                                       */
957   /************************************************************************/
958 
959   struct styleObj{
960 #ifdef SWIG
961     %immutable;
962 #endif /* SWIG */
963     int refcount;
964     char *symbolname;
965 #ifdef SWIG
966     %mutable;
967 #endif /* SWIG */
968 
969 #ifndef SWIG
970     /* private vars for rfc 48 & 64 */
971     expressionObj _geomtransform;
972 #endif
973 
974     /*should an angle be automatically computed*/
975     int autoangle;
976 
977     colorObj color;
978     colorObj backgroundcolor;
979     colorObj outlinecolor;
980 
981     int opacity;
982 
983     /* Stuff to handle Color Range Styles */
984     colorObj mincolor;
985     colorObj maxcolor;
986     double minvalue;
987     double maxvalue;
988     char *rangeitem;
989     int rangeitemindex;
990 
991     int symbol;
992     double size;
993     double minsize, maxsize;
994 
995 #if defined(SWIG) && defined(SWIGPYTHON) /* would probably make sense to mark it immutable for other binding languages than Python */
996   %immutable;
997 #endif
998     int patternlength;  /*moved from symbolObj in version 6.0*/
999 #if defined(SWIG) && defined(SWIGPYTHON)
1000   %mutable;
1001 #endif
1002 #if !(defined(SWIG) && defined(SWIGPYTHON)) /* in Python we use a special typemap for this */
1003     double pattern[MS_MAXPATTERNLENGTH]; /*moved from symbolObj in version 6.0*/
1004 #endif
1005 
1006     double gap; /*moved from symbolObj in version 6.0*/
1007     double initialgap;
1008     int position; /*moved from symbolObj in version 6.0*/
1009 
1010     int linecap, linejoin; /*moved from symbolObj in version 6.0*/
1011     double linejoinmaxsize; /*moved from symbolObj in version 6.0*/
1012 
1013     double width;
1014     double outlinewidth;
1015     double minwidth, maxwidth;
1016 
1017     double offsetx, offsety; /* for shadows, hollow symbols, etc... */
1018     double polaroffsetpixel, polaroffsetangle;
1019 
1020     double angle;
1021 
1022     double minscaledenom, maxscaledenom;
1023 
1024 #ifndef SWIG
1025     attributeBindingObj bindings[MS_STYLE_BINDING_LENGTH];
1026     int numbindings;
1027     expressionObj exprBindings[MS_STYLE_BINDING_LENGTH];
1028     int nexprbindings;
1029 #endif
1030   };
1031 
1032 #define MS_STYLE_SINGLE_SIDED_OFFSET -99
1033 #define MS_STYLE_DOUBLE_SIDED_OFFSET -999
1034 #define IS_PARALLEL_OFFSET(offsety) ((offsety) == MS_STYLE_SINGLE_SIDED_OFFSET || (offsety) == MS_STYLE_DOUBLE_SIDED_OFFSET)
1035 
1036   /********************************************************************/
1037   /*                          labelLeaderObj                          */
1038   /*                                                                  */
1039   /*  parameters defining how a label or a group of labels may be     */
1040   /*  offsetted from its original position                            */
1041   /********************************************************************/
1042 
1043   typedef struct {
1044     int maxdistance;
1045     int gridstep;
1046 #ifndef SWIG
1047     styleObj **styles;
1048     int maxstyles;
1049 #endif
1050 
1051 #ifdef SWIG
1052     %immutable;
1053 #endif
1054     int numstyles;
1055 #ifdef SWIG
1056     %mutable;
1057 #endif
1058 
1059   } labelLeaderObj;
1060 
1061 
1062   /************************************************************************/
1063   /*                               labelObj                               */
1064   /*                                                                      */
1065   /*      parameters needed to annotate a layer, legend or scalebar       */
1066   /************************************************************************/
1067 
1068   struct labelObj{
1069 #ifdef SWIG
1070     %immutable;
1071 #endif /* SWIG */
1072     int refcount;
1073 #ifdef SWIG
1074     %mutable;
1075 #endif /* SWIG */
1076 
1077     char *font;
1078     colorObj color;
1079     colorObj outlinecolor;
1080     int outlinewidth;
1081 
1082     colorObj shadowcolor;
1083     int shadowsizex, shadowsizey;
1084 
1085     int size;
1086     int minsize, maxsize;
1087 
1088     int position;
1089     int offsetx, offsety;
1090 
1091     double angle;
1092     enum MS_POSITIONS_ENUM anglemode;
1093 
1094     int buffer; /* space to reserve around a label */
1095 
1096     int align;
1097 
1098     char wrap;
1099     int maxlength;
1100     int minlength;
1101     double space_size_10; /*cached size of a single space character used for label text alignment of rfc40 */
1102 
1103     int minfeaturesize; /* minimum feature size (in pixels) to label */
1104     int autominfeaturesize; /* true or false */
1105 
1106     double minscaledenom, maxscaledenom;
1107 
1108     int mindistance;
1109     int repeatdistance;
1110     double maxoverlapangle;
1111     int partials; /* can labels run of an image */
1112 
1113     int force; /* labels *must* be drawn */
1114 
1115     char *encoding;
1116 
1117     int priority;  /* Priority level 1 to MS_MAX_LABEL_PRIORITY, default=1 */
1118 
1119 #ifndef SWIG
1120     expressionObj expression;
1121     expressionObj text;
1122 #endif
1123 
1124 #ifndef SWIG
1125     styleObj **styles;
1126     int maxstyles;
1127 #endif
1128     int numstyles;
1129 
1130 #ifndef SWIG
1131     attributeBindingObj bindings[MS_LABEL_BINDING_LENGTH];
1132     int numbindings;
1133     expressionObj exprBindings[MS_LABEL_BINDING_LENGTH];
1134     int nexprbindings;
1135 #endif
1136 
1137     labelLeaderObj *leader;
1138   };
1139 
1140 #ifdef SWIG
1141 #ifdef	__cplusplus
1142 extern "C" {
1143 #endif
1144 typedef struct labelObj labelObj;
1145 #ifdef	__cplusplus
1146 }
1147 #endif
1148 #endif
1149 
1150 #ifndef SWIG
1151   /* lightweight structure containing information to render a labelObj */
1152   typedef struct {
1153     lineObj *poly;
1154     rectObj bbox;
1155   } label_bounds;
1156 
1157   typedef struct {
1158     labelObj *label;
1159     char *annotext;
1160     double scalefactor,resolutionfactor;
1161     pointObj annopoint;
1162     double rotation;
1163     textPathObj *textpath;
1164     //rectObj bbox;
1165     label_bounds **style_bounds;
1166   } textSymbolObj;
1167 #endif
1168 
1169 #define MS_LABEL_PERPENDICULAR_OFFSET -99
1170 #define MS_LABEL_PERPENDICULAR_TOP_OFFSET 99
1171 #define IS_PERPENDICULAR_OFFSET(offsety) ((offsety) == MS_LABEL_PERPENDICULAR_OFFSET || (offsety) == MS_LABEL_PERPENDICULAR_TOP_OFFSET)
1172 
1173 
1174   /************************************************************************/
1175   /*                               classObj                               */
1176   /*                                                                      */
1177   /*      basic symbolization and classification information              */
1178   /************************************************************************/
1179 
1180   struct classObj {
1181 #ifndef SWIG
1182     expressionObj expression; /* the expression to be matched */
1183 #endif
1184 
1185     int status;
1186     int isfallback; // TRUE if this class should be applied if and only if
1187                     // no other class is applicable (e.g. SLD <ElseFilter/>)
1188 
1189 #ifndef SWIG
1190     styleObj **styles;
1191     int maxstyles;
1192 #endif
1193 
1194 #ifdef SWIG
1195     %immutable;
1196 #endif
1197     int numstyles;
1198     int numlabels;
1199 #ifdef SWIG
1200     %mutable;
1201 #endif
1202 
1203 #ifndef SWIG
1204     labelObj **labels;
1205     int maxlabels;
1206 #endif
1207     char *name; /* should be unique within a layer */
1208     char *title; /* used for legend labelling */
1209 
1210 #ifndef SWIG
1211     expressionObj text;
1212 #endif /* not SWIG */
1213 
1214 #ifndef __cplusplus
1215     char *template;
1216 #else /* __cplusplus */
1217     char *_template;
1218 #endif /* __cplusplus */
1219 
1220 #ifdef SWIG
1221     %immutable;
1222 #endif /* SWIG */
1223     hashTableObj metadata;
1224     hashTableObj validation;
1225 #ifdef SWIG
1226     %mutable;
1227 #endif /* SWIG */
1228 
1229     double minscaledenom, maxscaledenom;
1230     int minfeaturesize; /* minimum feature size (in pixels) to shape */
1231 #ifdef SWIG
1232     %immutable;
1233 #endif /* SWIG */
1234     int refcount;
1235     struct layerObj *layer;
1236     labelLeaderObj *leader;
1237 #ifdef SWIG
1238     %mutable;
1239 #endif /* SWIG */
1240     int debug;
1241 
1242     char *keyimage;
1243 
1244     char *group;
1245   };
1246 
1247   /************************************************************************/
1248   /*                         labelCacheMemberObj                          */
1249   /*                                                                      */
1250   /*      structures to implement label caching and collision             */
1251   /*      avoidance etc                                                   */
1252   /*                                                                      */
1253   /*        Note: These are scriptable, but are read only.                */
1254   /************************************************************************/
1255 
1256 
1257 #ifdef SWIG
1258   %immutable;
1259 #endif /* SWIG */
1260   typedef struct {
1261 #ifdef include_deprecated
1262     styleObj *styles; /* copied from the classObj, only present if there is a marker to be drawn */
1263     int numstyles;
1264 #endif
1265 
1266     textSymbolObj **textsymbols;
1267     int numtextsymbols;
1268 
1269     int layerindex; /* indexes */
1270     int classindex;
1271 
1272 #ifdef include_deprecated
1273     int shapetype; /* source geometry type, can be removed once annotation layers are dropped */
1274 #endif
1275 
1276     pointObj point; /* label point */
1277     rectObj bbox; /* bounds of the whole cachePtr. Individual text and symbol sub bounds are found in the textsymbols */
1278 
1279     int status; /* has this label been drawn or not */
1280 
1281     int markerid; /* corresponding marker (POINT layers only) */
1282     lineObj *leaderline;
1283     rectObj *leaderbbox;
1284   } labelCacheMemberObj;
1285 
1286   /************************************************************************/
1287   /*                         markerCacheMemberObj                         */
1288   /************************************************************************/
1289   typedef struct {
1290     int id; /* corresponding label */
1291     rectObj bounds;
1292   } markerCacheMemberObj;
1293 
1294   /************************************************************************/
1295   /*                          labelCacheSlotObj                           */
1296   /************************************************************************/
1297   typedef struct {
1298     labelCacheMemberObj *labels;
1299     int numlabels;
1300     int cachesize;
1301     markerCacheMemberObj *markers;
1302     int nummarkers;
1303     int markercachesize;
1304   } labelCacheSlotObj;
1305 
1306   /************************************************************************/
1307   /*                            labelCacheObj                             */
1308   /************************************************************************/
1309   typedef struct {
1310     /* One labelCacheSlotObj for each priority level */
1311     labelCacheSlotObj slots[MS_MAX_LABEL_PRIORITY];
1312     int gutter; /* space in pixels around the image where labels cannot be placed */
1313     labelCacheMemberObj **rendered_text_symbols;
1314     int num_allocated_rendered_members;
1315     int num_rendered_members;
1316   } labelCacheObj;
1317 
1318   /************************************************************************/
1319   /*                         resultObj                                    */
1320   /************************************************************************/
1321   typedef struct {
1322     long shapeindex;
1323     int tileindex;
1324     int resultindex;
1325     int classindex;
1326 #ifndef SWIG
1327     shapeObj* shape;
1328 #endif
1329   } resultObj;
1330 #ifdef SWIG
1331   %mutable;
1332 #endif /* SWIG */
1333 
1334 
1335   /************************************************************************/
1336   /*                            resultCacheObj                            */
1337   /************************************************************************/
1338   typedef struct {
1339 
1340 #ifndef SWIG
1341     resultObj *results;
1342     int cachesize;
1343 #endif /* not SWIG */
1344 
1345 #ifdef SWIG
1346     %immutable;
1347 #endif /* SWIG */
1348     int numresults;
1349     rectObj bounds;
1350 #ifndef SWIG
1351     rectObj previousBounds; /* bounds at previous iteration */
1352 #endif
1353 #ifdef SWIG
1354     %mutable;
1355 #endif /* SWIG */
1356 
1357     /* TODO: remove for 6.0, confirm with Assefa */
1358     /*used to force the result retreiving to use getshape instead of resultgetshape*/
1359     int usegetshape;
1360 
1361   } resultCacheObj;
1362 
1363 
1364   /************************************************************************/
1365   /*                             symbolSetObj                             */
1366   /************************************************************************/
1367   typedef struct {
1368     char *filename;
1369     int imagecachesize;
1370 #ifdef SWIG
1371     %immutable;
1372 #endif /* SWIG */
1373     int numsymbols;
1374     int maxsymbols;
1375 #ifdef SWIG
1376     %mutable;
1377 #endif /* SWIG */
1378 #ifndef SWIG
1379     int refcount;
1380     symbolObj** symbol;
1381     struct mapObj *map;
1382     fontSetObj *fontset; /* a pointer to the main mapObj version */
1383     struct imageCacheObj *imagecache;
1384 #endif /* not SWIG */
1385   } symbolSetObj;
1386 
1387   /************************************************************************/
1388   /*                           referenceMapObj                            */
1389   /************************************************************************/
1390   typedef struct {
1391     rectObj extent;
1392     int height, width;
1393     colorObj color;
1394     colorObj outlinecolor;
1395     char *image;
1396     int status;
1397     int marker;
1398     char *markername;
1399     int markersize;
1400     int minboxsize;
1401     int maxboxsize;
1402 #ifdef SWIG
1403     %immutable;
1404 #endif /* SWIG */
1405     struct mapObj *map;
1406 #ifdef SWIG
1407     %mutable;
1408 #endif /* SWIG */
1409   } referenceMapObj;
1410 
1411   /************************************************************************/
1412   /*                             scalebarObj                              */
1413   /************************************************************************/
1414   typedef struct {
1415     colorObj imagecolor;
1416     int height, width;
1417     int style;
1418     int intervals;
1419     labelObj label;
1420     colorObj color;
1421     colorObj backgroundcolor;
1422     colorObj outlinecolor;
1423     int units;
1424     int status; /* ON, OFF or EMBED */
1425     int position; /* for embeded scalebars */
1426 #ifndef SWIG
1427     int transparent;
1428     int interlace;
1429 #endif /* not SWIG */
1430     int postlabelcache;
1431     int align;
1432     int offsetx;
1433     int offsety;
1434   } scalebarObj;
1435 
1436   /************************************************************************/
1437   /*                              legendObj                               */
1438   /************************************************************************/
1439 
1440   typedef struct {
1441     colorObj imagecolor;
1442 #ifdef SWIG
1443     %immutable;
1444 #endif
1445     labelObj label;
1446 #ifdef SWIG
1447     %mutable;
1448 #endif
1449     int keysizex, keysizey;
1450     int keyspacingx, keyspacingy;
1451     colorObj outlinecolor; /* Color of outline of box, -1 for no outline */
1452     int status; /* ON, OFF or EMBED */
1453     int height, width;
1454     int position; /* for embeded legends */
1455 #ifndef SWIG
1456     int transparent;
1457     int interlace;
1458 #endif /* not SWIG */
1459     int postlabelcache;
1460 #ifndef __cplusplus
1461     char *template;
1462 #else /* __cplusplus */
1463     char *_template;
1464 #endif /* __cplusplus */
1465 #ifdef SWIG
1466     %immutable;
1467 #endif /* SWIG */
1468     struct mapObj *map;
1469 #ifdef SWIG
1470     %mutable;
1471 #endif /* SWIG */
1472   } legendObj;
1473 
1474   /************************************************************************/
1475   /*                             graticuleObj                             */
1476   /************************************************************************/
1477 #ifndef SWIG
1478   typedef struct {
1479     double    dwhichlatitude;
1480     double    dwhichlongitude;
1481     double    dstartlatitude;
1482     double    dstartlongitude;
1483     double    dendlatitude;
1484     double    dendlongitude;
1485     double    dincrementlatitude;
1486     double    dincrementlongitude;
1487     double    minarcs;
1488     double    maxarcs;
1489     double    minincrement;
1490     double    maxincrement;
1491     double    minsubdivides;
1492     double    maxsubdivides;
1493     int     bvertical;
1494     int     blabelaxes;
1495     int     ilabelstate;
1496     int     ilabeltype;
1497     rectObj   extent;
1498     lineObj   *pboundinglines;
1499     pointObj  *pboundingpoints;
1500     char    *labelformat;
1501   } graticuleObj;
1502 
1503   typedef struct {
1504     int nTop;
1505     pointObj *pasTop;
1506     char  **papszTopLabels;
1507     int nBottom;
1508     pointObj *pasBottom;
1509     char  **papszBottomLabels;
1510     int nLeft;
1511     pointObj *pasLeft;
1512     char  **papszLeftLabels;
1513     int nRight;
1514     pointObj *pasRight;
1515     char  **papszRightLabels;
1516 
1517   } graticuleIntersectionObj;
1518 
1519   struct layerVTable;
1520   typedef struct layerVTable layerVTableObj;
1521 
1522 #endif /*SWIG*/
1523 
1524   /************************************************************************/
1525   /*                               imageObj                               */
1526   /*                                                                      */
1527   /*      A wrapper for GD and other images.                              */
1528   /************************************************************************/
1529   struct imageObj{
1530 #ifdef SWIG
1531     %immutable;
1532 #endif
1533     int width, height;
1534     double resolution;
1535     double resolutionfactor;
1536 
1537     char *imagepath, *imageurl;
1538 
1539     outputFormatObj *format;
1540 #ifndef SWIG
1541     tileCacheObj *tilecache;
1542     int ntiles;
1543 #endif
1544 #ifdef SWIG
1545     %mutable;
1546 #endif
1547 #ifndef SWIG
1548     int size;
1549 #endif
1550 
1551 #ifndef SWIG
1552     union {
1553       void *plugin;
1554 
1555       char *imagemap;
1556       short *raw_16bit;
1557       float *raw_float;
1558       unsigned char *raw_byte;
1559     } img;
1560     ms_bitarray  img_mask;
1561     pointObj refpt;
1562     mapObj *map;
1563 #endif
1564   };
1565 
1566   /************************************************************************/
1567   /*                               layerObj                               */
1568   /*                                                                      */
1569   /*      base unit of a map.                                             */
1570   /************************************************************************/
1571 
1572   typedef struct {
1573     double minscale;
1574     double maxscale;
1575     char *value;
1576   } scaleTokenEntryObj;
1577 
1578   typedef struct {
1579      char *name;
1580      int n_entries;
1581      scaleTokenEntryObj *tokens;
1582   } scaleTokenObj;
1583 
1584 #ifndef SWIG
1585   typedef enum {
1586       SORT_ASC,
1587       SORT_DESC
1588   } sortOrderEnum;
1589 
1590   typedef struct {
1591       char* item;
1592       sortOrderEnum sortOrder;
1593   } sortByProperties;
1594 
1595   typedef struct {
1596       int nProperties;
1597       sortByProperties* properties;
1598   } sortByClause;
1599 
1600   typedef struct {
1601     /* The following store original members if they have been modified at runtime by a rfc86 scaletoken */
1602     char *data;
1603     char *tileitem;
1604     char *tileindex;
1605     char *filteritem;
1606     char *filter;
1607     char **processing;
1608     int *processing_idx;
1609     int n_processing;
1610   } originalScaleTokenStrings;
1611 #endif
1612 
1613   struct layerObj {
1614 
1615     char *classitem; /* .DBF item to be used for symbol lookup */
1616 
1617 #ifndef SWIG
1618     int classitemindex;
1619     resultCacheObj *resultcache; /* holds the results of a query against this layer */
1620     double scalefactor; /* computed, not set */
1621 #ifndef __cplusplus
1622     classObj **class; /* always at least 1 class */
1623 #else /* __cplusplus */
1624     classObj **_class;
1625 #endif /* __cplusplus */
1626 #endif /* not SWIG */
1627 
1628 #ifdef SWIG
1629     %immutable;
1630 #endif /* SWIG */
1631     /* reference counting, RFC24 */
1632     int refcount;
1633     int numclasses;
1634     int maxclasses;
1635     int index;
1636     struct mapObj *map;
1637 #ifdef SWIG
1638     %mutable;
1639 #endif /* SWIG */
1640 
1641     char *header, *footer; /* only used with multi result queries */
1642 
1643 #ifndef __cplusplus
1644     char *template; /* global template, used across all classes */
1645 #else /* __cplusplus */
1646     char *_template;
1647 #endif /* __cplusplus */
1648 
1649     char *name; /* should be unique */
1650     char *group; /* shouldn't be unique it's supposed to be a group right? */
1651 
1652     int status; /* on or off */
1653     enum MS_RENDER_MODE rendermode;
1654             // MS_FIRST_MATCHING_CLASS: Default and historic MapServer behavior
1655             // MS_ALL_MATCHING_CLASSES: SLD behavior
1656 
1657 #ifndef SWIG
1658     /* RFC86 Scale-dependent token replacements */
1659     scaleTokenObj *scaletokens;
1660     int numscaletokens;
1661     originalScaleTokenStrings *orig_st;
1662 
1663 #endif
1664 
1665     char *data; /* filename, can be relative or full path */
1666 
1667     enum MS_LAYER_TYPE type;
1668 
1669     double tolerance; /* search buffer for point and line queries (in toleranceunits) */
1670     int toleranceunits;
1671 
1672     double symbolscaledenom; /* scale at which symbols are default size */
1673     double minscaledenom, maxscaledenom;
1674     int minfeaturesize; /* minimum feature size (in pixels) to shape */
1675     double labelminscaledenom, labelmaxscaledenom;
1676     double mingeowidth, maxgeowidth; /* map width (in map units) at which the layer should be drawn */
1677 
1678     int sizeunits; /* applies to all classes */
1679 
1680     int maxfeatures;
1681     int startindex;
1682 
1683     colorObj offsite; /* transparent pixel value for raster images */
1684 
1685     int transform; /* does this layer have to be transformed to file coordinates */
1686 
1687     int labelcache, postlabelcache; /* on or off */
1688 
1689     char *labelitem;
1690 #ifndef SWIG
1691     int labelitemindex;
1692 #endif /* not SWIG */
1693 
1694     char *tileitem;
1695     char *tileindex; /* layer index file for tiling support */
1696     char *tilesrs;
1697 
1698 #ifndef SWIG
1699     int tileitemindex;
1700     projectionObj projection; /* projection information for the layer */
1701     int project; /* boolean variable, do we need to project this layer or not */
1702     reprojectionObj* reprojectorLayerToMap;
1703     reprojectionObj* reprojectorMapToLayer;
1704 #endif /* not SWIG */
1705 
1706     int units; /* units of the projection */
1707 
1708 #ifndef SWIG
1709     featureListNodeObjPtr features; /* linked list so we don't need a counter */
1710     featureListNodeObjPtr currentfeature; /* pointer to the current feature */
1711 #endif /* SWIG */
1712 
1713     char *connection;
1714     char *plugin_library;
1715     char *plugin_library_original; /* this is needed for mapfile writing */
1716     enum MS_CONNECTION_TYPE connectiontype;
1717 
1718 #ifndef SWIG
1719     layerVTableObj *vtable;
1720 
1721     /* SDL has converted OracleSpatial, SDE, Graticules */
1722     void *layerinfo; /* all connection types should use this generic pointer to a vendor specific structure */
1723     void *wfslayerinfo; /* For WFS layers, will contain a msWFSLayerInfo struct */
1724 #endif /* not SWIG */
1725 
1726     /* attribute/classification handling components */
1727 #ifdef SWIG
1728     %immutable;
1729 #endif /* SWIG */
1730     int numitems;
1731 #ifdef SWIG
1732     %mutable;
1733 #endif /* SWIG */
1734 
1735 #ifndef SWIG
1736     char **items;
1737     void *iteminfo; /* connection specific information necessary to retrieve values */
1738     expressionObj filter; /* connection specific attribute filter */
1739     int bandsitemindex;
1740     int filteritemindex;
1741     int styleitemindex;
1742 #endif /* not SWIG */
1743 
1744     char *bandsitem; /* which item in a tile contains bands to use (tiled raster data only) */
1745     char *filteritem;
1746     char *styleitem; /* item to be used for style lookup - can also be 'AUTO' */
1747 
1748     char *requires; /* context expressions, simple enough to not use expressionObj */
1749     char *labelrequires;
1750 
1751 #ifdef SWIG
1752     %immutable;
1753 #endif /* SWIG */
1754     hashTableObj metadata;
1755     hashTableObj validation;
1756     hashTableObj bindvals;
1757     clusterObj cluster;
1758 #ifdef SWIG
1759     %mutable;
1760 #endif /* SWIG */
1761 
1762     int dump;
1763     int debug;
1764 #ifndef SWIG
1765     char **processing;
1766     joinObj *joins;
1767 #endif /* not SWIG */
1768 #ifdef SWIG
1769     %immutable;
1770 #endif /* SWIG */
1771 
1772     rectObj extent;
1773 
1774     int numprocessing;
1775     int numjoins;
1776 #ifdef SWIG
1777     %mutable;
1778 #endif /* SWIG */
1779 
1780     char *classgroup;
1781 
1782 #ifndef SWIG
1783     imageObj *maskimage;
1784     graticuleObj* grid;
1785 #endif
1786     char *mask;
1787 
1788 #ifndef SWIG
1789     expressionObj _geomtransform;
1790 #endif
1791 
1792     char *encoding; /* for iconving shape attributes. ignored if NULL or "utf-8" */
1793 
1794   /* RFC93 UTFGrid support */
1795     char *utfitem;
1796     int utfitemindex;
1797     expressionObj utfdata;
1798 
1799 #ifndef SWIG
1800     sortByClause sortBy;
1801 #endif
1802 
1803     LayerCompositer *compositer;
1804 
1805     hashTableObj connectionoptions;
1806   };
1807 
1808 
1809 #ifndef SWIG
1810 void msFontCacheSetup();
1811 void msFontCacheCleanup();
1812 
1813 typedef struct {
1814   double minx,miny,maxx,maxy,advance;
1815 } glyph_metrics;
1816 
1817 typedef struct {
1818   glyph_element *glyph;
1819   face_element *face;
1820   pointObj pnt;
1821   double rot;
1822 } glyphObj;
1823 
1824 struct textPathObj{
1825   int numglyphs;
1826   int numlines;
1827   int line_height;
1828   int glyph_size;
1829   int absolute; /* are the glyph positions absolutely placed, or relative to the origin */
1830   glyphObj *glyphs;
1831   label_bounds bounds;
1832 };
1833 
1834 typedef enum {
1835   duplicate_never,
1836   duplicate_always,
1837   duplicate_if_needed
1838 } label_cache_mode;
1839 
1840 void initTextPath(textPathObj *tp);
1841 int WARN_UNUSED msComputeTextPath(mapObj *map, textSymbolObj *ts);
1842 void msCopyTextPath(textPathObj *dst, textPathObj *src);
1843 void freeTextPath(textPathObj *tp);
1844 void initTextSymbol(textSymbolObj *ts);
1845 void freeTextSymbol(textSymbolObj *ts);
1846 void copyLabelBounds(label_bounds *dst, label_bounds *src);
1847 void msCopyTextSymbol(textSymbolObj *dst, textSymbolObj *src);
1848 void msPopulateTextSymbolForLabelAndString(textSymbolObj *ts, labelObj *l, char *string, double scalefactor, double resolutionfactor, label_cache_mode cache);
1849 #endif /* SWIG */
1850 
1851 
1852   /************************************************************************/
1853   /*                                mapObj                                */
1854   /*                                                                      */
1855   /*      encompasses everything used in an Internet mapping              */
1856   /*      application.                                                    */
1857   /************************************************************************/
1858 
1859   /* MAP OBJECT -  */
1860   struct mapObj { /* structure for a map */
1861     char *name; /* small identifier for naming etc. */
1862     int status; /* is map creation on or off */
1863     int height, width;
1864     int maxsize;
1865 
1866 #ifndef SWIG
1867     layerObj **layers;
1868 #endif /* SWIG */
1869 
1870 #ifdef SWIG
1871     %immutable;
1872 #endif /* SWIG */
1873     /* reference counting, RFC24 */
1874     int refcount;
1875     int numlayers; /* number of layers in mapfile */
1876     int maxlayers; /* allocated size of layers[] array */
1877 
1878     symbolSetObj symbolset;
1879     fontSetObj fontset;
1880 
1881     labelCacheObj labelcache; /* we need this here so multiple feature processors can access it */
1882 #ifdef SWIG
1883     %mutable;
1884 #endif /* SWIG */
1885 
1886     int transparent; /* TODO - Deprecated */
1887     int interlace; /* TODO - Deprecated */
1888     int imagequality; /* TODO - Deprecated */
1889 
1890     rectObj extent; /* map extent array */
1891     double cellsize; /* in map units */
1892 
1893 
1894 #ifndef SWIG
1895     geotransformObj gt; /* rotation / geotransform */
1896     rectObj saved_extent;
1897 #endif /*SWIG*/
1898 
1899     enum MS_UNITS units; /* units of the projection */
1900     double scaledenom; /* scale of the output image */
1901     double resolution;
1902     double defresolution; /* default resolution: used for calculate the scalefactor */
1903 
1904     char *shapepath; /* where are the shape files located */
1905     char *mappath; /* path of the mapfile, all path are relative to this path */
1906     char *sldurl; // URL of SLD document as specified with "&SLD=..."
1907                   // WMS parameter.  Currently this reference is used
1908                   // only in mapogcsld.c and has a NULL value
1909                   // outside that context.
1910 
1911 #ifndef SWIG
1912     paletteObj palette; /* holds a map palette */
1913 #endif /*SWIG*/
1914     colorObj imagecolor; /* holds the initial image color value */
1915 
1916 #ifdef SWIG
1917     %immutable;
1918 #endif /* SWIG */
1919     int numoutputformats;
1920 #ifndef SWIG
1921     outputFormatObj **outputformatlist;
1922 #endif /*SWIG*/
1923     outputFormatObj *outputformat;
1924 
1925     char *imagetype; /* name of current outputformat */
1926 #ifdef SWIG
1927     %mutable;
1928 #endif /* SWIG */
1929 
1930 #ifndef SWIG
1931     projectionObj projection; /* projection information for output map */
1932     projectionObj latlon; /* geographic projection definition */
1933 #endif /* not SWIG */
1934 
1935 #ifdef SWIG
1936     %immutable;
1937 #endif /* SWIG */
1938     referenceMapObj reference;
1939     scalebarObj scalebar;
1940     legendObj legend;
1941 
1942     queryMapObj querymap;
1943 
1944     webObj web;
1945 #ifdef SWIG
1946     %mutable;
1947 #endif /* SWIG */
1948 
1949     int *layerorder;
1950 
1951     int debug;
1952 
1953     char *datapattern, *templatepattern; /* depricated, use VALIDATION ... END block instead */
1954 
1955 #ifdef SWIG
1956     %immutable;
1957 #endif /* SWIG */
1958     hashTableObj configoptions;
1959 #ifdef SWIG
1960     %mutable;
1961 #endif /* SWIG */
1962 
1963 #ifndef SWIG
1964     /* Private encryption key information - see mapcrypto.c */
1965     int encryption_key_loaded;        /* MS_TRUE once key has been loaded */
1966     unsigned char encryption_key[MS_ENCRYPTION_KEY_SIZE]; /* 128bits encryption key */
1967 
1968     queryObj query;
1969 #endif
1970 
1971 #ifdef USE_V8_MAPSCRIPT
1972     void *v8context;
1973 #endif
1974 
1975 #ifndef SWIG
1976     projectionContext* projContext;
1977 #endif
1978   };
1979 
1980   /************************************************************************/
1981   /*                             layerVTable                              */
1982   /*                                                                      */
1983   /*      contains function pointers to the layer operations.  If you     */
1984   /*      add new functions to here, remember to update                   */
1985   /*      populateVirtualTable in maplayer.c                              */
1986   /************************************************************************/
1987 #ifndef SWIG
1988   struct layerVTable {
1989     int (*LayerTranslateFilter)(layerObj *layer, expressionObj *filter, char *filteritem);
1990     int (*LayerSupportsCommonFilters)(layerObj *layer);
1991     int (*LayerInitItemInfo)(layerObj *layer);
1992     void (*LayerFreeItemInfo)(layerObj *layer);
1993     int (*LayerOpen)(layerObj *layer);
1994     int (*LayerIsOpen)(layerObj *layer);
1995     int (*LayerWhichShapes)(layerObj *layer, rectObj rect, int isQuery);
1996     int (*LayerNextShape)(layerObj *layer, shapeObj *shape);
1997     int (*LayerGetShape)(layerObj *layer, shapeObj *shape, resultObj *record);
1998     int (*LayerGetShapeCount)(layerObj *layer, rectObj rect, projectionObj *rectProjection);
1999     int (*LayerClose)(layerObj *layer);
2000     int (*LayerGetItems)(layerObj *layer);
2001     int (*LayerGetExtent)(layerObj *layer, rectObj *extent);
2002     int (*LayerGetAutoStyle)(mapObj *map, layerObj *layer, classObj *c, shapeObj *shape);
2003     int (*LayerCloseConnection)(layerObj *layer);
2004     int (*LayerSetTimeFilter)(layerObj *layer, const char *timestring, const char *timefield);
2005     int (*LayerApplyFilterToLayer)(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex);
2006     int (*LayerCreateItems)(layerObj *layer, int nt);
2007     int (*LayerGetNumFeatures)(layerObj *layer);
2008     int (*LayerGetAutoProjection)(layerObj *layer, projectionObj *projection);
2009     char* (*LayerEscapeSQLParam)(layerObj *layer, const char* pszString);
2010     char* (*LayerEscapePropertyName)(layerObj *layer, const char* pszString);
2011     void (*LayerEnablePaging)(layerObj *layer, int value);
2012     int (*LayerGetPaging)(layerObj *layer);
2013   };
2014 #endif /*SWIG*/
2015 
2016   /* Function prototypes, wrapable */
2017   MS_DLL_EXPORT int msSaveImage(mapObj *map, imageObj *img, const char *filename);
2018   MS_DLL_EXPORT void msFreeImage(imageObj *img);
2019   MS_DLL_EXPORT int msSetup(void);
2020   MS_DLL_EXPORT void msCleanup(void);
2021   MS_DLL_EXPORT mapObj *msLoadMapFromString(char *buffer, char *new_mappath);
2022 
2023   /* Function prototypes, not wrapable */
2024 
2025 #ifndef SWIG
2026 
2027   /*
2028   ** helper functions not part of the general API but needed in
2029   ** a few other places (like mapscript)... found in mapfile.c
2030   */
2031   int getString(char **s);
2032   int getDouble(double *d);
2033   int getInteger(int *i);
2034   int getSymbol(int n, ...);
2035   int getCharacter(char *c);
2036 
2037   int msBuildPluginLibraryPath(char **dest, const char *lib_str, mapObj *map);
2038 
2039   MS_DLL_EXPORT int  hex2int(char *hex);
2040 
2041   MS_DLL_EXPORT void initJoin(joinObj *join);
2042   MS_DLL_EXPORT void initSymbol(symbolObj *s);
2043   MS_DLL_EXPORT int initMap(mapObj *map);
2044   MS_DLL_EXPORT layerObj *msGrowMapLayers( mapObj *map );
2045   MS_DLL_EXPORT int initLayer(layerObj *layer, mapObj *map);
2046   MS_DLL_EXPORT int freeLayer( layerObj * );
2047   MS_DLL_EXPORT classObj *msGrowLayerClasses( layerObj *layer );
2048   MS_DLL_EXPORT scaleTokenObj *msGrowLayerScaletokens( layerObj *layer );
2049   MS_DLL_EXPORT int initScaleToken(scaleTokenObj *scaleToken);
2050   MS_DLL_EXPORT int initClass(classObj *_class);
2051   MS_DLL_EXPORT int freeClass( classObj * );
2052   MS_DLL_EXPORT styleObj *msGrowClassStyles( classObj *_class );
2053   MS_DLL_EXPORT labelObj *msGrowClassLabels( classObj *_class );
2054   MS_DLL_EXPORT styleObj *msGrowLabelStyles( labelObj *label );
2055   MS_DLL_EXPORT styleObj *msGrowLeaderStyles( labelLeaderObj *leader );
2056   MS_DLL_EXPORT int msMaybeAllocateClassStyle(classObj* c, int idx);
2057   MS_DLL_EXPORT void initLabel(labelObj *label);
2058   MS_DLL_EXPORT int  freeLabel(labelObj *label);
2059   MS_DLL_EXPORT int  freeLabelLeader(labelLeaderObj *leader);
2060   MS_DLL_EXPORT void resetClassStyle(classObj *_class);
2061   MS_DLL_EXPORT int initStyle(styleObj *style);
2062   MS_DLL_EXPORT int freeStyle(styleObj *style);
2063   MS_DLL_EXPORT void initReferenceMap(referenceMapObj *ref);
2064   MS_DLL_EXPORT void initScalebar(scalebarObj *scalebar);
2065   MS_DLL_EXPORT void initGrid( graticuleObj *pGraticule );
2066   MS_DLL_EXPORT void initWeb(webObj *web);
2067   MS_DLL_EXPORT void freeWeb(webObj *web);
2068   MS_DLL_EXPORT void initResultCache(resultCacheObj *resultcache);
2069   void cleanupResultCache(resultCacheObj *resultcache);
2070   MS_DLL_EXPORT int initLayerCompositer(LayerCompositer *compositer);
2071   MS_DLL_EXPORT void initLeader(labelLeaderObj *leader);
2072   MS_DLL_EXPORT void freeGrid( graticuleObj *pGraticule);
2073 
2074   MS_DLL_EXPORT featureListNodeObjPtr insertFeatureList(featureListNodeObjPtr *list, shapeObj *shape);
2075   MS_DLL_EXPORT void freeFeatureList(featureListNodeObjPtr list);
2076 
2077   /* To be used *only* within the mapfile loading phase */
2078   MS_DLL_EXPORT int loadExpressionString(expressionObj *exp, char *value);
2079   /* Use this next, thread safe wrapper, function everywhere else */
2080   MS_DLL_EXPORT int msLoadExpressionString(expressionObj *exp, char *value);
2081   MS_DLL_EXPORT char *msGetExpressionString(expressionObj *exp);
2082   MS_DLL_EXPORT void msInitExpression(expressionObj *exp);
2083   MS_DLL_EXPORT void msFreeExpressionTokens(expressionObj *exp);
2084   MS_DLL_EXPORT void msFreeExpression(expressionObj *exp);
2085 
2086   MS_DLL_EXPORT void msApplySubstitutions(mapObj *map, char **names, char **values, int npairs);
2087   MS_DLL_EXPORT void msApplyDefaultSubstitutions(mapObj *map);
2088 
2089   MS_DLL_EXPORT int getClassIndex(layerObj *layer, char *str);
2090 
2091   /* For maplabel */
2092   int intersectLabelPolygons(lineObj *p1, rectObj *r1, lineObj *p2, rectObj *r2);
2093   int intersectTextSymbol(textSymbolObj *ts, label_bounds *lb);
2094   pointObj get_metrics(pointObj *p, int position, textPathObj *tp, int ox, int oy, double rotation, int buffer, label_bounds *metrics);
2095   double dist(pointObj a, pointObj b);
2096   void fastComputeBounds(lineObj *line, rectObj *bounds);
2097 
2098   /*
2099   ** Main API Functions
2100   */
2101 
2102   /* mapobject.c */
2103 
2104   MS_DLL_EXPORT void msFreeMap(mapObj *map);
2105   MS_DLL_EXPORT mapObj *msNewMapObj(void);
2106   MS_DLL_EXPORT const char *msGetConfigOption( mapObj *map, const char *key);
2107   MS_DLL_EXPORT int msSetConfigOption( mapObj *map, const char *key, const char *value);
2108   MS_DLL_EXPORT int msTestConfigOption( mapObj *map, const char *key,
2109                                         int default_result );
2110   MS_DLL_EXPORT void msApplyMapConfigOptions( mapObj *map );
2111   MS_DLL_EXPORT int msMapComputeGeotransform( mapObj *map );
2112 
2113   MS_DLL_EXPORT void msMapPixelToGeoref( mapObj *map, double *x, double *y );
2114   MS_DLL_EXPORT void msMapGeorefToPixel( mapObj *map, double *x, double *y );
2115 
2116   MS_DLL_EXPORT int msMapSetExtent(mapObj *map, double minx, double miny,
2117                                    double maxx, double maxy);
2118   MS_DLL_EXPORT int msMapOffsetExtent( mapObj *map, double x, double y);
2119   MS_DLL_EXPORT int msMapScaleExtent( mapObj *map, double zoomfactor,
2120                                       double minscaledenom, double maxscaledenom);
2121   MS_DLL_EXPORT int msMapSetCenter( mapObj *map, pointObj *center);
2122   MS_DLL_EXPORT int msMapSetRotation( mapObj *map, double rotation_angle );
2123   MS_DLL_EXPORT int msMapSetSize( mapObj *map, int width, int height );
2124   MS_DLL_EXPORT int msMapSetSize( mapObj *map, int width, int height );
2125   MS_DLL_EXPORT int msMapSetFakedExtent( mapObj *map );
2126   MS_DLL_EXPORT int msMapRestoreRealExtent( mapObj *map );
2127   MS_DLL_EXPORT int msMapLoadOWSParameters( mapObj *map, cgiRequestObj *request,
2128       const char *wmtver_string );
2129   MS_DLL_EXPORT int msMapIgnoreMissingData( mapObj *map );
2130 
2131   /* mapfile.c */
2132 
2133   MS_DLL_EXPORT int msValidateParameter(const char *value, const char *pattern1, const char *pattern2, const char *pattern3, const char *pattern4);
2134   MS_DLL_EXPORT int msGetLayerIndex(mapObj *map, const char *name);
2135   MS_DLL_EXPORT int msGetSymbolIndex(symbolSetObj *set, char *name, int try_addimage_if_notfound);
2136   MS_DLL_EXPORT mapObj  *msLoadMap(const char *filename, const char *new_mappath);
2137   MS_DLL_EXPORT int msTransformXmlMapfile(const char *stylesheet, const char *xmlMapfile, FILE *tmpfile);
2138   MS_DLL_EXPORT int msSaveMap(mapObj *map, char *filename);
2139   MS_DLL_EXPORT void msFreeCharArray(char **array, int num_items);
2140   MS_DLL_EXPORT int msUpdateScalebarFromString(scalebarObj *scalebar, char *string, int url_string);
2141   MS_DLL_EXPORT int msUpdateQueryMapFromString(queryMapObj *querymap, char *string, int url_string);
2142   MS_DLL_EXPORT int msUpdateLabelFromString(labelObj *label, char *string, int url_string);
2143   MS_DLL_EXPORT int msUpdateClusterFromString(clusterObj *cluster, char *string);
2144   MS_DLL_EXPORT int msUpdateReferenceMapFromString(referenceMapObj *ref, char *string, int url_string);
2145   MS_DLL_EXPORT int msUpdateLegendFromString(legendObj *legend, char *string, int url_string);
2146   MS_DLL_EXPORT int msUpdateWebFromString(webObj *web, char *string, int url_string);
2147   MS_DLL_EXPORT int msUpdateStyleFromString(styleObj *style, char *string, int url_string);
2148   MS_DLL_EXPORT int msUpdateClassFromString(classObj *_class, char *string, int url_string);
2149   MS_DLL_EXPORT int msUpdateLayerFromString(layerObj *layer, char *string, int url_string);
2150   MS_DLL_EXPORT int msUpdateMapFromURL(mapObj *map, char *variable, char *string);
2151   MS_DLL_EXPORT char *msWriteLayerToString(layerObj *layer);
2152   MS_DLL_EXPORT char *msWriteMapToString(mapObj *map);
2153   MS_DLL_EXPORT char *msWriteClassToString(classObj *_class);
2154   MS_DLL_EXPORT char *msWriteStyleToString(styleObj *style);
2155   MS_DLL_EXPORT char *msWriteLabelToString(labelObj *label);
2156   MS_DLL_EXPORT char *msWriteWebToString(webObj *web);
2157   MS_DLL_EXPORT char *msWriteScalebarToString(scalebarObj *scalebar);
2158   MS_DLL_EXPORT char *msWriteQueryMapToString(queryMapObj *querymap);
2159   MS_DLL_EXPORT char *msWriteReferenceMapToString(referenceMapObj *ref);
2160   MS_DLL_EXPORT char *msWriteLegendToString(legendObj *legend);
2161   MS_DLL_EXPORT char *msWriteClusterToString(clusterObj *cluster);
2162   MS_DLL_EXPORT int msIsValidRegex(const char* e);
2163   MS_DLL_EXPORT int msEvalRegex(const char *e, const char *s);
2164   MS_DLL_EXPORT int msCaseEvalRegex(const char *e, const char *s);
2165 #ifdef USE_MSFREE
2166   MS_DLL_EXPORT void msFree(void *p);
2167 #else
2168 #define msFree free
2169 #endif
2170   MS_DLL_EXPORT char **msTokenizeMap(char *filename, int *numtokens);
2171   MS_DLL_EXPORT int msInitLabelCache(labelCacheObj *cache);
2172   MS_DLL_EXPORT int msFreeLabelCache(labelCacheObj *cache);
2173   MS_DLL_EXPORT int msCheckConnection(layerObj * layer); /* connection pooling functions (mapfile.c) */
2174   MS_DLL_EXPORT void msCloseConnections(mapObj *map);
2175 
2176   MS_DLL_EXPORT void msOGRInitialize(void);
2177   MS_DLL_EXPORT void msOGRCleanup(void);
2178   MS_DLL_EXPORT void msGDALCleanup(void);
2179   MS_DLL_EXPORT void msGDALInitialize(void);
2180 
2181   MS_DLL_EXPORT imageObj *msDrawScalebar(mapObj *map); /* in mapscale.c */
2182   MS_DLL_EXPORT int msCalculateScale(rectObj extent, int units, int width, int height, double resolution, double *scaledenom);
2183   MS_DLL_EXPORT double GetDeltaExtentsUsingScale(double scale, int units, double centerLat, int width, double resolution);
2184   MS_DLL_EXPORT double Pix2Georef(int nPixPos, int nPixMin, int nPixMax, double dfGeoMin, double dfGeoMax, int bULisYOrig);
2185   MS_DLL_EXPORT double Pix2LayerGeoref(mapObj *map, layerObj *layer, int value);
2186   MS_DLL_EXPORT double msInchesPerUnit(int units, double center_lat);
2187   MS_DLL_EXPORT int msEmbedScalebar(mapObj *map, imageObj *img);
2188 
2189   MS_DLL_EXPORT int msPointInRect(const pointObj *p, const rectObj *rect); /* in mapsearch.c */
2190   MS_DLL_EXPORT int msRectOverlap(const rectObj *a, const rectObj *b);
2191   MS_DLL_EXPORT int msRectContained(const rectObj *a, const rectObj *b);
2192   MS_DLL_EXPORT int msRectIntersect(rectObj *a, const rectObj *b);
2193 
2194   MS_DLL_EXPORT void msRectToFormattedString(rectObj *rect, char *format,
2195       char *buffer, int buffer_length);
2196   MS_DLL_EXPORT void msPointToFormattedString(pointObj *point, const char*format,
2197       char *buffer, int buffer_length);
2198   MS_DLL_EXPORT int msIsDegenerateShape(shapeObj *shape);
2199 
2200   MS_DLL_EXPORT void msMergeRect(rectObj *a, rectObj *b);
2201   MS_DLL_EXPORT double msDistancePointToPoint(pointObj *a, pointObj *b);
2202   MS_DLL_EXPORT double msSquareDistancePointToPoint(pointObj *a, pointObj *b);
2203   MS_DLL_EXPORT double msDistancePointToSegment(pointObj *p, pointObj *a, pointObj *b);
2204   MS_DLL_EXPORT double msSquareDistancePointToSegment(pointObj *p, pointObj *a, pointObj *b);
2205   MS_DLL_EXPORT double msDistancePointToShape(pointObj *p, shapeObj *shape);
2206   MS_DLL_EXPORT double msSquareDistancePointToShape(pointObj *p, shapeObj *shape);
2207   MS_DLL_EXPORT double msDistanceSegmentToSegment(pointObj *pa, pointObj *pb, pointObj *pc, pointObj *pd);
2208   MS_DLL_EXPORT double msDistanceShapeToShape(shapeObj *shape1, shapeObj *shape2);
2209   MS_DLL_EXPORT int msIntersectSegments(const pointObj *a, const pointObj *b, const pointObj *c, const pointObj *d);
2210   MS_DLL_EXPORT int msPointInPolygon(pointObj *p, lineObj *c);
2211   MS_DLL_EXPORT int msIntersectMultipointPolygon(shapeObj *multipoint, shapeObj *polygon);
2212   MS_DLL_EXPORT int msIntersectPointPolygon(pointObj *p, shapeObj *polygon);
2213   MS_DLL_EXPORT int msIntersectPolylinePolygon(shapeObj *line, shapeObj *poly);
2214   MS_DLL_EXPORT int msIntersectPolygons(shapeObj *p1, shapeObj *p2);
2215   MS_DLL_EXPORT int msIntersectPolylines(shapeObj *line1, shapeObj *line2);
2216 
2217   MS_DLL_EXPORT int msInitQuery(queryObj *query); /* in mapquery.c */
2218   MS_DLL_EXPORT void msFreeQuery(queryObj *query);
2219   MS_DLL_EXPORT int msSaveQuery(mapObj *map, char *filename, int results);
2220   MS_DLL_EXPORT int msLoadQuery(mapObj *map, char *filename);
2221   MS_DLL_EXPORT int msExecuteQuery(mapObj *map);
2222 
2223   MS_DLL_EXPORT int msQueryByIndex(mapObj *map); /* various query methods, all rely on the queryObj hung off the mapObj */
2224   MS_DLL_EXPORT int msQueryByAttributes(mapObj *map);
2225   MS_DLL_EXPORT int msQueryByPoint(mapObj *map);
2226   MS_DLL_EXPORT int msQueryByRect(mapObj *map);
2227   MS_DLL_EXPORT int msQueryByFeatures(mapObj *map);
2228   MS_DLL_EXPORT int msQueryByShape(mapObj *map);
2229   MS_DLL_EXPORT int msQueryByFilter(mapObj *map);
2230 
2231   MS_DLL_EXPORT int msGetQueryResultBounds(mapObj *map, rectObj *bounds);
2232   MS_DLL_EXPORT int msIsLayerQueryable(layerObj *lp);
2233   MS_DLL_EXPORT void msQueryFree(mapObj *map, int qlayer); /* todo: rename */
2234   MS_DLL_EXPORT int msRasterQueryByShape(mapObj *map, layerObj *layer, shapeObj *selectshape);
2235   MS_DLL_EXPORT int msRasterQueryByRect(mapObj *map, layerObj *layer, rectObj queryRect);
2236   MS_DLL_EXPORT int msRasterQueryByPoint(mapObj *map, layerObj *layer, int mode, pointObj p, double buffer, int maxresults );
2237 
2238   /* in mapstring.c */
2239   MS_DLL_EXPORT void msStringTrim(char *str);
2240   MS_DLL_EXPORT void msStringTrimBlanks(char *string);
2241   MS_DLL_EXPORT char *msStringTrimLeft(char *string);
2242   MS_DLL_EXPORT char *msStringChop(char *string);
2243   MS_DLL_EXPORT void msStringTrimEOL(char *string);
2244   MS_DLL_EXPORT char *msReplaceSubstring(char *str, const char *old, const char *sznew);
2245   MS_DLL_EXPORT void msReplaceChar(char *str, char old, char sznew);
2246   MS_DLL_EXPORT char *msCaseReplaceSubstring(char *str, const char *old, const char *sznew);
2247   MS_DLL_EXPORT char *msStripPath(char *fn);
2248   MS_DLL_EXPORT char *msGetPath(const char *fn);
2249   MS_DLL_EXPORT char *msBuildPath(char *pszReturnPath, const char *abs_path, const char *path);
2250   MS_DLL_EXPORT char *msBuildPath3(char *pszReturnPath, const char *abs_path, const char *path1, const char *path2);
2251   MS_DLL_EXPORT char *msTryBuildPath(char *szReturnPath, const char *abs_path, const char *path);
2252   MS_DLL_EXPORT char *msTryBuildPath3(char *szReturnPath, const char *abs_path, const char *path1, const char *path2);
2253   MS_DLL_EXPORT char **msStringSplit(const char *string, char cd, int *num_tokens);
2254   MS_DLL_EXPORT char ** msStringSplitComplex( const char * pszString, const char * pszDelimiters, int *num_tokens, int nFlags);
2255   MS_DLL_EXPORT int msStringArrayContains(char **array, const char *element, int numElements);
2256   MS_DLL_EXPORT char **msStringTokenize( const char *pszLine, const char *pszDelim, int *num_tokens, int preserve_quote);
2257   MS_DLL_EXPORT int msCountChars(char *str, char ch);
2258   MS_DLL_EXPORT char *msLongToString(long value);
2259   MS_DLL_EXPORT char *msDoubleToString(double value, int force_f);
2260   MS_DLL_EXPORT char *msIntToString(int value);
2261   MS_DLL_EXPORT void msStringToUpper(char *string);
2262   MS_DLL_EXPORT void msStringToLower(char *string);
2263   MS_DLL_EXPORT void msStringInitCap(char *string);
2264   MS_DLL_EXPORT void msStringFirstCap(char *string);
2265   MS_DLL_EXPORT int msEncodeChar(const char);
2266   MS_DLL_EXPORT char *msEncodeUrlExcept(const char*, const char);
2267   MS_DLL_EXPORT char *msEncodeUrl(const char*);
2268   MS_DLL_EXPORT char *msEscapeJSonString(const char* pszJSonString);
2269   MS_DLL_EXPORT char *msEncodeHTMLEntities(const char *string);
2270   MS_DLL_EXPORT void msDecodeHTMLEntities(const char *string);
2271   MS_DLL_EXPORT int msIsXMLTagValid(const char *string);
2272   MS_DLL_EXPORT char *msStringConcatenate(char *pszDest, const char *pszSrc);
2273   MS_DLL_EXPORT char *msJoinStrings(char **array, int arrayLength, const char *delimeter);
2274   MS_DLL_EXPORT char *msHashString(const char *pszStr);
2275   MS_DLL_EXPORT char *msCommifyString(char *str);
2276   MS_DLL_EXPORT int msHexToInt(char *hex);
2277   MS_DLL_EXPORT char *msGetEncodedString(const char *string, const char *encoding);
2278   MS_DLL_EXPORT char *msConvertWideStringToUTF8 (const wchar_t* string, const char* encoding);
2279   MS_DLL_EXPORT int msGetNextGlyph(const char **in_ptr, char *out_string);
2280   MS_DLL_EXPORT int msGetNumGlyphs(const char *in_ptr);
2281   MS_DLL_EXPORT int msGetUnicodeEntity(const char *inptr, unsigned int *unicode);
2282   MS_DLL_EXPORT int msStringIsInteger(const char *string);
2283   MS_DLL_EXPORT int msUTF8ToUniChar(const char *str, unsigned int *chPtr); /* maptclutf.c */
2284   MS_DLL_EXPORT char* msStringEscape( const char * pszString );
2285   MS_DLL_EXPORT int msStringInArray( const char * pszString, char **array, int numelements);
2286 
2287   typedef struct msStringBuffer msStringBuffer;
2288   MS_DLL_EXPORT msStringBuffer* msStringBufferAlloc(void);
2289   MS_DLL_EXPORT void msStringBufferFree(msStringBuffer* sb);
2290   MS_DLL_EXPORT const char* msStringBufferGetString(msStringBuffer* sb);
2291   MS_DLL_EXPORT char* msStringBufferReleaseStringAndFree(msStringBuffer* sb);
2292   MS_DLL_EXPORT int msStringBufferAppend(msStringBuffer* sb, const char* pszAppendedString);
2293 
2294 #ifndef HAVE_STRRSTR
2295   MS_DLL_EXPORT char *strrstr(const char *string, const char *find);
2296 #endif /* NEED_STRRSTR */
2297 
2298 #ifndef HAVE_STRCASESTR
2299   MS_DLL_EXPORT char *strcasestr(const char *s, const char *find);
2300 #endif /* NEED_STRCASESTR */
2301 
2302 #ifndef HAVE_STRNCASECMP
2303   MS_DLL_EXPORT int strncasecmp(const char *s1, const char *s2, int len);
2304 #endif /* NEED_STRNCASECMP */
2305 
2306 #ifndef HAVE_STRCASECMP
2307   MS_DLL_EXPORT int strcasecmp(const char *s1, const char *s2);
2308 #endif /* NEED_STRCASECMP */
2309 
2310 #ifndef HAVE_STRLCAT
2311   MS_DLL_EXPORT size_t strlcat(char *dst, const char *src, size_t siz);
2312 #endif /* NEED_STRLCAT */
2313 
2314 #ifndef HAVE_STRLCPY
2315   MS_DLL_EXPORT size_t strlcpy(char *dst, const char *src, size_t siz);
2316 #endif /* NEED_STRLCAT */
2317 
2318   MS_DLL_EXPORT char *msStrdup( const char * pszString );
2319 
2320 #include "hittest.h"
2321 
2322   /* in mapsymbol.c */
2323   /* Use this function *only* with mapfile loading phase */
2324   MS_DLL_EXPORT int loadSymbolSet(symbolSetObj *symbolset, mapObj *map);
2325   /* Use this threadsafe wrapper everywhere else */
2326   MS_DLL_EXPORT int msLoadSymbolSet(symbolSetObj *symbolset, mapObj *map);
2327   MS_DLL_EXPORT int msCopySymbol(symbolObj *dst, symbolObj *src, mapObj *map);
2328   MS_DLL_EXPORT int msCopySymbolSet(symbolSetObj *dst, symbolSetObj *src, mapObj *map);
2329   MS_DLL_EXPORT int msCopyHashTable(hashTableObj *dst, hashTableObj *src);
2330   MS_DLL_EXPORT void msInitSymbolSet(symbolSetObj *symbolset);
2331   MS_DLL_EXPORT symbolObj *msGrowSymbolSet( symbolSetObj *symbolset );
2332   MS_DLL_EXPORT int msAddImageSymbol(symbolSetObj *symbolset, char *filename);
2333   MS_DLL_EXPORT int msFreeSymbolSet(symbolSetObj *symbolset);
2334   MS_DLL_EXPORT int msFreeSymbol(symbolObj *symbol);
2335   MS_DLL_EXPORT int msAddNewSymbol(mapObj *map, char *name);
2336   MS_DLL_EXPORT int msAppendSymbol(symbolSetObj *symbolset, symbolObj *symbol);
2337   MS_DLL_EXPORT symbolObj *msRemoveSymbol(symbolSetObj *symbolset, int index);
2338   MS_DLL_EXPORT int msSaveSymbolSet(symbolSetObj *symbolset, const char *filename);
2339   MS_DLL_EXPORT int msLoadImageSymbol(symbolObj *symbol, const char *filename);
2340   MS_DLL_EXPORT int msPreloadImageSymbol(rendererVTableObj *renderer, symbolObj *symbol);
2341   MS_DLL_EXPORT int msPreloadSVGSymbol(symbolObj *symbol);
2342   MS_DLL_EXPORT symbolObj *msRotateSymbol(symbolObj *symbol, double angle);
2343 
2344   MS_DLL_EXPORT int WARN_UNUSED msGetCharacterSize(mapObj *map, char* font, int size, char *character, rectObj *r);
2345   MS_DLL_EXPORT int WARN_UNUSED msGetMarkerSize(mapObj *map, styleObj *style, double *width, double *height, double scalefactor);
2346   /* MS_DLL_EXPORT int msGetCharacterSize(char *character, int size, char *font, rectObj *rect); */
2347   MS_DLL_EXPORT double msSymbolGetDefaultSize(symbolObj *s);
2348   MS_DLL_EXPORT void freeImageCache(struct imageCacheObj *ic);
2349 
2350   MS_DLL_EXPORT imageObj WARN_UNUSED *msDrawLegend(mapObj *map, int scale_independent, map_hittest *hittest); /* in maplegend.c */
2351   MS_DLL_EXPORT int WARN_UNUSED msLegendCalcSize(mapObj *map, int scale_independent, int *size_x, int *size_y,
2352                                      int *alayers, int numl_ayer, map_hittest *hittest, double resolutionfactor);
2353   MS_DLL_EXPORT int WARN_UNUSED msEmbedLegend(mapObj *map, imageObj *img);
2354   MS_DLL_EXPORT int WARN_UNUSED msDrawLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height, imageObj *img, int dstX, int dstY, int scale_independant, class_hittest *hittest);
2355   MS_DLL_EXPORT imageObj WARN_UNUSED *msCreateLegendIcon(mapObj* map, layerObj* lp, classObj* myClass, int width, int height, int scale_independant);
2356 
2357   MS_DLL_EXPORT int msLoadFontSet(fontSetObj *fontSet, mapObj *map); /* in maplabel.c */
2358   MS_DLL_EXPORT int msInitFontSet(fontSetObj *fontset);
2359   MS_DLL_EXPORT int msFreeFontSet(fontSetObj *fontset);
2360 
2361   MS_DLL_EXPORT int WARN_UNUSED msGetTextSymbolSize(mapObj *map, textSymbolObj *ts, rectObj *r);
2362   MS_DLL_EXPORT int WARN_UNUSED msGetStringSize(mapObj *map, labelObj *label, int size, char *string, rectObj *r);
2363 
2364   MS_DLL_EXPORT int WARN_UNUSED msAddLabel(mapObj *map, imageObj *image, labelObj *label, int layerindex, int classindex, shapeObj *shape, pointObj *point, double featuresize, textSymbolObj *ts);
2365   MS_DLL_EXPORT int WARN_UNUSED msAddLabelGroup(mapObj *map, imageObj *image, layerObj *layer, int classindex, shapeObj *shape, pointObj *point, double featuresize);
2366   MS_DLL_EXPORT void insertRenderedLabelMember(mapObj *map, labelCacheMemberObj *cachePtr);
2367   MS_DLL_EXPORT int msTestLabelCacheCollisions(mapObj *map, labelCacheMemberObj *cachePtr, label_bounds *lb, int current_priority, int current_label);
2368   MS_DLL_EXPORT int msTestLabelCacheLeaderCollision(mapObj *map, pointObj *lp1, pointObj *lp2);
2369   MS_DLL_EXPORT labelCacheMemberObj *msGetLabelCacheMember(labelCacheObj *labelcache, int i);
2370 
2371   MS_DLL_EXPORT void msFreeShape(shapeObj *shape); /* in mapprimitive.c */
2372   int msGetShapeRAMSize(shapeObj* shape); /* in mapprimitive.c */
2373   MS_DLL_EXPORT void msFreeLabelPathObj(labelPathObj *path);
2374   MS_DLL_EXPORT shapeObj *msShapeFromWKT(const char *string);
2375   MS_DLL_EXPORT char *msShapeToWKT(shapeObj *shape);
2376   MS_DLL_EXPORT void msInitShape(shapeObj *shape);
2377   MS_DLL_EXPORT void msShapeDeleteLine( shapeObj *shape, int line );
2378   MS_DLL_EXPORT int msCopyShape(shapeObj *from, shapeObj *to);
2379   MS_DLL_EXPORT int msIsOuterRing(shapeObj *shape, int r);
2380   MS_DLL_EXPORT int *msGetOuterList(shapeObj *shape);
2381   MS_DLL_EXPORT int *msGetInnerList(shapeObj *shape, int r, int *outerlist);
2382   MS_DLL_EXPORT void msComputeBounds(shapeObj *shape);
2383   MS_DLL_EXPORT void msRectToPolygon(rectObj rect, shapeObj *poly);
2384   MS_DLL_EXPORT void msClipPolylineRect(shapeObj *shape, rectObj rect);
2385   MS_DLL_EXPORT void msClipPolygonRect(shapeObj *shape, rectObj rect);
2386   MS_DLL_EXPORT void msTransformShape(shapeObj *shape, rectObj extent, double cellsize, imageObj *image);
2387   MS_DLL_EXPORT void msTransformPoint(pointObj *point, rectObj *extent, double cellsize, imageObj *image);
2388 
2389   MS_DLL_EXPORT void msOffsetPointRelativeTo(pointObj *point, layerObj *layer);
2390   MS_DLL_EXPORT void msOffsetShapeRelativeTo(shapeObj *shape, layerObj *layer);
2391   MS_DLL_EXPORT void msTransformShapeSimplify(shapeObj *shape, rectObj extent, double cellsize);
2392   MS_DLL_EXPORT void msTransformShapeToPixelSnapToGrid(shapeObj *shape, rectObj extent, double cellsize, double grid_resolution);
2393   MS_DLL_EXPORT void msTransformShapeToPixelRound(shapeObj *shape, rectObj extent, double cellsize);
2394   MS_DLL_EXPORT void msTransformShapeToPixelDoublePrecision(shapeObj *shape, rectObj extent, double cellsize);
2395 
2396 #ifndef SWIG
2397 
2398   struct line_lengths {
2399     double *segment_lengths;
2400     double total_length;
2401     int longest_segment_index;
2402   };
2403 
2404   struct polyline_lengths {
2405     struct line_lengths *ll;
2406     double total_length;
2407     int longest_line_index;
2408     int longest_segment_line_index, longest_segment_point_index;
2409   };
2410 
2411   struct label_auto_result {
2412     pointObj *label_points;
2413     double *angles;
2414     int num_label_points;
2415   };
2416 
2417   struct label_follow_result {
2418     textSymbolObj **follow_labels;
2419     int num_follow_labels;
2420     struct label_auto_result lar;
2421   };
2422 
2423 #endif
2424 
2425   MS_DLL_EXPORT void msTransformPixelToShape(shapeObj *shape, rectObj extent, double cellsize);
2426   MS_DLL_EXPORT void msPolylineComputeLineSegments(shapeObj *shape, struct polyline_lengths *pll);
2427   MS_DLL_EXPORT int msPolylineLabelPath(mapObj *map, imageObj *image, shapeObj *p, textSymbolObj *ts, labelObj *label, struct label_follow_result *lfr);
2428   MS_DLL_EXPORT int WARN_UNUSED msPolylineLabelPoint(mapObj *map, shapeObj *p, textSymbolObj *ts, labelObj *label, struct label_auto_result *lar, double resolutionfactor);
2429   MS_DLL_EXPORT int WARN_UNUSED msLineLabelPath(mapObj *map, imageObj *img, lineObj *p, textSymbolObj *ts, struct line_lengths *ll, struct label_follow_result *lfr, labelObj *lbl);
2430   MS_DLL_EXPORT int WARN_UNUSED msLineLabelPoint(mapObj *map, lineObj *p, textSymbolObj *ts, struct line_lengths *ll, struct label_auto_result *lar, labelObj *lbl, double resolutionfactor);
2431   MS_DLL_EXPORT int msPolygonLabelPoint(shapeObj *p, pointObj *lp, double min_dimension);
2432   MS_DLL_EXPORT int msAddLine(shapeObj *p, lineObj *new_line);
2433   MS_DLL_EXPORT int msAddLineDirectly(shapeObj *p, lineObj *new_line);
2434   MS_DLL_EXPORT int msAddPointToLine(lineObj *line, pointObj *point );
2435   MS_DLL_EXPORT double msGetPolygonArea(shapeObj *p);
2436   MS_DLL_EXPORT int msGetPolygonCentroid(shapeObj *p, pointObj *lp, double *miny, double *maxy);
2437 
2438   MS_DLL_EXPORT int msDrawRasterLayer(mapObj *map, layerObj *layer, imageObj *image); /* in mapraster.c */
2439   MS_DLL_EXPORT imageObj *msDrawReferenceMap(mapObj *map);
2440 
2441   /* mapbits.c - bit array handling functions and macros */
2442 
2443 #define MS_ARRAY_BIT 32
2444 
2445 #define MS_GET_BIT(array,i) (array[i>>5] & (1 <<(i & 0x3f)))
2446 #define MS_SET_BIT(array,i) {array[i>>5] |= (1 <<(i & 0x3f));}
2447 #define MS_CLR_BIT(array,i) {array[i>>5] &= (~(1 <<(i & 0x3f)));}
2448 
2449   MS_DLL_EXPORT size_t msGetBitArraySize(int numbits); /* in mapbits.c */
2450   MS_DLL_EXPORT ms_bitarray msAllocBitArray(int numbits);
2451   MS_DLL_EXPORT int msGetBit(ms_const_bitarray array, int index);
2452   MS_DLL_EXPORT void msSetBit(ms_bitarray array, int index, int value);
2453   MS_DLL_EXPORT void msSetAllBits(ms_bitarray array, int index, int value);
2454   MS_DLL_EXPORT void msFlipBit(ms_bitarray array, int index);
2455   MS_DLL_EXPORT int msGetNextBit(ms_const_bitarray array, int index, int size);
2456 
2457   /* maplayer.c - layerObj  api */
2458 
2459   MS_DLL_EXPORT int msLayerInitItemInfo(layerObj *layer);
2460   MS_DLL_EXPORT void msLayerFreeItemInfo(layerObj *layer);
2461 
2462   MS_DLL_EXPORT int msLayerOpen(layerObj *layer); /* in maplayer.c */
2463   MS_DLL_EXPORT int msLayerApplyScaletokens(layerObj *layer, double scale);
2464   MS_DLL_EXPORT int msLayerRestoreFromScaletokens(layerObj *layer);
2465   MS_DLL_EXPORT int msClusterLayerOpen(layerObj *layer); /* in mapcluster.c */
2466   MS_DLL_EXPORT int msLayerIsOpen(layerObj *layer);
2467   MS_DLL_EXPORT void msLayerClose(layerObj *layer);
2468   MS_DLL_EXPORT void msLayerFreeExpressions(layerObj *layer);
2469   MS_DLL_EXPORT int msLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery);
2470   MS_DLL_EXPORT int msLayerGetItemIndex(layerObj *layer, char *item);
2471   MS_DLL_EXPORT int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata);
2472   MS_DLL_EXPORT int msLayerNextShape(layerObj *layer, shapeObj *shape);
2473   MS_DLL_EXPORT int msLayerGetItems(layerObj *layer);
2474   MS_DLL_EXPORT int msLayerSetItems(layerObj *layer, char **items, int numitems);
2475   MS_DLL_EXPORT int msLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record);
2476   MS_DLL_EXPORT int msLayerGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection);
2477   MS_DLL_EXPORT int msLayerGetExtent(layerObj *layer, rectObj *extent);
2478   MS_DLL_EXPORT int msLayerSetExtent( layerObj *layer, double minx, double miny, double maxx, double maxy);
2479   MS_DLL_EXPORT int msLayerGetAutoStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* shape);
2480   MS_DLL_EXPORT int msLayerGetFeatureStyle(mapObj *map, layerObj *layer, classObj *c, shapeObj* shape);
2481   MS_DLL_EXPORT void msLayerAddProcessing( layerObj *layer, const char *directive );
2482   MS_DLL_EXPORT void msLayerSetProcessingKey( layerObj *layer, const char *key, const char *value);
2483   MS_DLL_EXPORT char *msLayerGetProcessing( layerObj *layer, int proc_index);
2484   MS_DLL_EXPORT char *msLayerGetProcessingKey( layerObj *layer, const char *);
2485   MS_DLL_EXPORT int msLayerClearProcessing( layerObj *layer );
2486   MS_DLL_EXPORT void msLayerSubstituteProcessing( layerObj *layer, const char *from, const char *to );
2487   MS_DLL_EXPORT char *msLayerGetFilterString( layerObj *layer );
2488   MS_DLL_EXPORT int msLayerEncodeShapeAttributes( layerObj *layer, shapeObj *shape);
2489 
2490   MS_DLL_EXPORT int msLayerTranslateFilter(layerObj *layer, expressionObj *filter, char *filteritem);
2491   MS_DLL_EXPORT int msLayerSupportsCommonFilters(layerObj *layer);
2492   MS_DLL_EXPORT const char *msExpressionTokenToString(int token);
2493   MS_DLL_EXPORT int msTokenizeExpression(expressionObj *expression, char **list, int *listsize);
2494 
2495   MS_DLL_EXPORT int msLayerSetTimeFilter(layerObj *lp, const char *timestring, const char *timefield);
2496   MS_DLL_EXPORT int msLayerMakeBackticsTimeFilter(layerObj *lp, const char *timestring, const char *timefield);
2497   MS_DLL_EXPORT int msLayerMakePlainTimeFilter(layerObj *lp, const char *timestring, const char *timefield);
2498 
2499   MS_DLL_EXPORT int msLayerApplyCondSQLFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex);
2500   MS_DLL_EXPORT int msLayerApplyPlainFilterToLayer(FilterEncodingNode *psNode, mapObj *map, int iLayerIndex);
2501 
2502   /* maplayer.c */
2503   MS_DLL_EXPORT int msLayerGetNumFeatures(layerObj *layer);
2504 
2505   MS_DLL_EXPORT int msLayerSupportsPaging(layerObj *layer);
2506 
2507   MS_DLL_EXPORT void msLayerEnablePaging(layerObj *layer, int value);
2508   MS_DLL_EXPORT int msLayerGetPaging(layerObj *layer);
2509 
2510   MS_DLL_EXPORT int msLayerGetMaxFeaturesToDraw(layerObj *layer, outputFormatObj *format);
2511 
2512   MS_DLL_EXPORT char *msLayerEscapeSQLParam(layerObj *layer, const char* pszString);
2513   MS_DLL_EXPORT char *msLayerEscapePropertyName(layerObj *layer, const char* pszString);
2514 
2515   int msLayerSupportsSorting(layerObj *layer);
2516   void msLayerSetSort(layerObj *layer, const sortByClause* sortBy);
2517   MS_DLL_EXPORT char* msLayerBuildSQLOrderBy(layerObj *layer);
2518 
2519   /* These are special because SWF is using these */
2520   int msOGRLayerNextShape(layerObj *layer, shapeObj *shape);
2521   int msOGRLayerGetItems(layerObj *layer);
2522   void msOGRLayerFreeItemInfo(layerObj *layer);
2523   int msOGRLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record);
2524   int msOGRLayerGetExtent(layerObj *layer, rectObj *extent);
2525 
2526   MS_DLL_EXPORT int msOGRGeometryToShape(OGRGeometryH hGeometry, shapeObj *shape,
2527                                          OGRwkbGeometryType type);
2528 
2529   MS_DLL_EXPORT int msInitializeVirtualTable(layerObj *layer);
2530   MS_DLL_EXPORT int msConnectLayer(layerObj *layer, const int connectiontype,
2531                                    const char *library_str);
2532 
2533   MS_DLL_EXPORT int msINLINELayerInitializeVirtualTable(layerObj *layer);
2534   MS_DLL_EXPORT int msSHPLayerInitializeVirtualTable(layerObj *layer);
2535   MS_DLL_EXPORT int msTiledSHPLayerInitializeVirtualTable(layerObj *layer);
2536   MS_DLL_EXPORT int msOGRLayerInitializeVirtualTable(layerObj *layer);
2537   MS_DLL_EXPORT int msPostGISLayerInitializeVirtualTable(layerObj *layer);
2538   MS_DLL_EXPORT int msOracleSpatialLayerInitializeVirtualTable(layerObj *layer);
2539   MS_DLL_EXPORT int msWFSLayerInitializeVirtualTable(layerObj *layer);
2540   MS_DLL_EXPORT int msGraticuleLayerInitializeVirtualTable(layerObj *layer);
2541   MS_DLL_EXPORT int msRASTERLayerInitializeVirtualTable(layerObj *layer);
2542   MS_DLL_EXPORT int msUVRASTERLayerInitializeVirtualTable(layerObj *layer);
2543   MS_DLL_EXPORT int msContourLayerInitializeVirtualTable(layerObj *layer);
2544   MS_DLL_EXPORT int msPluginLayerInitializeVirtualTable(layerObj *layer);
2545   MS_DLL_EXPORT int msUnionLayerInitializeVirtualTable(layerObj *layer);
2546   MS_DLL_EXPORT void msPluginFreeVirtualTableFactory(void);
2547 
2548   MS_DLL_EXPORT int LayerDefaultGetShapeCount(layerObj *layer, rectObj rect, projectionObj *rectProjection);
2549   void msUVRASTERLayerUseMapExtentAndProjectionForNextWhichShapes(layerObj* layer, mapObj* map);
2550   rectObj msUVRASTERGetSearchRect( layerObj* layer, mapObj* map );
2551 
2552   /* ==================================================================== */
2553   /*      Prototypes for functions in mapdraw.c                           */
2554   /* ==================================================================== */
2555 
2556   MS_DLL_EXPORT imageObj *msPrepareImage(mapObj *map, int allow_nonsquare);
2557   MS_DLL_EXPORT imageObj *msDrawMap(mapObj *map, int querymap);
2558   MS_DLL_EXPORT int msLayerIsVisible(mapObj *map, layerObj *layer);
2559   MS_DLL_EXPORT int msDrawLayer(mapObj *map, layerObj *layer, imageObj *image);
2560   MS_DLL_EXPORT int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image);
2561   MS_DLL_EXPORT int msDrawQueryLayer(mapObj *map, layerObj *layer, imageObj *image);
2562   MS_DLL_EXPORT int msDrawWMSLayer(mapObj *map, layerObj *layer, imageObj *image);
2563   MS_DLL_EXPORT int msDrawWFSLayer(mapObj *map, layerObj *layer, imageObj *image);
2564 
2565 #define MS_DRAWMODE_FEATURES    0x00001
2566 #define MS_DRAW_FEATURES(mode) (MS_DRAWMODE_FEATURES&(mode))
2567 #define MS_DRAWMODE_LABELS      0x00002
2568 #define MS_DRAW_LABELS(mode) (MS_DRAWMODE_LABELS&(mode))
2569 #define MS_DRAWMODE_SINGLESTYLE 0x00004
2570 #define MS_DRAW_SINGLESTYLE(mode) (MS_DRAWMODE_SINGLESTYLE&(mode))
2571 #define MS_DRAWMODE_QUERY       0x00008
2572 #define MS_DRAW_QUERY(mode) (MS_DRAWMODE_QUERY&(mode))
2573 #define MS_DRAWMODE_UNCLIPPEDLABELS       0x00010
2574 #define MS_DRAW_UNCLIPPED_LABELS(mode) (MS_DRAWMODE_UNCLIPPEDLABELS&(mode))
2575 #define MS_DRAWMODE_UNCLIPPEDLINES       0x00020
2576 #define MS_DRAW_UNCLIPPED_LINES(mode) (MS_DRAWMODE_UNCLIPPEDLINES&(mode))
2577 
2578   MS_DLL_EXPORT int WARN_UNUSED msDrawShape(mapObj *map, layerObj *layer, shapeObj *shape, imageObj *image, int style, int mode);
2579   MS_DLL_EXPORT int WARN_UNUSED msDrawPoint(mapObj *map, layerObj *layer, pointObj *point, imageObj *image, int classindex, char *labeltext);
2580 
2581   /*Range Support*/
2582   typedef enum {
2583     MS_COLORSPACE_RGB,
2584     MS_COLORSPACE_HSL
2585   } colorspace;
2586   MS_DLL_EXPORT int msShapeToRange(styleObj *style, shapeObj *shape);
2587   MS_DLL_EXPORT int msValueToRange(styleObj *style, double fieldVal, colorspace cs);
2588 
2589   MS_DLL_EXPORT int WARN_UNUSED msDrawMarkerSymbol(mapObj *map, imageObj *image, pointObj *p, styleObj *style, double scalefactor);
2590   MS_DLL_EXPORT int WARN_UNUSED msDrawLineSymbol(mapObj *map, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
2591   MS_DLL_EXPORT int WARN_UNUSED msDrawShadeSymbol(mapObj *map, imageObj *image, shapeObj *p, styleObj *style, double scalefactor);
2592   MS_DLL_EXPORT int WARN_UNUSED msCircleDrawLineSymbol(mapObj *map, imageObj *image, pointObj *p, double r, styleObj *style, double scalefactor);
2593   MS_DLL_EXPORT int WARN_UNUSED msCircleDrawShadeSymbol(mapObj *map, imageObj *image, pointObj *p, double r, styleObj *style, double scalefactor);
2594   MS_DLL_EXPORT int WARN_UNUSED msDrawPieSlice(mapObj *map, imageObj *image, pointObj *p, styleObj *style, double radius, double start, double end);
2595   MS_DLL_EXPORT int WARN_UNUSED msDrawLabelBounds(mapObj *map, imageObj *image, label_bounds *bnds, styleObj *style, double scalefactor);
2596 
2597   MS_DLL_EXPORT void msOutlineRenderingPrepareStyle(styleObj *pStyle, mapObj *map, layerObj *layer, imageObj *image);
2598   MS_DLL_EXPORT void msOutlineRenderingRestoreStyle(styleObj *pStyle, mapObj *map, layerObj *layer, imageObj *image);
2599 
2600   MS_DLL_EXPORT int WARN_UNUSED msDrawLabel(mapObj *map, imageObj *image, pointObj labelPnt, char *string, labelObj *label, double scalefactor);
2601   MS_DLL_EXPORT int WARN_UNUSED msDrawTextSymbol(mapObj *map, imageObj *image, pointObj labelPnt, textSymbolObj *ts);
2602   MS_DLL_EXPORT int WARN_UNUSED msDrawLabelCache(mapObj *map, imageObj *image);
2603 
2604   MS_DLL_EXPORT void msImageStartLayer(mapObj *map, layerObj *layer, imageObj *image);
2605   MS_DLL_EXPORT void msImageEndLayer(mapObj *map, layerObj *layer, imageObj *image);
2606 
2607   MS_DLL_EXPORT void msDrawStartShape(mapObj *map, layerObj *layer, imageObj *image, shapeObj *shape);
2608   MS_DLL_EXPORT void msDrawEndShape(mapObj *map, layerObj *layer, imageObj *image, shapeObj *shape);
2609   /* ==================================================================== */
2610   /*      End of Prototypes for functions in mapdraw.c                    */
2611   /* ==================================================================== */
2612 
2613   /* ==================================================================== */
2614   /*      Prototypes for functions in mapgeomutil.cpp                       */
2615   /* ==================================================================== */
2616   MS_DLL_EXPORT shapeObj *msRasterizeArc(double x0, double y0, double radius, double startAngle, double endAngle, int isSlice);
2617   MS_DLL_EXPORT int msHatchPolygon(imageObj *img, shapeObj *poly, double spacing, double width, double *pattern, int patternlength, double angle, colorObj *color);
2618 
2619 
2620 
2621   /* ==================================================================== */
2622   /*      Prototypes for functions in mapimagemap.c                       */
2623   /* ==================================================================== */
2624   MS_DLL_EXPORT imageObj *msImageCreateIM(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, double resolution, double defresolution);
2625   MS_DLL_EXPORT void msImageStartLayerIM(mapObj *map, layerObj *layer, imageObj *image);
2626   MS_DLL_EXPORT int msSaveImageIM(imageObj* img, const char *filename, outputFormatObj *format);
2627   MS_DLL_EXPORT void msFreeImageIM(imageObj* img);
2628   MS_DLL_EXPORT void msDrawMarkerSymbolIM(mapObj *map, imageObj* img, pointObj *p, styleObj *style, double scalefactor);
2629   MS_DLL_EXPORT void msDrawLineSymbolIM(mapObj *map, imageObj* img, shapeObj *p, styleObj *style, double scalefactor);
2630   MS_DLL_EXPORT void msDrawShadeSymbolIM(mapObj *map, imageObj* img, shapeObj *p, styleObj *style, double scalefactor);
2631   MS_DLL_EXPORT int msDrawTextIM(mapObj *map, imageObj* img, pointObj labelPnt, char *string, labelObj *label, double scalefactor);
2632   /* ==================================================================== */
2633   /*      End of Prototypes for functions in mapimagemap.c                */
2634   /* ==================================================================== */
2635 
2636 
2637   /* various JOIN functions (in mapjoin.c) */
2638   MS_DLL_EXPORT int msJoinConnect(layerObj *layer, joinObj *join);
2639   MS_DLL_EXPORT int msJoinPrepare(joinObj *join, shapeObj *shape);
2640   MS_DLL_EXPORT int msJoinNext(joinObj *join);
2641   MS_DLL_EXPORT int msJoinClose(joinObj *join);
2642 
2643   /*in mapraster.c */
2644   int msDrawRasterLayerLowCheckIfMustDraw(mapObj *map, layerObj *layer);
2645   void* msDrawRasterLayerLowOpenDataset(mapObj *map, layerObj *layer,
2646                                       const char* filename,
2647                                       char szPath[MS_MAXPATHLEN],
2648                                       char** p_decrypted_path);
2649   void msDrawRasterLayerLowCloseDataset(layerObj *layer, void* hDataset);
2650   int msDrawRasterLayerLowWithDataset(mapObj *map, layerObj *layer, imageObj *image, rasterBufferObj *rb, void* hDatasetIn );
2651 
2652   MS_DLL_EXPORT int msDrawRasterLayerLow(mapObj *map, layerObj *layer, imageObj *image, rasterBufferObj *rb );
2653   MS_DLL_EXPORT int msGetClass(layerObj *layer, colorObj *color, int colormap_index);
2654   MS_DLL_EXPORT int msGetClass_FloatRGB(layerObj *layer, float fValue,
2655                                         int red, int green, int blue );
2656   int msGetClass_FloatRGB_WithFirstClassToTry(layerObj *layer, float fValue, int red, int green, int blue, int firstClassToTry );
2657 
2658   /* in mapdrawgdal.c */
2659   MS_DLL_EXPORT int msDrawRasterLayerGDAL(mapObj *map, layerObj *layer, imageObj *image, rasterBufferObj *rb, void *hDSVoid );
2660   MS_DLL_EXPORT int msGetGDALGeoTransform(void *hDS, mapObj *map, layerObj *layer, double *padfGeoTransform );
2661   MS_DLL_EXPORT int *msGetGDALBandList( layerObj *layer, void *hDS, int max_bands, int *band_count );
2662   MS_DLL_EXPORT double msGetGDALNoDataValue( layerObj *layer, void *hBand, int *pbGotNoData );
2663 
2664   /* in interpolation.c */
2665   MS_DLL_EXPORT int msComputeKernelDensityDataset(mapObj *map, imageObj *image, layerObj *layer, void **hDSvoid, void **cleanup_ptr);
2666   MS_DLL_EXPORT int msCleanupKernelDensityDataset(mapObj *map, imageObj *image, layerObj *layer, void *cleanup_ptr);
2667 
2668   /* in mapchart.c */
2669   MS_DLL_EXPORT int msDrawChartLayer(mapObj *map, layerObj *layer, imageObj *image);
2670 
2671   /* ==================================================================== */
2672   /*      End of prototypes for functions in mapgd.c                      */
2673   /* ==================================================================== */
2674 
2675   /* ==================================================================== */
2676   /*      Prototypes for functions in maputil.c                           */
2677   /* ==================================================================== */
2678 
2679   MS_DLL_EXPORT int msScaleInBounds(double scale, double minscale, double maxscale);
2680   MS_DLL_EXPORT void *msSmallMalloc( size_t nSize );
2681   MS_DLL_EXPORT void * msSmallRealloc( void * pData, size_t nNewSize );
2682   MS_DLL_EXPORT void *msSmallCalloc( size_t nCount, size_t nSize );
2683   MS_DLL_EXPORT int msIntegerInArray(const int value, int *array, int numelements);
2684 
2685   MS_DLL_EXPORT int msExtentsOverlap(mapObj *map, layerObj *layer);
2686   MS_DLL_EXPORT char *msBuildOnlineResource(mapObj *map, cgiRequestObj *req);
2687 
2688   /* For mapswf */
2689   MS_DLL_EXPORT int getRgbColor(mapObj *map,int i,int *r,int *g,int *b); /* maputil.c */
2690 
2691   MS_DLL_EXPORT int msBindLayerToShape(layerObj *layer, shapeObj *shape, int querymapMode);
2692   MS_DLL_EXPORT int msValidateContexts(mapObj *map);
2693   MS_DLL_EXPORT int msEvalContext(mapObj *map, layerObj *layer, char *context);
2694   MS_DLL_EXPORT int msEvalExpression(layerObj *layer, shapeObj *shape, expressionObj *expression, int itemindex);
2695   MS_DLL_EXPORT int msShapeGetClass(layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses);
2696   MS_DLL_EXPORT int msShapeGetNextClass(int currentclass, layerObj *layer, mapObj *map, shapeObj *shape, int *classgroup, int numclasses);
2697   MS_DLL_EXPORT int msShapeCheckSize(shapeObj *shape, double minfeaturesize);
2698   MS_DLL_EXPORT char* msShapeGetLabelAnnotation(layerObj *layer, shapeObj *shape, labelObj *lbl);
2699   MS_DLL_EXPORT int msGetLabelStatus(mapObj *map, layerObj *layer, shapeObj *shape, labelObj *lbl);
2700   MS_DLL_EXPORT int msAdjustImage(rectObj rect, int *width, int *height);
2701   MS_DLL_EXPORT char *msEvalTextExpression(expressionObj *expr, shapeObj *shape);
2702   MS_DLL_EXPORT char *msEvalTextExpressionJSonEscape(expressionObj *expr, shapeObj *shape);
2703   MS_DLL_EXPORT double msEvalDoubleExpression(expressionObj *expr, shapeObj *shape);
2704   MS_DLL_EXPORT double msAdjustExtent(rectObj *rect, int width, int height);
2705   MS_DLL_EXPORT int msConstrainExtent(rectObj *bounds, rectObj *rect, double overlay);
2706   MS_DLL_EXPORT int *msGetLayersIndexByGroup(mapObj *map, char *groupname, int *nCount);
2707   MS_DLL_EXPORT unsigned char *msSaveImageBuffer(imageObj* image, int *size_ptr, outputFormatObj *format);
2708   MS_DLL_EXPORT shapeObj* msOffsetPolyline(shapeObj* shape, double offsetx, double offsety);
2709   MS_DLL_EXPORT int msMapSetLayerProjections(mapObj* map);
2710 
2711   /* Functions to chnage the drawing order of the layers. */
2712   /* Defined in mapobject.c */
2713   MS_DLL_EXPORT int msMoveLayerUp(mapObj *map, int nLayerIndex);
2714   MS_DLL_EXPORT int msMoveLayerDown(mapObj *map, int nLayerIndex);
2715   MS_DLL_EXPORT int msSetLayersdrawingOrder(mapObj *self, int *panIndexes);
2716   MS_DLL_EXPORT int msInsertLayer(mapObj *map, layerObj *layer, int nIndex);
2717   MS_DLL_EXPORT layerObj *msRemoveLayer(mapObj *map, int nIndex);
2718 
2719   /* Defined in layerobject.c */
2720   MS_DLL_EXPORT int msInsertClass(layerObj *layer,classObj *classobj,int nIndex);
2721   MS_DLL_EXPORT classObj *msRemoveClass(layerObj *layer, int nIndex);
2722   MS_DLL_EXPORT int msMoveClassUp(layerObj *layer, int nClassIndex);
2723   MS_DLL_EXPORT int msMoveClassDown(layerObj *layer, int nClassIndex);
2724 
2725   /* classobject.c */
2726   MS_DLL_EXPORT int msAddLabelToClass(classObj *classo, labelObj *label);
2727   MS_DLL_EXPORT labelObj *msRemoveLabelFromClass(classObj *classo, int nLabelIndex);
2728   MS_DLL_EXPORT int msMoveStyleUp(classObj *classo, int nStyleIndex);
2729   MS_DLL_EXPORT int msMoveStyleDown(classObj *classo, int nStyleIndex);
2730   MS_DLL_EXPORT int msDeleteStyle(classObj *classo, int nStyleIndex);
2731   MS_DLL_EXPORT int msInsertStyle(classObj *classo, styleObj *style, int nStyleIndex);
2732   MS_DLL_EXPORT styleObj *msRemoveStyle(classObj *classo, int index);
2733 
2734   /* maplabel.c */
2735   MS_DLL_EXPORT int msInsertLabelStyle(labelObj *label, styleObj *style,
2736                                        int nStyleIndex);
2737   MS_DLL_EXPORT int msMoveLabelStyleUp(labelObj *label, int nStyleIndex);
2738   MS_DLL_EXPORT int msMoveLabelStyleDown(labelObj *label, int nStyleIndex);
2739   MS_DLL_EXPORT int msDeleteLabelStyle(labelObj *label, int nStyleIndex);
2740   MS_DLL_EXPORT styleObj *msRemoveLabelStyle(labelObj *label, int nStyleIndex);
2741 
2742   /* Measured shape utility functions. */
2743   MS_DLL_EXPORT pointObj *msGetPointUsingMeasure(shapeObj *shape, double m);
2744   MS_DLL_EXPORT pointObj *msGetMeasureUsingPoint(shapeObj *shape, pointObj *point);
2745 
2746   MS_DLL_EXPORT char **msGetAllGroupNames(mapObj* map, int *numTok);
2747   MS_DLL_EXPORT char *msTmpFile(mapObj *map, const char *mappath, const char *tmppath, const char *ext);
2748   MS_DLL_EXPORT char *msTmpPath(mapObj *map, const char *mappath, const char *tmppath);
2749   MS_DLL_EXPORT char *msTmpFilename(const char *ext);
2750   MS_DLL_EXPORT void msForceTmpFileBase( const char *new_base );
2751 
2752 
2753   MS_DLL_EXPORT imageObj *msImageCreate(int width, int height, outputFormatObj *format, char *imagepath, char *imageurl, double resolution, double defresolution, colorObj *bg);
2754 
2755   MS_DLL_EXPORT void msAlphaBlend(
2756     unsigned char red_src, unsigned char green_src,
2757     unsigned char blue_src, unsigned char alpha_src,
2758     unsigned char *red_dst, unsigned char *green_dst,
2759     unsigned char *blue_dst, unsigned char *alpha_dst );
2760   MS_DLL_EXPORT void msAlphaBlendPM(
2761     unsigned char red_src, unsigned char green_src,
2762     unsigned char blue_src, unsigned char alpha_src,
2763     unsigned char *red_dst, unsigned char *green_dst,
2764     unsigned char *blue_dst, unsigned char *alpha_dst );
2765 
2766   MS_DLL_EXPORT void msRGBtoHSL(colorObj *rgb, double *h, double *s, double *l);
2767 
2768   MS_DLL_EXPORT void msHSLtoRGB(double h, double s, double l, colorObj *rgb);
2769 
2770   MS_DLL_EXPORT int msCheckParentPointer(void* p, char* objname);
2771 
2772   MS_DLL_EXPORT int *msAllocateValidClassGroups(layerObj *lp, int *nclasses);
2773 
2774   MS_DLL_EXPORT void msFreeRasterBuffer(rasterBufferObj *b);
2775   MS_DLL_EXPORT void msSetLayerOpacity(layerObj *layer, int opacity);
2776 
2777   void msMapSetLanguageSpecificConnection(mapObj* map, const char* validated_language);
2778   MS_DLL_EXPORT shapeObj* msGeneralize(shapeObj * shape, double tolerance);
2779   /* ==================================================================== */
2780   /*      End of prototypes for functions in maputil.c                    */
2781   /* ==================================================================== */
2782 
2783 
2784   /* ==================================================================== */
2785   /*      prototypes for functions in mapoutput.c                         */
2786   /* ==================================================================== */
2787 
2788   MS_DLL_EXPORT void msApplyDefaultOutputFormats( mapObj * );
2789   MS_DLL_EXPORT void msFreeOutputFormat( outputFormatObj * );
2790   MS_DLL_EXPORT int msGetOutputFormatIndex(mapObj *map, const char *imagetype);
2791   MS_DLL_EXPORT int msRemoveOutputFormat(mapObj *map, const char *imagetype);
2792   MS_DLL_EXPORT int msAppendOutputFormat(mapObj *map, outputFormatObj *format);
2793   MS_DLL_EXPORT outputFormatObj *msSelectOutputFormat( mapObj *map, const char *imagetype );
2794   MS_DLL_EXPORT void msApplyOutputFormat( outputFormatObj **target, outputFormatObj *format, int transparent, int interlaced, int imagequality );
2795   MS_DLL_EXPORT const char *msGetOutputFormatOption( outputFormatObj *format, const char *optionkey, const char *defaultresult );
2796   MS_DLL_EXPORT outputFormatObj *msCreateDefaultOutputFormat( mapObj *map, const char *driver, const char *name );
2797   MS_DLL_EXPORT int msPostMapParseOutputFormatSetup( mapObj *map );
2798   MS_DLL_EXPORT void msSetOutputFormatOption( outputFormatObj *format, const char *key, const char *value );
2799   MS_DLL_EXPORT void msGetOutputFormatMimeList( mapObj *map, char **mime_list, int max_mime );
2800   MS_DLL_EXPORT void msGetOutputFormatMimeListImg( mapObj *map, char **mime_list, int max_mime );
2801   MS_DLL_EXPORT void msGetOutputFormatMimeListWMS( mapObj *map, char **mime_list, int max_mime );
2802   MS_DLL_EXPORT outputFormatObj *msCloneOutputFormat( outputFormatObj *format );
2803   MS_DLL_EXPORT int msOutputFormatValidate( outputFormatObj *format,
2804       int issue_error );
2805   void  msOutputFormatResolveFromImage( mapObj *map, imageObj* img );
2806 
2807   /* ==================================================================== */
2808   /*      End of prototypes for functions in mapoutput.c                  */
2809   /* ==================================================================== */
2810 
2811   /* ==================================================================== */
2812   /*      prototypes for functions in mapgdal.c                           */
2813   /* ==================================================================== */
2814   MS_DLL_EXPORT int msSaveImageGDAL( mapObj *map, imageObj *image, const char *filename );
2815   MS_DLL_EXPORT int msInitDefaultGDALOutputFormat( outputFormatObj *format );
2816   void msCleanVSIDir( const char *pszDir );
2817   char** msGetStringListFromHashTable(hashTableObj* table);
2818 
2819   /* ==================================================================== */
2820   /*      prototypes for functions in mapogroutput.c                      */
2821   /* ==================================================================== */
2822   MS_DLL_EXPORT int msInitDefaultOGROutputFormat( outputFormatObj *format );
2823   MS_DLL_EXPORT int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format,
2824                                          int sendheaders );
2825 
2826   /* ==================================================================== */
2827   /*      Public prototype for mapogr.cpp functions.                      */
2828   /* ==================================================================== */
2829   int MS_DLL_EXPORT msOGRLayerWhichShapes(layerObj *layer, rectObj rect, int isQuery);
2830   int MS_DLL_EXPORT msOGRLayerOpen(layerObj *layer, const char *pszOverrideConnection); /* in mapogr.cpp */
2831   int MS_DLL_EXPORT msOGRLayerClose(layerObj *layer);
2832 
2833   char MS_DLL_EXPORT *msOGRShapeToWKT(shapeObj *shape);
2834   shapeObj MS_DLL_EXPORT *msOGRShapeFromWKT(const char *string);
2835   int msOGRUpdateStyleFromString(mapObj *map, layerObj *layer, classObj *c,
2836                                  const char *stylestring);
2837 
2838   /* ==================================================================== */
2839   /*      prototypes for functions in mapcopy                             */
2840   /* ==================================================================== */
2841   MS_DLL_EXPORT int msCopyMap(mapObj *dst, mapObj *src);
2842   MS_DLL_EXPORT int msCopyLayer(layerObj *dst, layerObj *src);
2843   MS_DLL_EXPORT int msCopyScaleToken(scaleTokenObj *src, scaleTokenObj *dst);
2844   MS_DLL_EXPORT int msCopyPoint(pointObj *dst, pointObj *src);
2845   MS_DLL_EXPORT int msCopyFontSet(fontSetObj *dst, fontSetObj *src, mapObj *map);
2846   MS_DLL_EXPORT void copyProperty(void *dst, void *src, int size);
2847   MS_DLL_EXPORT char *copyStringProperty(char **dst, char *src);
2848   MS_DLL_EXPORT int msCopyClass(classObj *dst, classObj *src, layerObj *layer);
2849   MS_DLL_EXPORT int msCopyStyle(styleObj *dst, styleObj *src);
2850   MS_DLL_EXPORT int msCopyLabel(labelObj *dst, labelObj *src);
2851   MS_DLL_EXPORT int msCopyLabelLeader(labelLeaderObj *dst, labelLeaderObj *src);
2852   MS_DLL_EXPORT int msCopyLine(lineObj *dst, lineObj *src);
2853   MS_DLL_EXPORT int msCopyProjection(projectionObj *dst, projectionObj *src);
2854   MS_DLL_EXPORT int msCopyProjectionExtended(projectionObj *dst, projectionObj *src, char ** args, int num_args);
2855   int msCopyExpression(expressionObj *dst, expressionObj *src);
2856   int msCopyProjection(projectionObj *dst, projectionObj *src);
2857   MS_DLL_EXPORT int msCopyRasterBuffer(rasterBufferObj *dst, const rasterBufferObj *src);
2858 
2859   /* ==================================================================== */
2860   /*      end prototypes for functions in mapcopy                         */
2861   /* ==================================================================== */
2862 
2863   /* ==================================================================== */
2864   /*      mappool.c: connection pooling API.                              */
2865   /* ==================================================================== */
2866   MS_DLL_EXPORT void *msConnPoolRequest( layerObj *layer );
2867   MS_DLL_EXPORT void msConnPoolRelease( layerObj *layer, void * );
2868   MS_DLL_EXPORT void msConnPoolRegister( layerObj *layer,
2869                                          void *conn_handle,
2870                                          void (*close)( void * ) );
2871   MS_DLL_EXPORT void msConnPoolCloseUnreferenced( void );
2872   MS_DLL_EXPORT void msConnPoolFinalCleanup( void );
2873 
2874   /* ==================================================================== */
2875   /*      prototypes for functions in mapcpl.c                            */
2876   /* ==================================================================== */
2877   MS_DLL_EXPORT const char *msGetBasename( const char *pszFullFilename );
2878   MS_DLL_EXPORT void *msGetSymbol(const char *pszLibrary,
2879                                   const char *pszEntryPoint);
2880 
2881   /* ==================================================================== */
2882   /*      prototypes for functions in mapgeos.c                         */
2883   /* ==================================================================== */
2884   MS_DLL_EXPORT void msGEOSSetup(void);
2885   MS_DLL_EXPORT void msGEOSCleanup(void);
2886   MS_DLL_EXPORT void msGEOSFreeGeometry(shapeObj *shape);
2887 
2888   MS_DLL_EXPORT shapeObj *msGEOSShapeFromWKT(const char *string);
2889   MS_DLL_EXPORT char *msGEOSShapeToWKT(shapeObj *shape);
2890   MS_DLL_EXPORT void msGEOSFreeWKT(char* pszGEOSWKT);
2891 
2892   MS_DLL_EXPORT shapeObj *msGEOSBuffer(shapeObj *shape, double width);
2893   MS_DLL_EXPORT shapeObj *msGEOSSimplify(shapeObj *shape, double tolerance);
2894   MS_DLL_EXPORT shapeObj *msGEOSTopologyPreservingSimplify(shapeObj *shape, double tolerance);
2895   MS_DLL_EXPORT shapeObj *msGEOSConvexHull(shapeObj *shape);
2896   MS_DLL_EXPORT shapeObj *msGEOSBoundary(shapeObj *shape);
2897   MS_DLL_EXPORT pointObj *msGEOSGetCentroid(shapeObj *shape);
2898   MS_DLL_EXPORT shapeObj *msGEOSUnion(shapeObj *shape1, shapeObj *shape2);
2899   MS_DLL_EXPORT shapeObj *msGEOSIntersection(shapeObj *shape1, shapeObj *shape2);
2900   MS_DLL_EXPORT shapeObj *msGEOSDifference(shapeObj *shape1, shapeObj *shape2);
2901   MS_DLL_EXPORT shapeObj *msGEOSSymDifference(shapeObj *shape1, shapeObj *shape2);
2902   MS_DLL_EXPORT shapeObj *msGEOSOffsetCurve(shapeObj *p, double offset);
2903 
2904   MS_DLL_EXPORT int msGEOSContains(shapeObj *shape1, shapeObj *shape2);
2905   MS_DLL_EXPORT int msGEOSOverlaps(shapeObj *shape1, shapeObj *shape2);
2906   MS_DLL_EXPORT int msGEOSWithin(shapeObj *shape1, shapeObj *shape2);
2907   MS_DLL_EXPORT int msGEOSCrosses(shapeObj *shape1, shapeObj *shape2);
2908   MS_DLL_EXPORT int msGEOSIntersects(shapeObj *shape1, shapeObj *shape2);
2909   MS_DLL_EXPORT int msGEOSTouches(shapeObj *shape1, shapeObj *shape2);
2910   MS_DLL_EXPORT int msGEOSEquals(shapeObj *shape1, shapeObj *shape2);
2911   MS_DLL_EXPORT int msGEOSDisjoint(shapeObj *shape1, shapeObj *shape2);
2912 
2913   MS_DLL_EXPORT double msGEOSArea(shapeObj *shape);
2914   MS_DLL_EXPORT double msGEOSLength(shapeObj *shape);
2915   MS_DLL_EXPORT double msGEOSDistance(shapeObj *shape1, shapeObj *shape2);
2916 
2917   /* ==================================================================== */
2918   /*      prototypes for functions in mapcrypto.c                         */
2919   /* ==================================================================== */
2920   MS_DLL_EXPORT int msGenerateEncryptionKey(unsigned char *k);
2921   MS_DLL_EXPORT int msReadEncryptionKeyFromFile(const char *keyfile, unsigned char *k);
2922   MS_DLL_EXPORT void msEncryptStringWithKey(const unsigned char *key, const char *in, char *out);
2923   MS_DLL_EXPORT void msDecryptStringWithKey(const unsigned char *key, const char *in, char *out);
2924   MS_DLL_EXPORT char *msDecryptStringTokens(mapObj *map, const char *in);
2925   MS_DLL_EXPORT void msHexEncode(const unsigned char *in, char *out, int numbytes);
2926   MS_DLL_EXPORT int msHexDecode(const char *in, unsigned char *out, int numchars);
2927 
2928   /* ==================================================================== */
2929   /*      prototypes for functions in mapxmp.c                            */
2930   /* ==================================================================== */
2931   MS_DLL_EXPORT int msXmpPresent(mapObj *map);
2932   MS_DLL_EXPORT int msXmpWrite(mapObj *map, const char *filename);
2933 
2934   /* ==================================================================== */
2935   /*      prototypes for functions in mapgeomtransform.c                  */
2936   /* ==================================================================== */
2937   enum MS_GEOMTRANSFORM_TYPE {
2938     MS_GEOMTRANSFORM_NONE,
2939     MS_GEOMTRANSFORM_EXPRESSION,
2940     MS_GEOMTRANSFORM_START,
2941     MS_GEOMTRANSFORM_END,
2942     MS_GEOMTRANSFORM_VERTICES,
2943     MS_GEOMTRANSFORM_BBOX,
2944     MS_GEOMTRANSFORM_CENTROID,
2945     MS_GEOMTRANSFORM_BUFFER,
2946     MS_GEOMTRANSFORM_CONVEXHULL,
2947     MS_GEOMTRANSFORM_LABELPOINT,
2948     MS_GEOMTRANSFORM_LABELPOLY,
2949     MS_GEOMTRANSFORM_LABELCENTER
2950   };
2951 
2952   MS_DLL_EXPORT int msDrawTransformedShape(mapObj *map, imageObj *image, shapeObj *shape, styleObj *style, double scalefactor);
2953   MS_DLL_EXPORT void msStyleSetGeomTransform(styleObj *s, char *transform);
2954   MS_DLL_EXPORT char *msStyleGetGeomTransform(styleObj *style);
2955 
2956   MS_DLL_EXPORT int msGeomTransformShape(mapObj *map, layerObj *layer, shapeObj *shape);
2957 
2958   /* ==================================================================== */
2959   /*      end of prototypes for functions in mapgeomtransform.c                 */
2960   /* ==================================================================== */
2961 
2962 
2963   /* ==================================================================== */
2964   /*      prototypes for functions in mapgraticule.c                      */
2965   /* ==================================================================== */
2966   MS_DLL_EXPORT graticuleIntersectionObj *msGraticuleLayerGetIntersectionPoints(mapObj *map, layerObj *layer);
2967   MS_DLL_EXPORT void msGraticuleLayerFreeIntersectionPoints( graticuleIntersectionObj *psValue);
2968 
2969   /* ==================================================================== */
2970   /*      end of prototypes for functions in mapgraticule.c               */
2971   /* ==================================================================== */
2972 
2973   /* ==================================================================== */
2974   /*      prototypes for functions in mapsmoothing.c                      */
2975   /* ==================================================================== */
2976   MS_DLL_EXPORT shapeObj* msSmoothShapeSIA(shapeObj *shape, int ss, int si, char *preprocessing);
2977 
2978   /* ==================================================================== */
2979   /*      end of prototypes for functions in mapsmoothing.c               */
2980   /* ==================================================================== */
2981 
2982   /* ==================================================================== */
2983   /*      prototypes for functions in mapv8.cpp                           */
2984   /* ==================================================================== */
2985 #ifdef USE_V8_MAPSCRIPT
2986   MS_DLL_EXPORT void msV8CreateContext(mapObj *map);
2987   MS_DLL_EXPORT void msV8ContextSetLayer(mapObj *map, layerObj *layer);
2988   MS_DLL_EXPORT void msV8FreeContext(mapObj *map);
2989   MS_DLL_EXPORT char* msV8GetFeatureStyle(mapObj *map, const char *filename,
2990                                           layerObj *layer, shapeObj *shape);
2991   MS_DLL_EXPORT shapeObj *msV8TransformShape(shapeObj *shape,
2992                                              const char* filename);
2993 #endif
2994   /* ==================================================================== */
2995   /*      end of prototypes for functions in mapv8.cpp                    */
2996   /* ==================================================================== */
2997 
2998 #endif
2999 
3000 
3001 #ifndef SWIG
3002   /*
3003    * strokeStyleObj
3004    */
3005   typedef struct {
3006     double width; /* line width in pixels */
3007 
3008     /* line pattern, e.g. dots, dashes, etc.. */
3009     int patternlength;
3010     double pattern[MS_MAXPATTERNLENGTH];
3011     double patternoffset;
3012 
3013     /* must be a valid color if not NULL */
3014     /* color.alpha must be used if supported by the renderer */
3015     colorObj *color;
3016 
3017     int linecap; /* MS_CJC_TRIANGLE, MS_CJC_SQUARE, MS_CJC_ROUND, MS_CJC_BUTT */
3018     int linejoin; /* MS_CJC_BEVEL MS_CJC_ROUND MS_CJC_MITER */
3019     double linejoinmaxsize;
3020   } strokeStyleObj;
3021 
3022 #define INIT_STROKE_STYLE(s) { (s).width=0; (s).patternlength=0; (s).color=NULL; (s).linecap=MS_CJC_ROUND; (s).linejoin=MS_CJC_ROUND; (s).linejoinmaxsize=0;}
3023 
3024 
3025   /*
3026    * symbolStyleObj
3027    */
3028   typedef struct {
3029     /* must be valid colors if not NULL */
3030     /* color.alpha must be used if supported by the renderer */
3031     colorObj *color;
3032     colorObj *backgroundcolor;
3033 
3034     double outlinewidth;
3035     colorObj *outlinecolor;
3036 
3037     /* scalefactor to be applied on the tile or symbol*/
3038     double scale;
3039 
3040     /* rotation to apply on the symbol (and the tile?)
3041      * in radians */
3042     double rotation;
3043 
3044     /* the gap to space symbols appart when used as a polygon tile
3045      */
3046     double gap;
3047 
3048     /* style object, necessary for vector type renderers to be able
3049      * to render symbols through other renders such as cairo/agg */
3050     styleObj *style;
3051   } symbolStyleObj;
3052 
3053 #define INIT_SYMBOL_STYLE(s) {(s).color=NULL; (s).backgroundcolor=NULL; (s).outlinewidth=0; (s).outlinecolor=NULL; (s).scale=1.0; (s).rotation=0; (s).style=NULL;}
3054 
3055   struct tileCacheObj {
3056     symbolObj *symbol;
3057     int width;
3058     int height;
3059     colorObj color, outlinecolor, backgroundcolor;
3060     double outlinewidth, rotation,scale;
3061     imageObj *image;
3062     tileCacheObj *next;
3063   };
3064 
3065 
3066   /*
3067    * labelStyleObj
3068    */
3069   typedef struct {
3070     /* full paths to truetype font file */
3071     char* fonts[MS_MAX_LABEL_FONTS];
3072     int numfonts;
3073     double size;
3074     double rotation;
3075     colorObj *color;
3076     double outlinewidth;
3077     colorObj *outlinecolor;
3078   } labelStyleObj;
3079 
3080 #define INIT_LABEL_STYLE(s) {memset(&(s),'\0',sizeof(labelStyleObj));}
3081 
3082 #endif
3083 
3084 #ifndef SWIG
3085   MS_DLL_EXPORT int msInitializeDummyRenderer(rendererVTableObj *vtable);
3086   MS_DLL_EXPORT int msInitializeRendererVTable(outputFormatObj *outputformat);
3087   MS_DLL_EXPORT int msPopulateRendererVTableCairoRaster( rendererVTableObj *renderer );
3088   MS_DLL_EXPORT int msPopulateRendererVTableCairoSVG( rendererVTableObj *renderer );
3089   MS_DLL_EXPORT int msPopulateRendererVTableCairoPDF( rendererVTableObj *renderer );
3090   MS_DLL_EXPORT int msPopulateRendererVTableOGL( rendererVTableObj *renderer );
3091   MS_DLL_EXPORT int msPopulateRendererVTableAGG( rendererVTableObj *renderer );
3092   MS_DLL_EXPORT int msPopulateRendererVTableUTFGrid( rendererVTableObj *renderer );
3093   MS_DLL_EXPORT int msPopulateRendererVTableKML( rendererVTableObj *renderer );
3094   MS_DLL_EXPORT int msPopulateRendererVTableOGR( rendererVTableObj *renderer );
3095   MS_DLL_EXPORT int msPopulateRendererVTableMVT( rendererVTableObj *renderer );
3096 
3097   MS_DLL_EXPORT int msMVTWriteTile( mapObj *map, int sendheaders );
3098 
3099 #ifdef USE_CAIRO
3100   MS_DLL_EXPORT void msCairoCleanup(void);
3101 #endif
3102 
3103   /* allocate 50k for starters */
3104 #define MS_DEFAULT_BUFFER_ALLOC 50000
3105 
3106   typedef struct _autobuffer {
3107     unsigned char *data;
3108     size_t size;
3109     size_t available;
3110     size_t _next_allocation_size;
3111   } bufferObj;
3112 
3113 
3114   /* in mapimageio.c */
3115   int msQuantizeRasterBuffer(rasterBufferObj *rb, unsigned int *reqcolors, rgbaPixel *palette,
3116                              rgbaPixel *forced_palette, int num_forced_palette_entries,
3117                              unsigned int *palette_scaling_maxval);
3118   int msClassifyRasterBuffer(rasterBufferObj *rb, rasterBufferObj *qrb);
3119   int msSaveRasterBuffer(mapObj *map, rasterBufferObj *data, FILE *stream, outputFormatObj *format);
3120   int msSaveRasterBufferToBuffer(rasterBufferObj *data, bufferObj *buffer, outputFormatObj *format);
3121   int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb);
3122 
3123   /* in mapagg.cpp */
3124   void msApplyBlurringCompositingFilter(rasterBufferObj *rb, unsigned int radius);
3125 
3126   int WARN_UNUSED msApplyCompositingFilter(mapObj *map, rasterBufferObj *rb, CompositingFilter *filter);
3127 
3128   void msBufferInit(bufferObj *buffer);
3129   void msBufferResize(bufferObj *buffer, size_t target_size);
3130   MS_DLL_EXPORT void msBufferFree(bufferObj *buffer);
3131   MS_DLL_EXPORT void msBufferAppend(bufferObj *buffer, void *data, size_t length);
3132 
3133   typedef struct {
3134     int charWidth, charHeight;
3135   } fontMetrics;
3136 
3137   struct rendererVTableObj {
3138     int supports_pixel_buffer;
3139     int supports_clipping;
3140     int supports_svg;
3141     int use_imagecache;
3142     enum MS_TRANSFORM_MODE default_transform_mode;
3143     enum MS_TRANSFORM_MODE transform_mode;
3144     double default_approximation_scale;
3145     double approximation_scale;
3146 
3147     void *renderer_data;
3148 
3149     int WARN_UNUSED (*renderLine)(imageObj *img, shapeObj *p, strokeStyleObj *style);
3150     int WARN_UNUSED (*renderPolygon)(imageObj *img, shapeObj *p, colorObj *color);
3151     int WARN_UNUSED (*renderPolygonTiled)(imageObj *img, shapeObj *p, imageObj *tile);
3152     int WARN_UNUSED (*renderLineTiled)(imageObj *img, shapeObj *p, imageObj *tile);
3153 
3154     int WARN_UNUSED (*renderGlyphs)(imageObj *img, textPathObj *tp, colorObj *clr, colorObj *olcolor, int olwidth, int isMarker);
3155     int WARN_UNUSED (*renderText)(imageObj *img, pointObj *labelpnt, char *text, double angle, colorObj *clr, colorObj *olcolor, int olwidth);
3156 
3157     int WARN_UNUSED (*renderVectorSymbol)(imageObj *img, double x, double y,
3158                               symbolObj *symbol, symbolStyleObj *style);
3159 
3160     int WARN_UNUSED (*renderPixmapSymbol)(imageObj *img, double x, double y,
3161                               symbolObj *symbol, symbolStyleObj *style);
3162 
3163     int WARN_UNUSED (*renderEllipseSymbol)(imageObj *image, double x, double y,
3164                                symbolObj *symbol, symbolStyleObj *style);
3165 
3166     int WARN_UNUSED (*renderSVGSymbol)(imageObj *img, double x, double y,
3167                            symbolObj *symbol, symbolStyleObj *style);
3168 
3169     int WARN_UNUSED (*renderTile)(imageObj *img, imageObj *tile, double x, double y);
3170 
3171     int WARN_UNUSED (*loadImageFromFile)(char *path, rasterBufferObj *rb);
3172 
3173     int WARN_UNUSED (*getRasterBufferHandle)(imageObj *img, rasterBufferObj *rb);
3174     int WARN_UNUSED (*getRasterBufferCopy)(imageObj *img, rasterBufferObj *rb);
3175     int WARN_UNUSED (*initializeRasterBuffer)(rasterBufferObj *rb, int width, int height, int mode);
3176 
3177     int WARN_UNUSED (*mergeRasterBuffer)(imageObj *dest, rasterBufferObj *overlay, double opacity, int srcX, int srcY, int dstX, int dstY, int width, int height);
3178     int WARN_UNUSED (*compositeRasterBuffer)(imageObj *dest, rasterBufferObj *overlay, CompositingOperation comp_op, int opacity);
3179 
3180 
3181     /* image i/o */
3182     imageObj* WARN_UNUSED (*createImage)(int width, int height, outputFormatObj *format, colorObj* bg);
3183     int WARN_UNUSED (*saveImage)(imageObj *img, mapObj *map, FILE *fp, outputFormatObj *format);
3184     unsigned char* WARN_UNUSED (*saveImageBuffer)(imageObj *img, int *size_ptr, outputFormatObj *format);
3185     /*...*/
3186 
3187     int (*startLayer)(imageObj *img, mapObj *map, layerObj *layer);
3188     int (*endLayer)(imageObj *img, mapObj *map, layerObj *layer);
3189 
3190     int (*startShape)(imageObj *img, shapeObj *shape);
3191     int (*endShape)(imageObj *img, shapeObj *shape);
3192     int (*setClip)(imageObj *img, rectObj clipRect);
3193     int (*resetClip)(imageObj *img);
3194 
3195     int (*freeImage)(imageObj *image);
3196     int (*freeSymbol)(symbolObj *symbol);
3197     int (*cleanup)(void *renderer_data);
3198   } ;
3199   MS_DLL_EXPORT int msRenderRasterizedSVGSymbol(imageObj* img, double x, double y, symbolObj* symbol, symbolStyleObj* style);
3200 
3201 #define MS_IMAGE_RENDERER(im) ((im)->format->vtable)
3202 #define MS_RENDERER_CACHE(renderer) ((renderer)->renderer_data)
3203 #define MS_IMAGE_RENDERER_CACHE(im) MS_RENDERER_CACHE(MS_IMAGE_RENDERER((im)))
3204 #define MS_MAP_RENDERER(map) ((map)->outputformat->vtable)
3205 
3206 shapeObj *msOffsetCurve(shapeObj *p, double offset);
3207 #if defined USE_GEOS && (GEOS_VERSION_MAJOR > 3 || (GEOS_VERSION_MAJOR == 3 && GEOS_VERSION_MINOR >= 3))
3208 shapeObj *msGEOSOffsetCurve(shapeObj *p, double offset);
3209 #endif
3210 
3211 int msOGRIsSpatialite(layerObj* layer);
3212 
3213 #endif /* SWIG */
3214 
3215 #ifdef __cplusplus
3216 }
3217 #endif
3218 
3219 #endif /* MAP_H */
3220