1 /******************************************************************************
2  * $Id$
3  *
4  * Project:  MapServer
5  * Purpose:  Interface file for MapServer PHP scripting extension
6  *           called MapScript. This file was originally based on
7  *           the SWIG interface file mapscript.i
8  * Author:   Daniel Morissette, DM Solutions Group (dmorissette@dmsolutions.ca)
9  *
10  **********************************************************************
11  * Copyright (c) 2000, 2007, Daniel Morissette, DM Solutions Group Inc.
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included in
21  * all copies of this Software or works derived from this Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  **********************************************************************/
31 
32 #include "php_mapscript.h"
33 
34 /* grab mapserver declarations to wrap
35  */
36 #include "../../mapserver.h"
37 #include "../../mapows.h"
38 #include "../../maperror.h"
39 #include "../../mapprimitive.h"
40 #include "../../mapsymbol.h"
41 #include "../../mapshape.h"
42 #include "../../mapproject.h"
43 #include "../../maphash.h"
44 
45 /**********************************************************************
46  * class extensions for mapObj
47  **********************************************************************/
mapObj_new(char * filename,char * new_path)48 mapObj *mapObj_new(char *filename, char *new_path)
49 {
50   if(filename && strlen(filename))
51     return msLoadMap(filename, new_path);
52   else { /* create an empty map, no layers etc... */
53     return msNewMapObj();
54   }
55 }
56 
mapObj_newFromString(char * map_text,char * new_path)57 mapObj *mapObj_newFromString(char *map_text, char *new_path)
58 {
59 
60   if(map_text && strlen(map_text))
61     return msLoadMapFromString(map_text, new_path);
62   else { /* create an empty map, no layers etc... */
63     return msNewMapObj();
64   }
65 }
66 
mapObj_destroy(mapObj * self)67 void  mapObj_destroy(mapObj* self)
68 {
69   msFreeMap(self);
70 }
71 
mapObj_clone(mapObj * self)72 mapObj *mapObj_clone(mapObj* self)
73 {
74   mapObj *dstMap;
75   dstMap = msNewMapObj();
76   if (msCopyMap(dstMap, self) != MS_SUCCESS) {
77     msFreeMap(dstMap);
78     dstMap = NULL;
79   }
80   return dstMap;
81 }
82 
mapObj_setRotation(mapObj * self,double rotation_angle)83 int mapObj_setRotation(mapObj* self, double rotation_angle )
84 {
85   return msMapSetRotation( self, rotation_angle );
86 }
87 
mapObj_getLayer(mapObj * self,int i)88 layerObj *mapObj_getLayer(mapObj* self, int i)
89 {
90   if(i >= 0 && i < self->numlayers)
91     return (self->layers[i]); /* returns an EXISTING layer */
92   else
93     return NULL;
94 }
95 
mapObj_getLayerByName(mapObj * self,char * name)96 layerObj *mapObj_getLayerByName(mapObj* self, char *name)
97 {
98   int i;
99 
100   i = msGetLayerIndex(self, name);
101 
102   if(i != -1)
103     return (self->layers[i]); /* returns an EXISTING layer */
104   else
105     return NULL;
106 }
107 
mapObj_getLayersIndexByGroup(mapObj * self,char * groupname,int * pnCount)108 int *mapObj_getLayersIndexByGroup(mapObj* self, char *groupname,
109                                   int *pnCount)
110 {
111   return msGetLayersIndexByGroup(self, groupname, pnCount);
112 }
113 
114 
mapObj_getSymbolByName(mapObj * self,char * name)115 int mapObj_getSymbolByName(mapObj* self, char *name)
116 {
117   return msGetSymbolIndex(&self->symbolset, name, MS_TRUE);
118 }
119 
mapObj_prepareQuery(mapObj * self)120 void mapObj_prepareQuery(mapObj* self)
121 {
122   int status;
123 
124   status = msCalculateScale(self->extent, self->units, self->width, self->height, self->resolution, &self->scaledenom);
125   if(status != MS_SUCCESS) self->scaledenom = -1; // degenerate extents ok here
126 }
127 
mapObj_prepareImage(mapObj * self)128 imageObj *mapObj_prepareImage(mapObj* self)
129 {
130   return msPrepareImage(self, MS_FALSE);
131 }
132 
mapObj_draw(mapObj * self)133 imageObj *mapObj_draw(mapObj* self)
134 {
135   return msDrawMap(self, MS_FALSE);
136 }
137 
mapObj_drawQuery(mapObj * self)138 imageObj *mapObj_drawQuery(mapObj* self)
139 {
140   return msDrawMap(self, MS_TRUE);
141 }
142 
mapObj_drawLegend(mapObj * self)143 imageObj *mapObj_drawLegend(mapObj* self)
144 {
145   return msDrawLegend(self, MS_FALSE, NULL);
146 }
147 
148 
mapObj_drawScalebar(mapObj * self)149 imageObj *mapObj_drawScalebar(mapObj* self)
150 {
151   return msDrawScalebar(self);
152 }
153 
mapObj_drawReferenceMap(mapObj * self)154 imageObj *mapObj_drawReferenceMap(mapObj* self)
155 {
156   return msDrawReferenceMap(self);
157 }
158 
159 //TODO
mapObj_embedScalebar(mapObj * self,imageObj * img)160 int mapObj_embedScalebar(mapObj* self, imageObj *img)
161 {
162   return msEmbedScalebar(self, img);
163 }
164 
165 //TODO
mapObj_embedLegend(mapObj * self,imageObj * img)166 int mapObj_embedLegend(mapObj* self, imageObj *img)
167 {
168   return msEmbedLegend(self, img);
169 }
170 
mapObj_drawLabelCache(mapObj * self,imageObj * img)171 int mapObj_drawLabelCache(mapObj* self, imageObj *img)
172 {
173   return msDrawLabelCache(self, img);
174 }
175 
mapObj_getLabel(mapObj * self,int i)176 labelCacheMemberObj* mapObj_getLabel(mapObj* self, int i)
177 {
178   msSetError(MS_MISCERR, "LabelCacheMember access is not available", "getLabel()");
179   return NULL;
180 }
181 
mapObj_queryByPoint(mapObj * self,pointObj * point,int mode,double buffer)182 int mapObj_queryByPoint(mapObj* self, pointObj *point, int mode, double buffer)
183 {
184   msInitQuery(&(self->query));
185 
186   self->query.type = MS_QUERY_BY_POINT;
187   self->query.mode = mode;
188   self->query.point = *point;
189   self->query.buffer = buffer;
190 
191   return msQueryByPoint(self);
192 }
193 
mapObj_queryByRect(mapObj * self,rectObj rect)194 int mapObj_queryByRect(mapObj* self, rectObj rect)
195 {
196   msInitQuery(&(self->query));
197 
198   self->query.type = MS_QUERY_BY_RECT;
199   self->query.mode = MS_QUERY_MULTIPLE;
200   self->query.rect = rect;
201 
202   return msQueryByRect(self);
203 }
204 
mapObj_queryByFeatures(mapObj * self,int slayer)205 int mapObj_queryByFeatures(mapObj* self, int slayer)
206 {
207   self->query.slayer = slayer;
208   return msQueryByFeatures(self);
209 }
210 
mapObj_queryByFilter(mapObj * self,char * string)211 int mapObj_queryByFilter(mapObj* self, char *string)
212 {
213   msInitQuery(&(self->query));
214 
215   self->query.type = MS_QUERY_BY_FILTER;
216   self->query.mode = MS_QUERY_MULTIPLE;
217 
218   self->query.filter.string = msStrdup(string);
219   self->query.filter.type = MS_EXPRESSION;
220 
221   self->query.rect = self->extent;
222 
223   return msQueryByFilter(self);
224 }
225 
mapObj_queryByShape(mapObj * self,shapeObj * shape)226 int mapObj_queryByShape(mapObj *self, shapeObj *shape)
227 {
228   msInitQuery(&(self->query));
229 
230   self->query.type = MS_QUERY_BY_SHAPE;
231   self->query.mode = MS_QUERY_MULTIPLE;
232   self->query.shape = (shapeObj *) malloc(sizeof(shapeObj));
233   msInitShape(self->query.shape);
234   msCopyShape(shape, self->query.shape);
235 
236   return msQueryByShape(self);
237 }
238 
mapObj_queryByIndex(mapObj * self,int qlayer,int tileindex,int shapeindex,int bAddToQuery)239 int mapObj_queryByIndex(mapObj *self, int qlayer, int tileindex, int shapeindex, int bAddToQuery)
240 {
241   msInitQuery(&(self->query));
242 
243   self->query.type = MS_QUERY_BY_INDEX;
244   self->query.mode = MS_QUERY_SINGLE;
245   self->query.tileindex = tileindex;
246   self->query.shapeindex = shapeindex;
247   self->query.clear_resultcache = !bAddToQuery;
248   self->query.layer = qlayer;
249 
250   return msQueryByIndex(self);
251 }
252 
mapObj_saveQuery(mapObj * self,char * filename,int results)253 int mapObj_saveQuery(mapObj *self, char *filename, int results)
254 {
255   return msSaveQuery(self, filename, results);
256 }
mapObj_loadQuery(mapObj * self,char * filename)257 int mapObj_loadQuery(mapObj *self, char *filename)
258 {
259   return msLoadQuery(self, filename);
260 }
mapObj_freeQuery(mapObj * self,int qlayer)261 void mapObj_freeQuery(mapObj *self, int qlayer)
262 {
263   msQueryFree(self, qlayer);
264 }
265 
mapObj_setWKTProjection(mapObj * self,char * string)266 int mapObj_setWKTProjection(mapObj *self, char *string)
267 {
268   return msOGCWKT2ProjectionObj(string, &(self->projection), self->debug);
269 }
270 
mapObj_getProjection(mapObj * self)271 char *mapObj_getProjection(mapObj* self)
272 {
273   return msGetProjectionString(&self->projection);
274 }
275 
mapObj_setProjection(mapObj * self,char * string)276 int mapObj_setProjection(mapObj* self, char *string)
277 {
278   return(msLoadProjectionString(&(self->projection), string));
279 }
280 
mapObj_save(mapObj * self,char * filename)281 int mapObj_save(mapObj* self, char *filename)
282 {
283   return msSaveMap(self, filename);
284 }
285 
mapObj_getMetaData(mapObj * self,char * name)286 const char *mapObj_getMetaData(mapObj *self, char *name)
287 {
288   return(msLookupHashTable(&(self->web.metadata), name));
289 }
290 
mapObj_setMetaData(mapObj * self,char * name,char * value)291 int mapObj_setMetaData(mapObj *self, char *name, char *value)
292 {
293   if (msInsertHashTable(&(self->web.metadata), name, value) == NULL)
294     return MS_FAILURE;
295   return MS_SUCCESS;
296 }
297 
mapObj_removeMetaData(mapObj * self,char * name)298 int mapObj_removeMetaData(mapObj *self, char *name)
299 {
300   return(msRemoveHashTable(&(self->web.metadata), name));
301 }
302 
mapObj_moveLayerup(mapObj * self,int layerindex)303 int mapObj_moveLayerup(mapObj *self, int layerindex)
304 {
305   return msMoveLayerUp(self, layerindex);
306 }
307 
mapObj_moveLayerdown(mapObj * self,int layerindex)308 int mapObj_moveLayerdown(mapObj *self, int layerindex)
309 {
310   return msMoveLayerDown(self, layerindex);
311 }
312 
mapObj_getLayersdrawingOrder(mapObj * self)313 int *mapObj_getLayersdrawingOrder(mapObj *self)
314 {
315   return self->layerorder;
316 }
317 
mapObj_setLayersdrawingOrder(mapObj * self,int * panIndexes)318 int mapObj_setLayersdrawingOrder(mapObj *self, int *panIndexes)
319 {
320   return msSetLayersdrawingOrder(self, panIndexes);
321 }
322 
mapObj_processTemplate(mapObj * self,int bGenerateImages,char ** names,char ** values,int numentries)323 char *mapObj_processTemplate(mapObj *self, int bGenerateImages,
324                              char **names, char **values,
325                              int numentries)
326 {
327   return msProcessTemplate(self, bGenerateImages,
328                            names, values, numentries);
329 }
330 
mapObj_processLegendTemplate(mapObj * self,char ** names,char ** values,int numentries)331 char *mapObj_processLegendTemplate(mapObj *self,
332                                    char **names, char **values,
333                                    int numentries)
334 {
335   return msProcessLegendTemplate(self, names, values, numentries);
336 }
337 
338 
mapObj_processQueryTemplate(mapObj * self,int bGenerateImages,char ** names,char ** values,int numentries)339 char *mapObj_processQueryTemplate(mapObj *self, int bGenerateImages,
340                                   char **names, char **values,
341                                   int numentries)
342 {
343   return msProcessQueryTemplate(self, bGenerateImages, names, values,
344                                 numentries);
345 }
346 
mapObj_setSymbolSet(mapObj * self,char * szFileName)347 int mapObj_setSymbolSet(mapObj *self,
348                         char *szFileName)
349 {
350   msFreeSymbolSet(&self->symbolset);
351   msInitSymbolSet(&self->symbolset);
352 
353   // Set symbolset filename
354   self->symbolset.filename = msStrdup(szFileName);
355 
356   // Symbolset shares same fontset as main mapfile
357   self->symbolset.fontset = &(self->fontset);
358 
359   return msLoadSymbolSet(&self->symbolset, self);
360 }
361 
mapObj_getNumSymbols(mapObj * self)362 int mapObj_getNumSymbols(mapObj *self)
363 {
364   return self->symbolset.numsymbols;
365 }
366 
mapObj_setFontSet(mapObj * self,char * szFileName)367 int mapObj_setFontSet(mapObj *self, char *szFileName)
368 {
369   msFreeFontSet(&(self->fontset));
370   msInitFontSet(&(self->fontset));
371 
372   // Set fontset filename
373   self->fontset.filename = msStrdup(szFileName);
374 
375   return msLoadFontSet(&(self->fontset), self);
376 }
377 
mapObj_saveMapContext(mapObj * self,char * szFilename)378 int mapObj_saveMapContext(mapObj *self, char *szFilename)
379 {
380   return msSaveMapContext(self, szFilename);
381 }
382 
mapObj_loadMapContext(mapObj * self,char * szFilename,int bUniqueLayerName)383 int mapObj_loadMapContext(mapObj *self, char *szFilename, int bUniqueLayerName)
384 {
385   return msLoadMapContext(self, szFilename, bUniqueLayerName);
386 }
387 
388 
389 
mapObj_selectOutputFormat(mapObj * self,const char * imagetype)390 int mapObj_selectOutputFormat(mapObj *self,
391                               const char *imagetype)
392 {
393   outputFormatObj *format = NULL;
394 
395   format = msSelectOutputFormat(self, imagetype);
396   if (format) {
397     msApplyOutputFormat( &(self->outputformat), format,
398                          self->transparent, self->interlace,
399                          self->imagequality );
400     return(MS_SUCCESS);
401   }
402   return(MS_FAILURE);
403 
404 }
405 
mapObj_applySLD(mapObj * self,char * sld)406 int mapObj_applySLD(mapObj *self, char *sld)
407 {
408   return msSLDApplySLD(self, sld, -1, NULL, NULL);
409 }
mapObj_applySLDURL(mapObj * self,char * sld)410 int mapObj_applySLDURL(mapObj *self, char *sld)
411 {
412   return msSLDApplySLDURL(self, sld, -1, NULL, NULL);
413 }
414 
mapObj_generateSLD(mapObj * self)415 char *mapObj_generateSLD(mapObj *self)
416 {
417   return msSLDGenerateSLD(self, -1, NULL);
418 }
419 
420 
mapObj_loadOWSParameters(mapObj * self,cgiRequestObj * request,char * wmtver_string)421 int mapObj_loadOWSParameters(mapObj *self, cgiRequestObj *request,
422                              char *wmtver_string)
423 {
424   return msMapLoadOWSParameters(self, request, wmtver_string);
425 }
426 
mapObj_OWSDispatch(mapObj * self,cgiRequestObj * req)427 int mapObj_OWSDispatch(mapObj *self, cgiRequestObj *req )
428 {
429   return msOWSDispatch( self, req, MS_TRUE);
430 }
431 
mapObj_insertLayer(mapObj * self,layerObj * layer,int index)432 int mapObj_insertLayer(mapObj *self, layerObj *layer, int index)
433 {
434   if (self && layer)
435     return msInsertLayer(self, layer, index);
436 
437   return -1;
438 }
439 
mapObj_removeLayer(mapObj * self,int layerindex)440 layerObj *mapObj_removeLayer(mapObj *self, int layerindex)
441 {
442   return msRemoveLayer(self, layerindex);
443 }
444 
mapObj_setCenter(mapObj * self,pointObj * center)445 int mapObj_setCenter(mapObj *self, pointObj *center)
446 {
447   return msMapSetCenter(self, center);
448 }
449 
mapObj_offsetExtent(mapObj * self,double x,double y)450 int mapObj_offsetExtent(mapObj *self, double x, double y)
451 {
452   return msMapOffsetExtent(self, x, y);
453 }
454 
mapObj_scaleExtent(mapObj * self,double zoomfactor,double minscaledenom,double maxscaledenom)455 int mapObj_scaleExtent(mapObj *self, double zoomfactor, double minscaledenom,
456                        double maxscaledenom)
457 {
458   return msMapScaleExtent(self, zoomfactor, minscaledenom, maxscaledenom);
459 }
460 
mapObj_convertToString(mapObj * self)461 char *mapObj_convertToString(mapObj *self)
462 {
463   return msWriteMapToString(self);
464 }
465 
466 /**********************************************************************
467  * class extensions for layerObj, always within the context of a map
468  **********************************************************************/
layerObj_new(mapObj * map)469 layerObj *layerObj_new(mapObj *map)
470 {
471   if(msGrowMapLayers(map) == NULL)
472     return(NULL);
473 
474   if(initLayer((map->layers[map->numlayers]), map) == -1)
475     return(NULL);
476 
477   map->layers[map->numlayers]->index = map->numlayers;
478   //Update the layer order list with the layer's index.
479   map->layerorder[map->numlayers] = map->numlayers;
480 
481   map->numlayers++;
482 
483   return (map->layers[map->numlayers-1]);
484 }
485 
layerObj_destroy(layerObj * self)486 void layerObj_destroy(layerObj *self)
487 {
488   /* if the layer has a parent_map, let's the map object destroy it */
489   if ((self->map == NULL) && (self->refcount == 1)) {
490     /* if there is no other PHP Object that use this C layer object, delete it */
491     freeLayer(self);
492     free(self);
493     self = NULL;
494   } else {
495     MS_REFCNT_DECR(self);
496   }
497   return;
498 }
499 
layerObj_clone(layerObj * layer)500 layerObj *layerObj_clone(layerObj *layer)
501 {
502   layerObj *dstLayer;
503   dstLayer = (layerObj *)malloc(sizeof(layerObj));
504   initLayer(dstLayer, layer->map);
505   msCopyLayer(dstLayer, layer);
506   return dstLayer;
507 }
508 
509 
layerObj_updateFromString(layerObj * self,char * snippet)510 int layerObj_updateFromString(layerObj *self, char *snippet)
511 {
512   return msUpdateLayerFromString(self, snippet, MS_FALSE);
513 }
514 
layerObj_convertToString(layerObj * self)515 char *layerObj_convertToString(layerObj *self)
516 {
517   return msWriteLayerToString(self);
518 }
519 
layerObj_open(layerObj * self)520 int layerObj_open(layerObj *self)
521 {
522   return msLayerOpen(self);
523 }
524 
525 
layerObj_whichShapes(layerObj * self,rectObj * poRect)526 int layerObj_whichShapes(layerObj *self, rectObj *poRect)
527 {
528   int oldconnectiontype = self->connectiontype;
529   self->connectiontype = MS_INLINE;
530 
531   if(msLayerWhichItems(self, MS_FALSE, NULL) != MS_SUCCESS) {
532     self->connectiontype = oldconnectiontype;
533     return MS_FAILURE;
534   }
535   self->connectiontype = oldconnectiontype;
536 
537   return msLayerWhichShapes(self, *poRect, MS_FALSE);
538 }
539 
540 
layerObj_nextShape(layerObj * self)541 shapeObj *layerObj_nextShape(layerObj *self)
542 {
543   int status;
544   shapeObj *shape;
545 
546   shape = (shapeObj *)malloc(sizeof(shapeObj));
547   if (!shape) return NULL;
548   msInitShape(shape);
549 
550   status = msLayerNextShape(self, shape);
551   if(status != MS_SUCCESS) {
552     msFreeShape(shape);
553     free(shape);
554     return NULL;
555   } else
556     return shape;
557 }
558 
layerObj_close(layerObj * self)559 void layerObj_close(layerObj *self)
560 {
561   msLayerClose(self);
562 }
563 
layerObj_getResult(layerObj * self,int i)564 resultObj *layerObj_getResult(layerObj *self, int i)
565 {
566   if(!self->resultcache) return NULL;
567 
568   if(i >= 0 && i < self->resultcache->numresults)
569     return &self->resultcache->results[i];
570   else
571     return NULL;
572 }
573 
layerObj_getClass(layerObj * self,int i)574 classObj *layerObj_getClass(layerObj *self, int i)   // returns an EXISTING class
575 {
576   if(i >= 0 && i < self->numclasses)
577     return (self->class[i]);
578   else
579     return(NULL);
580 }
581 
layerObj_getClassIndex(layerObj * self,mapObj * map,shapeObj * shape,int * classgroup,int numclasses)582 int layerObj_getClassIndex(layerObj *self, mapObj *map, shapeObj *shape,
583                            int *classgroup, int numclasses)
584 {
585   return msShapeGetClass(self, map, shape, classgroup, numclasses);
586 }
587 
layerObj_draw(layerObj * self,mapObj * map,imageObj * img)588 int layerObj_draw(layerObj *self, mapObj *map, imageObj *img)
589 {
590   return msDrawLayer(map, self, img);
591 }
592 
layerObj_drawQuery(layerObj * self,mapObj * map,imageObj * img)593 int layerObj_drawQuery(layerObj *self, mapObj *map, imageObj *img)
594 {
595   return msDrawQueryLayer(map, self, img);
596 }
597 
layerObj_queryByAttributes(layerObj * self,mapObj * map,char * qitem,char * qstring,int mode)598 int layerObj_queryByAttributes(layerObj *self, mapObj *map, char *qitem, char *qstring, int mode)
599 {
600   int status;
601   int retval;
602 
603   msInitQuery(&(map->query));
604 
605   map->query.type = MS_QUERY_BY_FILTER;
606   map->query.mode = mode;
607 
608   if(qitem) map->query.filteritem = msStrdup(qitem);
609   if(qstring) {
610     msInitExpression(&map->query.filter);
611     msLoadExpressionString(&map->query.filter, qstring);
612   }
613 
614   map->query.layer = self->index;
615   map->query.rect = map->extent;
616 
617   status = self->status;
618   self->status = MS_ON;
619   retval = msQueryByFilter(map);
620   self->status = status;
621 
622   return retval;
623 }
624 
layerObj_queryByPoint(layerObj * self,mapObj * map,pointObj * point,int mode,double buffer)625 int layerObj_queryByPoint(layerObj *self, mapObj *map, pointObj *point, int mode, double buffer)
626 {
627   int status;
628   int retval;
629 
630   msInitQuery(&(map->query));
631 
632   map->query.type = MS_QUERY_BY_POINT;
633   map->query.mode = mode;
634   map->query.point = *point;
635   map->query.buffer = buffer;
636   map->query.layer = self->index;
637 
638   status = self->status;
639   self->status = MS_ON;
640   retval = msQueryByPoint(map);
641   self->status = status;
642 
643   return retval;
644 }
645 
layerObj_queryByRect(layerObj * self,mapObj * map,rectObj rect)646 int layerObj_queryByRect(layerObj *self, mapObj *map, rectObj rect)
647 {
648   int status;
649   int retval;
650 
651   msInitQuery(&(map->query));
652 
653   map->query.type = MS_QUERY_BY_RECT;
654   map->query.mode = MS_QUERY_MULTIPLE;
655   map->query.rect = rect;
656   map->query.layer = self->index;
657 
658   status = self->status;
659   self->status = MS_ON;
660   retval = msQueryByRect(map);
661   self->status = status;
662 
663   return retval;
664 }
665 
layerObj_queryByFeatures(layerObj * self,mapObj * map,int slayer)666 int layerObj_queryByFeatures(layerObj *self, mapObj *map, int slayer)
667 {
668   int status;
669   int retval;
670 
671   map->query.slayer = slayer;
672   map->query.layer = self->index;
673 
674   status = self->status;
675   self->status = MS_ON;
676   retval = msQueryByFeatures(map);
677   self->status = status;
678 
679   return retval;
680 }
681 
layerObj_queryByShape(layerObj * self,mapObj * map,shapeObj * shape)682 int layerObj_queryByShape(layerObj *self, mapObj *map, shapeObj *shape)
683 {
684   int status;
685   int retval;
686 
687   msInitQuery(&(map->query));
688 
689   map->query.type = MS_QUERY_BY_SHAPE;
690   map->query.mode = MS_QUERY_MULTIPLE;
691   map->query.shape = (shapeObj *) malloc(sizeof(shapeObj));
692   msInitShape(map->query.shape);
693   msCopyShape(shape, map->query.shape);
694   map->query.layer = self->index;
695 
696   status = self->status;
697   self->status = MS_ON;
698   retval = msQueryByShape(map);
699   self->status = status;
700 
701   return retval;
702 }
703 
layerObj_queryByFilter(layerObj * self,mapObj * map,char * string)704 int layerObj_queryByFilter(layerObj *self, mapObj *map, char *string)
705 {
706   int status;
707   int retval;
708 
709   msInitQuery(&(map->query));
710 
711   map->query.type = MS_QUERY_BY_FILTER;
712   map->query.mode = MS_QUERY_MULTIPLE;
713 
714   map->query.filter.string = msStrdup(string);
715   map->query.filter.type = MS_EXPRESSION;
716 
717   map->query.layer = self->index;
718   map->query.rect = map->extent;
719 
720   status = self->status;
721   self->status = MS_ON;
722   retval = msQueryByFilter(map);
723   self->status = status;
724 
725   return retval;
726 }
727 
layerObj_queryByIndex(layerObj * self,mapObj * map,int tileindex,int shapeindex,int addtoquery)728 int layerObj_queryByIndex(layerObj *self, mapObj *map, int tileindex, int shapeindex, int addtoquery)
729 {
730   int status;
731   int retval;
732 
733   msInitQuery(&(map->query));
734 
735   map->query.type = MS_QUERY_BY_INDEX;
736   map->query.mode = MS_QUERY_SINGLE;
737   map->query.tileindex = tileindex;
738   map->query.shapeindex = shapeindex;
739   map->query.clear_resultcache = !addtoquery;
740   map->query.layer = self->index;
741 
742   status = self->status;
743   self->status = MS_ON;
744   retval = msQueryByIndex(map);
745   self->status = status;
746 
747   return retval;
748 }
749 
layerObj_setFilter(layerObj * self,char * string)750 int layerObj_setFilter(layerObj *self, char *string)
751 {
752   if (!string || strlen(string) == 0) {
753     msFreeExpression(&self->filter);
754     return MS_SUCCESS;
755   } else return msLoadExpressionString(&self->filter, string);
756 }
757 
layerObj_getFilter(layerObj * self)758 char *layerObj_getFilter(layerObj *self)
759 {
760   return msGetExpressionString(&(self->filter));
761 }
762 
layerObj_setWKTProjection(layerObj * self,char * string)763 int layerObj_setWKTProjection(layerObj *self, char *string)
764 {
765   self->project = MS_TRUE;
766   return msOGCWKT2ProjectionObj(string, &(self->projection), self->debug);
767 }
768 
layerObj_getProjection(layerObj * self)769 char *layerObj_getProjection(layerObj* self)
770 {
771   return msGetProjectionString(&self->projection);
772 }
773 
layerObj_setProjection(layerObj * self,char * string)774 int layerObj_setProjection(layerObj *self, char *string)
775 {
776   int nReturn;
777   nReturn = msLoadProjectionString(&(self->projection), string);
778   if (nReturn == MS_SUCCESS)
779     self->project = MS_TRUE;
780   return nReturn;
781 
782 }
783 
layerObj_addFeature(layerObj * self,shapeObj * shape)784 int layerObj_addFeature(layerObj *self, shapeObj *shape)
785 {
786   if(self->features != NULL && self->features->tailifhead != NULL)
787     shape->index = self->features->tailifhead->shape.index + 1;
788   else
789     shape->index = 0;
790   if(insertFeatureList(&(self->features), shape) == NULL)
791     return MS_FAILURE;
792   else
793     return MS_SUCCESS;
794 }
795 
layerObj_getMetaData(layerObj * self,char * name)796 const char *layerObj_getMetaData(layerObj *self, char *name)
797 {
798   return(msLookupHashTable(&(self->metadata), name));
799 }
800 
801 
layerObj_setMetaData(layerObj * self,char * name,char * value)802 int layerObj_setMetaData(layerObj *self, char *name, char *value)
803 {
804   if (msInsertHashTable(&(self->metadata), name, value) == NULL)
805     return MS_FAILURE;
806   return MS_SUCCESS;
807 }
808 
layerObj_removeMetaData(layerObj * self,char * name)809 int layerObj_removeMetaData(layerObj *self, char *name)
810 {
811   return(msRemoveHashTable(&(self->metadata), name));
812 }
813 
layerObj_getWMSFeatureInfoURL(layerObj * self,mapObj * map,int click_x,int click_y,int feature_count,char * info_format)814 char *layerObj_getWMSFeatureInfoURL(layerObj *self, mapObj *map, int click_x, int click_y,
815                                     int feature_count, char *info_format)
816 {
817   // NOTE: the returned string should be freed by the caller but right
818   // now we're leaking it.
819   return(msWMSGetFeatureInfoURL(map, self, click_x, click_y,
820                                 feature_count, info_format));
821 }
822 
layerObj_executeWFSGetFeature(layerObj * self)823 char *layerObj_executeWFSGetFeature(layerObj *self)
824 {
825   return (msWFSExecuteGetFeature(self));
826 }
827 
layerObj_applySLD(layerObj * self,char * sld,char * stylelayer)828 int layerObj_applySLD(layerObj *self, char *sld, char *stylelayer)
829 {
830   return msSLDApplySLD(self->map, sld, self->index, stylelayer, NULL);
831 }
layerObj_applySLDURL(layerObj * self,char * sld,char * stylelayer)832 int layerObj_applySLDURL(layerObj *self, char *sld, char *stylelayer)
833 {
834   return msSLDApplySLDURL(self->map, sld, self->index, stylelayer, NULL);
835 }
836 
layerObj_generateSLD(layerObj * self)837 char *layerObj_generateSLD(layerObj *self)
838 {
839   return msSLDGenerateSLD(self->map, self->index, NULL);
840 }
841 
layerObj_moveClassUp(layerObj * self,int index)842 int layerObj_moveClassUp(layerObj *self, int index)
843 {
844   return msMoveClassUp(self, index);
845 }
846 
layerObj_moveClassDown(layerObj * self,int index)847 int layerObj_moveClassDown(layerObj *self, int index)
848 {
849   return msMoveClassDown(self, index);
850 }
851 
layerObj_removeClass(layerObj * self,int index)852 classObj *layerObj_removeClass(layerObj *self, int index)
853 {
854   return msRemoveClass(self, index);
855 }
856 
layerObj_setConnectionType(layerObj * self,int connectiontype,const char * library_str)857 int layerObj_setConnectionType(layerObj *self, int connectiontype,
858                                const char *library_str)
859 {
860   /* Caller is responsible to close previous layer correctly before calling
861    * msConnectLayer()
862    */
863   if (msLayerIsOpen(self))
864     msLayerClose(self);
865 
866   return msConnectLayer(self, connectiontype, library_str);
867 }
868 
869 /**********************************************************************
870  * class extensions for labelObj
871  **********************************************************************/
labelObj_new()872 labelObj *labelObj_new()
873 {
874   labelObj *label;
875 
876   label = (labelObj *)malloc(sizeof(labelObj));
877   if(!label)
878     return(NULL);
879 
880   initLabel(label);
881 
882   return label;
883 }
884 
labelObj_destroy(labelObj * self)885 void labelObj_destroy(labelObj *self)
886 {
887   if (freeLabel(self) == MS_SUCCESS)
888     free(self);
889 
890 }
891 
labelObj_clone(labelObj * label)892 labelObj *labelObj_clone(labelObj *label)
893 {
894   labelObj *dstLabel;
895   dstLabel = (labelObj *)malloc(sizeof(labelObj));
896   initLabel(dstLabel);
897   dstLabel->font = NULL;
898   msCopyLabel(dstLabel, label);
899 
900   return dstLabel;
901 }
902 
labelObj_updateFromString(labelObj * self,char * snippet)903 int labelObj_updateFromString(labelObj *self, char *snippet)
904 {
905   return msUpdateLabelFromString(self, snippet, MS_FALSE);
906 }
907 
labelObj_convertToString(labelObj * self)908 char *labelObj_convertToString(labelObj *self)
909 {
910   return msWriteLabelToString(self);
911 }
912 
labelObj_moveStyleUp(labelObj * self,int index)913 int labelObj_moveStyleUp(labelObj *self, int index)
914 {
915   return msMoveLabelStyleUp(self, index);
916 }
917 
labelObj_moveStyleDown(labelObj * self,int index)918 int labelObj_moveStyleDown(labelObj *self, int index)
919 {
920   return msMoveLabelStyleDown(self, index);
921 }
922 
labelObj_deleteStyle(labelObj * self,int index)923 int labelObj_deleteStyle(labelObj *self, int index)
924 {
925   return msDeleteLabelStyle(self, index);
926 }
927 
labelObj_setExpression(labelObj * self,char * string)928 int labelObj_setExpression(labelObj *self, char *string)
929 {
930   if (!string || strlen(string) == 0) {
931     msFreeExpression(&self->expression);
932     return MS_SUCCESS;
933   } else return msLoadExpressionString(&self->expression, string);
934 }
935 
labelObj_getExpressionString(labelObj * self)936 char *labelObj_getExpressionString(labelObj *self)
937 {
938   return msGetExpressionString(&(self->expression));
939 }
940 
labelObj_setText(labelObj * self,layerObj * layer,char * string)941 int labelObj_setText(labelObj *self, layerObj *layer, char *string)
942 {
943   if (!string || strlen(string) == 0) {
944     msFreeExpression(&self->text);
945     return MS_SUCCESS;
946   }
947   return msLoadExpressionString(&self->text, string);
948 }
949 
labelObj_getTextString(labelObj * self)950 char *labelObj_getTextString(labelObj *self)
951 {
952   return msGetExpressionString(&(self->text));
953 }
954 
955 /**********************************************************************
956  * class extensions for legendObj
957  **********************************************************************/
legendObj_updateFromString(legendObj * self,char * snippet)958 int legendObj_updateFromString(legendObj *self, char *snippet)
959 {
960   return msUpdateLegendFromString(self, snippet, MS_FALSE);
961 }
962 
legendObj_convertToString(legendObj * self)963 char *legendObj_convertToString(legendObj *self)
964 {
965   return msWriteLegendToString(self);
966 }
967 
968 /**********************************************************************
969  * class extensions for queryMapObj
970  **********************************************************************/
queryMapObj_updateFromString(queryMapObj * self,char * snippet)971 int queryMapObj_updateFromString(queryMapObj *self, char *snippet)
972 {
973   return msUpdateQueryMapFromString(self, snippet, MS_FALSE);
974 }
975 
queryMapObj_convertToString(queryMapObj * self)976 char *queryMapObj_convertToString(queryMapObj *self)
977 {
978   return msWriteQueryMapToString(self);
979 }
980 
981 /**********************************************************************
982  * class extensions for referenceMapObj
983  **********************************************************************/
984 
referenceMapObj_updateFromString(referenceMapObj * self,char * snippet)985 int referenceMapObj_updateFromString(referenceMapObj *self, char *snippet)
986 {
987   return msUpdateReferenceMapFromString(self, snippet, MS_FALSE);
988 }
989 
referenceMapObj_convertToString(referenceMapObj * self)990 char *referenceMapObj_convertToString(referenceMapObj *self)
991 {
992   return msWriteReferenceMapToString(self);
993 }
994 
995 /**********************************************************************
996  * class extensions for scaleBarObj
997  **********************************************************************/
998 
scalebarObj_updateFromString(scalebarObj * self,char * snippet)999 int scalebarObj_updateFromString(scalebarObj *self, char *snippet)
1000 {
1001   return msUpdateScalebarFromString(self, snippet, MS_FALSE);
1002 }
1003 
scalebarObj_convertToString(scalebarObj * self)1004 char *scalebarObj_convertToString(scalebarObj *self)
1005 {
1006   return msWriteScalebarToString(self);
1007 }
1008 
1009 /**********************************************************************
1010  * class extensions for webObj
1011  **********************************************************************/
1012 
webObj_updateFromString(webObj * self,char * snippet)1013 int webObj_updateFromString(webObj *self, char *snippet)
1014 {
1015   return msUpdateWebFromString(self, snippet, MS_FALSE);
1016 }
1017 
webObj_convertToString(webObj * self)1018 char *webObj_convertToString(webObj *self)
1019 {
1020   return msWriteWebToString(self);
1021 }
1022 
1023 /**********************************************************************
1024  * class extensions for classObj, always within the context of a layer
1025  **********************************************************************/
classObj_new(layerObj * layer,classObj * class)1026 classObj *classObj_new(layerObj *layer, classObj *class)
1027 {
1028   if(msGrowLayerClasses(layer) == NULL)
1029     return NULL;
1030 
1031   if(initClass((layer->class[layer->numclasses])) == -1)
1032     return NULL;
1033 
1034   if (class) {
1035     msCopyClass((layer->class[layer->numclasses]), class, layer);
1036     layer->class[layer->numclasses]->layer = layer;
1037   }
1038 
1039   layer->class[layer->numclasses]->layer = layer;
1040 
1041   layer->numclasses++;
1042 
1043   return (layer->class[layer->numclasses-1]);
1044 }
1045 
classObj_addLabel(classObj * self,labelObj * label)1046 int classObj_addLabel(classObj *self, labelObj *label)
1047 {
1048   return msAddLabelToClass(self, label);
1049 }
1050 
classObj_removeLabel(classObj * self,int index)1051 labelObj *classObj_removeLabel(classObj *self, int index)
1052 {
1053   return msRemoveLabelFromClass(self, index);
1054 }
1055 
classObj_getLabel(classObj * self,int i)1056 labelObj *classObj_getLabel(classObj *self, int i)   // returns an EXISTING label
1057 {
1058   if(i >= 0 && i < self->numlabels)
1059     return (self->labels[i]);
1060   else
1061     return(NULL);
1062 }
1063 
classObj_updateFromString(classObj * self,char * snippet)1064 int classObj_updateFromString(classObj *self, char *snippet)
1065 {
1066   return msUpdateClassFromString(self, snippet, MS_FALSE);
1067 }
1068 
classObj_convertToString(classObj * self)1069 char *classObj_convertToString(classObj *self)
1070 {
1071   return msWriteClassToString(self);
1072 }
1073 
classObj_destroy(classObj * self)1074 void  classObj_destroy(classObj *self)
1075 {
1076   return; /* do nothing, map deconstrutor takes care of it all */
1077 }
1078 
classObj_setExpression(classObj * self,char * string)1079 int classObj_setExpression(classObj *self, char *string)
1080 {
1081   if (!string || strlen(string) == 0) {
1082     msFreeExpression(&self->expression);
1083     return MS_SUCCESS;
1084   } else return msLoadExpressionString(&self->expression, string);
1085 }
1086 
classObj_getExpressionString(classObj * self)1087 char *classObj_getExpressionString(classObj *self)
1088 {
1089   return msGetExpressionString(&(self->expression));
1090 }
1091 
classObj_setText(classObj * self,layerObj * layer,char * string)1092 int classObj_setText(classObj *self, layerObj *layer, char *string)
1093 {
1094   if (!string || strlen(string) == 0) {
1095     msFreeExpression(&self->text);
1096     return MS_SUCCESS;
1097   }
1098   return msLoadExpressionString(&self->text, string);
1099 }
1100 
classObj_getTextString(classObj * self)1101 char *classObj_getTextString(classObj *self)
1102 {
1103   return msGetExpressionString(&(self->text));
1104 }
1105 
classObj_drawLegendIcon(classObj * self,mapObj * map,layerObj * layer,int width,int height,imageObj * dstImg,int dstX,int dstY)1106 int classObj_drawLegendIcon(classObj *self, mapObj *map, layerObj *layer, int width, int height, imageObj *dstImg, int dstX, int dstY)
1107 {
1108 #ifdef USE_GD
1109   msClearLayerPenValues(layer); // just in case the mapfile has already been processed
1110 #endif
1111   return msDrawLegendIcon(map, layer, self, width, height, dstImg, dstX, dstY, MS_TRUE, NULL);
1112 }
1113 
classObj_createLegendIcon(classObj * self,mapObj * map,layerObj * layer,int width,int height)1114 imageObj *classObj_createLegendIcon(classObj *self, mapObj *map, layerObj *layer, int width, int height)
1115 {
1116   return msCreateLegendIcon(map, layer, self, width, height, MS_TRUE);
1117 }
1118 
1119 
classObj_setSymbolByName(classObj * self,mapObj * map,char * pszSymbolName)1120 int classObj_setSymbolByName(classObj *self, mapObj *map, char* pszSymbolName)
1121 {
1122   /*
1123    self->symbol = msGetSymbolIndex(&map->symbolset, pszSymbolName, MS_TRUE);
1124     return self->symbol;
1125   */
1126   return -1;
1127 }
1128 
classObj_setOverlaySymbolByName(classObj * self,mapObj * map,char * pszOverlaySymbolName)1129 int classObj_setOverlaySymbolByName(classObj *self, mapObj *map, char* pszOverlaySymbolName)
1130 {
1131   /*
1132     self->overlaysymbol = msGetSymbolIndex(&map->symbolset, pszOverlaySymbolName, MS_TRUE);
1133     return self->overlaysymbol;
1134   */
1135   return -1;
1136 
1137 }
1138 
classObj_clone(classObj * class,layerObj * layer)1139 classObj *classObj_clone(classObj *class, layerObj *layer)
1140 {
1141   classObj *dstClass;
1142   dstClass = (classObj *)malloc(sizeof(classObj));
1143 
1144   initClass(dstClass);
1145   msCopyClass(dstClass, class, layer);
1146 
1147   return dstClass;
1148 }
1149 
classObj_moveStyleUp(classObj * self,int index)1150 int classObj_moveStyleUp(classObj *self, int index)
1151 {
1152   return msMoveStyleUp(self, index);
1153 }
1154 
classObj_moveStyleDown(classObj * self,int index)1155 int classObj_moveStyleDown(classObj *self, int index)
1156 {
1157   return msMoveStyleDown(self, index);
1158 }
1159 
classObj_deleteStyle(classObj * self,int index)1160 int classObj_deleteStyle(classObj *self, int index)
1161 {
1162   return msDeleteStyle(self, index);
1163 }
1164 
1165 /**********************************************************************
1166  * class extensions for pointObj, useful many places
1167  **********************************************************************/
pointObj_new()1168 pointObj *pointObj_new()
1169 {
1170   return (pointObj *)malloc(sizeof(pointObj));
1171 }
1172 
pointObj_destroy(pointObj * self)1173 void pointObj_destroy(pointObj *self)
1174 {
1175   free(self);
1176 }
1177 
pointObj_project(pointObj * self,projectionObj * in,projectionObj * out)1178 int pointObj_project(pointObj *self, projectionObj *in, projectionObj *out)
1179 {
1180   return msProjectPoint(in, out, self);
1181 }
1182 
pointObj_draw(pointObj * self,mapObj * map,layerObj * layer,imageObj * img,int class_index,char * label_string)1183 int pointObj_draw(pointObj *self, mapObj *map, layerObj *layer,
1184                   imageObj *img, int class_index, char *label_string)
1185 {
1186   return msDrawPoint(map, layer, self, img, class_index, label_string);
1187 }
1188 
pointObj_distanceToPoint(pointObj * self,pointObj * point)1189 double pointObj_distanceToPoint(pointObj *self, pointObj *point)
1190 {
1191   return msDistancePointToPoint(self, point);
1192 }
1193 
pointObj_distanceToLine(pointObj * self,pointObj * a,pointObj * b)1194 double pointObj_distanceToLine(pointObj *self, pointObj *a, pointObj *b)
1195 {
1196   return msDistancePointToSegment(self, a, b);
1197 }
1198 
pointObj_distanceToShape(pointObj * self,shapeObj * shape)1199 double pointObj_distanceToShape(pointObj *self, shapeObj *shape)
1200 {
1201   return msDistancePointToShape(self, shape);
1202 }
1203 
1204 /**********************************************************************
1205  * class extensions for lineObj (eg. a line or group of points),
1206  * useful many places
1207  **********************************************************************/
lineObj_new()1208 lineObj *lineObj_new()
1209 {
1210   lineObj *line;
1211 
1212   line = (lineObj *)malloc(sizeof(lineObj));
1213   if(!line)
1214     return(NULL);
1215 
1216   line->numpoints=0;
1217   line->point=NULL;
1218 
1219   return line;
1220 }
1221 
lineObj_destroy(lineObj * self)1222 void lineObj_destroy(lineObj *self)
1223 {
1224   free(self->point);
1225   free(self);
1226 }
1227 
lineObj_clone(lineObj * line)1228 lineObj *lineObj_clone(lineObj *line)
1229 {
1230   lineObj *dstLine;
1231   dstLine = (lineObj *)malloc(sizeof(lineObj));
1232   dstLine->numpoints= line->numpoints;
1233   dstLine->point = (pointObj *)malloc(sizeof(pointObj)*(dstLine->numpoints));
1234   msCopyLine(dstLine, line);
1235 
1236 
1237   return dstLine;
1238 }
1239 
lineObj_project(lineObj * self,projectionObj * in,projectionObj * out)1240 int lineObj_project(lineObj *self, projectionObj *in, projectionObj *out)
1241 {
1242   return msProjectLine(in, out, self);
1243 }
1244 
lineObj_get(lineObj * self,int i)1245 pointObj *lineObj_get(lineObj *self, int i)
1246 {
1247   if(i<0 || i>=self->numpoints)
1248     return NULL;
1249   else
1250     return &(self->point[i]);
1251 }
1252 
lineObj_add(lineObj * self,pointObj * p)1253 int lineObj_add(lineObj *self, pointObj *p)
1254 {
1255   if(self->numpoints == 0) { /* new */
1256     self->point = (pointObj *)malloc(sizeof(pointObj));
1257     if(!self->point)
1258       return MS_FAILURE;
1259   } else { /* extend array */
1260     self->point = (pointObj *)realloc(self->point, sizeof(pointObj)*(self->numpoints+1));
1261     if(!self->point)
1262       return MS_FAILURE;
1263   }
1264 
1265   self->point[self->numpoints].x = p->x;
1266   self->point[self->numpoints].y = p->y;
1267 #ifdef USE_POINT_Z_M
1268   self->point[self->numpoints].m = p->m;
1269 #endif
1270   self->numpoints++;
1271 
1272   return MS_SUCCESS;
1273 }
1274 
1275 
1276 /**********************************************************************
1277  * class extensions for shapeObj
1278  **********************************************************************/
shapeObj_new(int type)1279 shapeObj *shapeObj_new(int type)
1280 {
1281   shapeObj *shape;
1282 
1283   shape = (shapeObj *)malloc(sizeof(shapeObj));
1284   if(!shape)
1285     return NULL;
1286 
1287   msInitShape(shape);
1288   shape->type = type;
1289   return shape;
1290 }
1291 
shapeObj_destroy(shapeObj * self)1292 void shapeObj_destroy(shapeObj *self)
1293 {
1294   msFreeShape(self);
1295   free(self);
1296 }
1297 
shapeObj_project(shapeObj * self,projectionObj * in,projectionObj * out)1298 int shapeObj_project(shapeObj *self, projectionObj *in, projectionObj *out)
1299 {
1300   return msProjectShape(in, out, self);
1301 }
1302 
shapeObj_get(shapeObj * self,int i)1303 lineObj *shapeObj_get(shapeObj *self, int i)
1304 {
1305   if(i<0 || i>=self->numlines)
1306     return NULL;
1307   else
1308     return &(self->line[i]);
1309 }
1310 
shapeObj_add(shapeObj * self,lineObj * line)1311 int shapeObj_add(shapeObj *self, lineObj *line)
1312 {
1313   return msAddLine(self, line);
1314 }
1315 
shapeObj_draw(shapeObj * self,mapObj * map,layerObj * layer,imageObj * img)1316 int shapeObj_draw(shapeObj *self, mapObj *map, layerObj *layer,
1317                   imageObj *img)
1318 {
1319   return msDrawShape(map, layer, self, img, -1, MS_DRAWMODE_FEATURES|MS_DRAWMODE_LABELS);
1320 }
1321 
shapeObj_setBounds(shapeObj * self)1322 void shapeObj_setBounds(shapeObj *self)
1323 {
1324   int i, j;
1325 
1326   self->bounds.minx = self->bounds.maxx = self->line[0].point[0].x;
1327   self->bounds.miny = self->bounds.maxy = self->line[0].point[0].y;
1328 
1329   for( i=0; i<self->numlines; i++ ) {
1330     for( j=0; j<self->line[i].numpoints; j++ ) {
1331       self->bounds.minx = MS_MIN(self->bounds.minx, self->line[i].point[j].x);
1332       self->bounds.maxx = MS_MAX(self->bounds.maxx, self->line[i].point[j].x);
1333       self->bounds.miny = MS_MIN(self->bounds.miny, self->line[i].point[j].y);
1334       self->bounds.maxy = MS_MAX(self->bounds.maxy, self->line[i].point[j].y);
1335     }
1336   }
1337 
1338   return;
1339 }
1340 
shapeObj_copy(shapeObj * self,shapeObj * dest)1341 int shapeObj_copy(shapeObj *self, shapeObj *dest)
1342 {
1343   return(msCopyShape(self, dest));
1344 }
1345 
shapeObj_contains(shapeObj * self,pointObj * point)1346 int shapeObj_contains(shapeObj *self, pointObj *point)
1347 {
1348   if(self->type == MS_SHAPE_POLYGON)
1349     return msIntersectPointPolygon(point, self);
1350 
1351   return -1;
1352 }
1353 
shapeObj_intersects(shapeObj * self,shapeObj * shape)1354 int shapeObj_intersects(shapeObj *self, shapeObj *shape)
1355 {
1356   switch(self->type) {
1357     case(MS_SHAPE_LINE):
1358       switch(shape->type) {
1359         case(MS_SHAPE_LINE):
1360           return msIntersectPolylines(self, shape);
1361         case(MS_SHAPE_POLYGON):
1362           return msIntersectPolylinePolygon(self, shape);
1363       }
1364       break;
1365     case(MS_SHAPE_POLYGON):
1366       switch(shape->type) {
1367         case(MS_SHAPE_LINE):
1368           return msIntersectPolylinePolygon(shape, self);
1369         case(MS_SHAPE_POLYGON):
1370           return msIntersectPolygons(self, shape);
1371       }
1372       break;
1373   }
1374 
1375   return -1;
1376 }
1377 
shapeObj_getpointusingmeasure(shapeObj * self,double m)1378 pointObj *shapeObj_getpointusingmeasure(shapeObj *self, double m)
1379 {
1380   if (self)
1381     return msGetPointUsingMeasure(self, m);
1382 
1383   return NULL;
1384 }
1385 
shapeObj_getmeasureusingpoint(shapeObj * self,pointObj * point)1386 pointObj *shapeObj_getmeasureusingpoint(shapeObj *self, pointObj *point)
1387 {
1388   if (self)
1389     return msGetMeasureUsingPoint(self, point);
1390 
1391   return NULL;
1392 }
1393 
1394 
shapeObj_buffer(shapeObj * self,double width)1395 shapeObj *shapeObj_buffer(shapeObj *self, double width)
1396 {
1397   return msGEOSBuffer(self, width);
1398 }
1399 
1400 
shapeObj_simplify(shapeObj * self,double tolerance)1401 shapeObj *shapeObj_simplify(shapeObj *self, double tolerance)
1402 {
1403   return msGEOSSimplify(self, tolerance);
1404 }
1405 
1406 
shapeObj_topologypreservingsimplify(shapeObj * self,double tolerance)1407 shapeObj *shapeObj_topologypreservingsimplify(shapeObj *self, double tolerance)
1408 {
1409   return msGEOSTopologyPreservingSimplify(self, tolerance);
1410 }
1411 
1412 
shapeObj_convexHull(shapeObj * self)1413 shapeObj *shapeObj_convexHull(shapeObj *self)
1414 {
1415   return msGEOSConvexHull(self);
1416 }
1417 
shapeObj_boundary(shapeObj * self)1418 shapeObj *shapeObj_boundary(shapeObj *self)
1419 {
1420   return msGEOSBoundary(self);
1421 }
1422 
shapeObj_contains_geos(shapeObj * self,shapeObj * shape)1423 int shapeObj_contains_geos(shapeObj *self, shapeObj *shape)
1424 {
1425   return msGEOSContains(self, shape);
1426 }
1427 
shapeObj_Union(shapeObj * self,shapeObj * shape)1428 shapeObj *shapeObj_Union(shapeObj *self, shapeObj *shape)
1429 {
1430   return msGEOSUnion(self, shape);
1431 }
1432 
shapeObj_intersection(shapeObj * self,shapeObj * shape)1433 shapeObj *shapeObj_intersection(shapeObj *self, shapeObj *shape)
1434 {
1435   return msGEOSIntersection(self, shape);
1436 }
1437 
shapeObj_difference(shapeObj * self,shapeObj * shape)1438 shapeObj *shapeObj_difference(shapeObj *self, shapeObj *shape)
1439 {
1440   return msGEOSDifference(self, shape);
1441 }
1442 
shapeObj_symdifference(shapeObj * self,shapeObj * shape)1443 shapeObj *shapeObj_symdifference(shapeObj *self, shapeObj *shape)
1444 {
1445   return msGEOSSymDifference(self, shape);
1446 }
1447 
shapeObj_overlaps(shapeObj * self,shapeObj * shape)1448 int shapeObj_overlaps(shapeObj *self, shapeObj *shape)
1449 {
1450   return msGEOSOverlaps(self, shape);
1451 }
1452 
shapeObj_within(shapeObj * self,shapeObj * shape)1453 int shapeObj_within(shapeObj *self, shapeObj *shape)
1454 {
1455   return msGEOSWithin(self, shape);
1456 }
1457 
shapeObj_crosses(shapeObj * self,shapeObj * shape)1458 int shapeObj_crosses(shapeObj *self, shapeObj *shape)
1459 {
1460   return msGEOSCrosses(self, shape);
1461 }
1462 
shapeObj_touches(shapeObj * self,shapeObj * shape)1463 int shapeObj_touches(shapeObj *self, shapeObj *shape)
1464 {
1465   return msGEOSTouches(self, shape);
1466 }
1467 
shapeObj_equals(shapeObj * self,shapeObj * shape)1468 int shapeObj_equals(shapeObj *self, shapeObj *shape)
1469 {
1470   return msGEOSEquals(self, shape);
1471 }
1472 
shapeObj_disjoint(shapeObj * self,shapeObj * shape)1473 int shapeObj_disjoint(shapeObj *self, shapeObj *shape)
1474 {
1475   return msGEOSDisjoint(self, shape);
1476 }
1477 
1478 
shapeObj_getcentroid(shapeObj * self)1479 pointObj *shapeObj_getcentroid(shapeObj *self)
1480 {
1481   return msGEOSGetCentroid(self);
1482 }
1483 
shapeObj_getarea(shapeObj * self)1484 double shapeObj_getarea(shapeObj *self)
1485 {
1486   return msGEOSArea(self);
1487 }
1488 
shapeObj_getlength(shapeObj * self)1489 double shapeObj_getlength(shapeObj *self)
1490 {
1491   return msGEOSLength(self);
1492 }
1493 
shapeObj_getLabelPoint(shapeObj * self)1494 pointObj *shapeObj_getLabelPoint(shapeObj *self)
1495 {
1496   pointObj *point = (pointObj *)calloc(1, sizeof(pointObj));
1497   if (point == NULL) {
1498     msSetError(MS_MEMERR, "Failed to allocate memory for point", "getLabelPoint()");
1499     return NULL;
1500   }
1501 
1502   if(self->type == MS_SHAPE_POLYGON && msPolygonLabelPoint(self, point, -1) == MS_SUCCESS)
1503     return point;
1504 
1505   free(point);
1506   return NULL;
1507 }
1508 
1509 
1510 /**********************************************************************
1511  * class extensions for rectObj
1512  **********************************************************************/
rectObj_new()1513 rectObj *rectObj_new()
1514 {
1515   rectObj *rect;
1516 
1517   rect = (rectObj *)calloc(1, sizeof(rectObj));
1518   if(!rect)
1519     return(NULL);
1520 
1521   rect->minx = -1;
1522   rect->miny = -1;
1523   rect->maxx = -1;
1524   rect->maxy = -1;
1525 
1526   return(rect);
1527 }
1528 
rectObj_destroy(rectObj * self)1529 void rectObj_destroy(rectObj *self)
1530 {
1531   free(self);
1532 }
1533 
rectObj_project(rectObj * self,projectionObj * in,projectionObj * out)1534 int rectObj_project(rectObj *self, projectionObj *in, projectionObj *out)
1535 {
1536   return msProjectRect(in, out, self);
1537 }
1538 
rectObj_fit(rectObj * self,int width,int height)1539 double rectObj_fit(rectObj *self, int width, int height)
1540 {
1541   return  msAdjustExtent(self, width, height);
1542 }
1543 
rectObj_draw(rectObj * self,mapObj * map,layerObj * layer,imageObj * img,int classindex,char * text)1544 int rectObj_draw(rectObj *self, mapObj *map, layerObj *layer,
1545                  imageObj *img, int classindex, char *text)
1546 {
1547   shapeObj shape;
1548 
1549   msInitShape(&shape);
1550   msRectToPolygon(*self, &shape);
1551   shape.classindex = classindex;
1552 
1553   if(text && layer->class[classindex]->numlabels > 0) {
1554     shape.text = msStrdup(text);
1555   }
1556 
1557   if(MS_SUCCESS != msDrawShape(map, layer, &shape, img, -1, MS_DRAWMODE_FEATURES|MS_DRAWMODE_LABELS)) {
1558     /* error message has been set already */
1559   }
1560 
1561   msFreeShape(&shape);
1562 
1563   return 0;
1564 }
1565 
1566 /**********************************************************************
1567  * class extensions for shapefileObj
1568  **********************************************************************/
shapefileObj_new(char * filename,int type)1569 shapefileObj *shapefileObj_new(char *filename, int type)
1570 {
1571   shapefileObj *shapefile;
1572   int status;
1573 
1574   shapefile = (shapefileObj *)calloc(1,sizeof(shapefileObj));
1575   if(!shapefile)
1576     return NULL;
1577 
1578   if(type == -1)
1579     status = msShapefileOpen(shapefile, "rb", filename, MS_TRUE);
1580   else if (type == -2)
1581     status = msShapefileOpen(shapefile, "rb+", filename, MS_TRUE);
1582   else
1583     status = msShapefileCreate(shapefile, filename, type);
1584 
1585   if(status == -1) {
1586     msShapefileClose(shapefile);
1587     free(shapefile);
1588     return NULL;
1589   }
1590 
1591   return(shapefile);
1592 }
1593 
shapefileObj_destroy(shapefileObj * self)1594 void shapefileObj_destroy(shapefileObj *self)
1595 {
1596   msShapefileClose(self);
1597   free(self);
1598 }
1599 
shapefileObj_get(shapefileObj * self,int i,shapeObj * shape)1600 int shapefileObj_get(shapefileObj *self, int i, shapeObj *shape)
1601 {
1602   if(i<0 || i>=self->numshapes)
1603     return -1;
1604 
1605   msFreeShape(shape); /* frees all lines and points before re-filling */
1606   msSHPReadShape(self->hSHP, i, shape);
1607   self->lastshape = i;
1608 
1609   return MS_SUCCESS;
1610 }
1611 
shapefileObj_getPoint(shapefileObj * self,int i,pointObj * point)1612 int shapefileObj_getPoint(shapefileObj *self, int i, pointObj *point)
1613 {
1614   if(i<0 || i>=self->numshapes)
1615     return -1;
1616 
1617   return msSHPReadPoint(self->hSHP, i, point);
1618 }
1619 
shapefileObj_getTransformed(shapefileObj * self,mapObj * map,int i,shapeObj * shape)1620 int shapefileObj_getTransformed(shapefileObj *self, mapObj *map,
1621                                 int i, shapeObj *shape)
1622 {
1623   if(i<0 || i>=self->numshapes)
1624     return -1;
1625 
1626   msFreeShape(shape); /* frees all lines and points before re-filling */
1627   msSHPReadShape(self->hSHP, i, shape);
1628   msTransformShapeSimplify(shape, map->extent, map->cellsize);
1629 
1630   return 0;
1631 }
1632 
shapefileObj_getExtent(shapefileObj * self,int i,rectObj * rect)1633 void shapefileObj_getExtent(shapefileObj *self, int i, rectObj *rect)
1634 {
1635   msSHPReadBounds(self->hSHP, i, rect);
1636 }
1637 
shapefileObj_add(shapefileObj * self,shapeObj * shape)1638 int shapefileObj_add(shapefileObj *self, shapeObj *shape)
1639 {
1640   return msSHPWriteShape(self->hSHP, shape);
1641 }
1642 
shapefileObj_addPoint(shapefileObj * self,pointObj * point)1643 int shapefileObj_addPoint(shapefileObj *self, pointObj *point)
1644 {
1645   return msSHPWritePoint(self->hSHP, point);
1646 }
1647 
1648 /**********************************************************************
1649  * class extensions for projectionObj
1650  **********************************************************************/
projectionObj_new(char * string)1651 projectionObj *projectionObj_new(char *string)
1652 {
1653 
1654   int status;
1655   projectionObj *proj=NULL;
1656 
1657   proj = (projectionObj *)malloc(sizeof(projectionObj));
1658   if(!proj) return NULL;
1659   msInitProjection(proj);
1660 
1661   status = msLoadProjectionString(proj, string);
1662   if(status == -1) {
1663     msFreeProjection(proj);
1664     free(proj);
1665     return NULL;
1666   }
1667 
1668   return proj;
1669 }
1670 
projectionObj_getUnits(projectionObj * self)1671 int projectionObj_getUnits(projectionObj *self)
1672 {
1673   return GetMapserverUnitUsingProj(self);
1674 }
1675 
projectionObj_destroy(projectionObj * self)1676 void projectionObj_destroy(projectionObj *self)
1677 {
1678   msFreeProjection(self);
1679   free(self);
1680 }
1681 
projectionObj_clone(projectionObj * projection)1682 projectionObj *projectionObj_clone(projectionObj *projection)
1683 {
1684   projectionObj *dstProjection;
1685   dstProjection = (projectionObj *)malloc(sizeof(projectionObj));
1686   msInitProjection(dstProjection);
1687   msCopyProjection(dstProjection, projection);
1688 
1689   return dstProjection;
1690 }
1691 
1692 /**********************************************************************
1693  * class extensions for labelCacheObj - TP mods
1694  **********************************************************************/
labelCacheObj_freeCache(labelCacheObj * self)1695 void labelCacheObj_freeCache(labelCacheObj *self)
1696 {
1697   msFreeLabelCache(self);
1698 
1699 }
1700 
1701 /**********************************************************************
1702  * class extensions for DBFInfo - TP mods
1703  **********************************************************************/
DBFInfo_getFieldName(DBFInfo * self,int iField)1704 char *DBFInfo_getFieldName(DBFInfo *self, int iField)
1705 {
1706   static char pszFieldName[1000];
1707   int pnWidth;
1708   int pnDecimals;
1709   msDBFGetFieldInfo(self, iField, &pszFieldName[0], &pnWidth, &pnDecimals);
1710   return pszFieldName;
1711 }
1712 
DBFInfo_getFieldWidth(DBFInfo * self,int iField)1713 int DBFInfo_getFieldWidth(DBFInfo *self, int iField)
1714 {
1715   char pszFieldName[1000];
1716   int pnWidth;
1717   int pnDecimals;
1718   msDBFGetFieldInfo(self, iField, &pszFieldName[0], &pnWidth, &pnDecimals);
1719   return pnWidth;
1720 }
1721 
DBFInfo_getFieldDecimals(DBFInfo * self,int iField)1722 int DBFInfo_getFieldDecimals(DBFInfo *self, int iField)
1723 {
1724   char pszFieldName[1000];
1725   int pnWidth;
1726   int pnDecimals;
1727   msDBFGetFieldInfo(self, iField, &pszFieldName[0], &pnWidth, &pnDecimals);
1728   return pnDecimals;
1729 }
1730 
DBFInfo_getFieldType(DBFInfo * self,int iField)1731 DBFFieldType DBFInfo_getFieldType(DBFInfo *self, int iField)
1732 {
1733   return msDBFGetFieldInfo(self, iField, NULL, NULL, NULL);
1734 }
1735 
1736 /**********************************************************************
1737  * class extensions for styleObj, always within the context of a class
1738  **********************************************************************/
styleObj_new(classObj * class,styleObj * style)1739 styleObj *styleObj_new(classObj *class, styleObj *style)
1740 {
1741   if(msGrowClassStyles(class) == NULL)
1742     return NULL;
1743 
1744   if(initStyle(class->styles[class->numstyles]) == -1)
1745     return NULL;
1746 
1747   if (style)
1748     msCopyStyle(class->styles[class->numstyles], style);
1749 
1750   class->numstyles++;
1751 
1752   return class->styles[class->numstyles-1];
1753 }
1754 
styleObj_label_new(labelObj * label,styleObj * style)1755 styleObj *styleObj_label_new(labelObj *label, styleObj *style)
1756 {
1757   if(msGrowLabelStyles(label) == NULL)
1758     return NULL;
1759 
1760   if(initStyle(label->styles[label->numstyles]) == -1)
1761     return NULL;
1762 
1763   if (style)
1764     msCopyStyle(label->styles[label->numstyles], style);
1765 
1766   label->numstyles++;
1767 
1768   return label->styles[label->numstyles-1];
1769 }
1770 
styleObj_updateFromString(styleObj * self,char * snippet)1771 int styleObj_updateFromString(styleObj *self, char *snippet)
1772 {
1773   return msUpdateStyleFromString(self, snippet, MS_FALSE);
1774 }
1775 
styleObj_convertToString(styleObj * self)1776 char *styleObj_convertToString(styleObj *self)
1777 {
1778   return msWriteStyleToString(self);
1779 }
1780 
styleObj_setSymbolByName(styleObj * self,mapObj * map,char * pszSymbolName)1781 int styleObj_setSymbolByName(styleObj *self, mapObj *map, char* pszSymbolName)
1782 {
1783   self->symbol = msGetSymbolIndex(&map->symbolset, pszSymbolName, MS_TRUE);
1784   return self->symbol;
1785 }
1786 
styleObj_clone(styleObj * style)1787 styleObj *styleObj_clone(styleObj *style)
1788 {
1789   styleObj *newstyle = NULL;
1790   if (!style)
1791     return NULL;
1792 
1793   newstyle = (styleObj *)malloc(sizeof(styleObj));
1794   initStyle(newstyle);
1795 
1796   msCopyStyle(newstyle, style);
1797 
1798   return newstyle;
1799 }
1800 
styleObj_setGeomTransform(styleObj * style,char * transform)1801 void styleObj_setGeomTransform(styleObj *style, char *transform)
1802 {
1803   if (!style)
1804     return;
1805 
1806   msStyleSetGeomTransform(style, transform);
1807 }
1808 
1809 
cgirequestObj_new()1810 cgiRequestObj *cgirequestObj_new()
1811 {
1812   cgiRequestObj *request;
1813   request = msAllocCgiObj();
1814 
1815   return request;
1816 }
1817 
cgirequestObj_loadParams(cgiRequestObj * self,char * (* getenv2)(const char *,void * thread_context),char * raw_post_data,ms_uint32 raw_post_data_length,void * thread_context)1818 int cgirequestObj_loadParams(cgiRequestObj *self,
1819                              char* (*getenv2)(const char*, void* thread_context),
1820                              char *raw_post_data,
1821                              ms_uint32 raw_post_data_length,
1822                              void* thread_context)
1823 {
1824   self->NumParams = loadParams(self, getenv2, raw_post_data, raw_post_data_length, thread_context);
1825   return self->NumParams;
1826 }
1827 
1828 
cgirequestObj_setParameter(cgiRequestObj * self,char * name,char * value)1829 void cgirequestObj_setParameter(cgiRequestObj *self, char *name, char *value)
1830 {
1831   int i;
1832 
1833   if (self->NumParams == MS_DEFAULT_CGI_PARAMS) {
1834     msSetError(MS_CHILDERR, "Maximum number of items, %d, has been reached", "setItem()", MS_DEFAULT_CGI_PARAMS);
1835   }
1836 
1837   for (i=0; i<self->NumParams; i++) {
1838     if (strcasecmp(self->ParamNames[i], name) == 0) {
1839       free(self->ParamValues[i]);
1840       self->ParamValues[i] = msStrdup(value);
1841       break;
1842     }
1843   }
1844   if (i == self->NumParams) {
1845     self->ParamNames[self->NumParams] = msStrdup(name);
1846     self->ParamValues[self->NumParams] = msStrdup(value);
1847     self->NumParams++;
1848   }
1849 }
1850 
cgirequestObj_addParameter(cgiRequestObj * self,char * name,char * value)1851 void cgirequestObj_addParameter(cgiRequestObj *self, char *name, char *value)
1852 {
1853   if (self->NumParams == MS_DEFAULT_CGI_PARAMS) {
1854     msSetError(MS_CHILDERR, "Maximum number of items, %d, has been reached", "addParameter()", MS_DEFAULT_CGI_PARAMS);
1855   }
1856   self->ParamNames[self->NumParams] = msStrdup(name);
1857   self->ParamValues[self->NumParams] = msStrdup(value);
1858   self->NumParams++;
1859 }
1860 
cgirequestObj_getName(cgiRequestObj * self,int index)1861 char *cgirequestObj_getName(cgiRequestObj *self, int index)
1862 {
1863   if (index < 0 || index >= self->NumParams) {
1864     msSetError(MS_CHILDERR, "Invalid index, valid range is [0, %d]", "getName()", self->NumParams-1);
1865     return NULL;
1866   }
1867   return self->ParamNames[index];
1868 }
1869 
cgirequestObj_getValue(cgiRequestObj * self,int index)1870 char *cgirequestObj_getValue(cgiRequestObj *self, int index)
1871 {
1872   if (index < 0 || index >= self->NumParams) {
1873     msSetError(MS_CHILDERR, "Invalid index, valid range is [0, %d]", "getValue()", self->NumParams-1);
1874     return NULL;
1875   }
1876   return self->ParamValues[index];
1877 }
1878 
cgirequestObj_getValueByName(cgiRequestObj * self,const char * name)1879 char *cgirequestObj_getValueByName(cgiRequestObj *self, const char *name)
1880 {
1881   int i;
1882   for (i=0; i<self->NumParams; i++) {
1883     if (strcasecmp(self->ParamNames[i], name) == 0) {
1884       return self->ParamValues[i];
1885     }
1886   }
1887   return NULL;
1888 }
cgirequestObj_destroy(cgiRequestObj * self)1889 void cgirequestObj_destroy(cgiRequestObj *self)
1890 {
1891   free(self);
1892 }
1893 
1894 
1895 /**********************************************************************
1896  * class extensions hashTableObj
1897  **********************************************************************/
1898 
1899 // New instance
hashTableObj_new()1900 hashTableObj *hashTableObj_new()
1901 {
1902   return msCreateHashTable();
1903 }
1904 
1905 // set a hash item given key and value
hashTableObj_set(hashTableObj * self,const char * key,const char * value)1906 int hashTableObj_set(hashTableObj *self, const char *key, const char *value)
1907 {
1908   if (msInsertHashTable(self, key, value) == NULL) {
1909     return MS_FAILURE;
1910   }
1911   return MS_SUCCESS;
1912 }
1913 
1914 // get value from item by its key
hashTableObj_get(hashTableObj * self,const char * key)1915 const char *hashTableObj_get(hashTableObj *self, const char *key)
1916 {
1917   return (msLookupHashTable(self, key));
1918 }
1919 
1920 // Remove one item from hash table
hashTableObj_remove(hashTableObj * self,const char * key)1921 int hashTableObj_remove(hashTableObj *self, const char *key)
1922 {
1923   return (msRemoveHashTable(self, key));
1924 }
1925 
1926 // Clear all items in hash table (to NULL)
hashTableObj_clear(hashTableObj * self)1927 void hashTableObj_clear(hashTableObj *self)
1928 {
1929   msFreeHashItems(self);
1930   initHashTable(self);
1931 }
1932 
1933 // Return the next key or first key if previousKey == NULL
hashTableObj_nextKey(hashTableObj * self,const char * previousKey)1934 char *hashTableObj_nextKey(hashTableObj *self, const char *previousKey)
1935 {
1936   return ((char *)msNextKeyFromHashTable(self, previousKey));
1937 }
1938 
resultObj_new()1939 resultObj *resultObj_new()
1940 {
1941   resultObj *r = (resultObj *) msSmallMalloc(sizeof(resultObj));
1942   r->tileindex = -1;
1943   r->shapeindex = -1;
1944   r->resultindex = -1;
1945   return r;
1946 }
1947 
1948 /**********************************************************************
1949  * class extensions clusterObj
1950  **********************************************************************/
1951 
clusterObj_updateFromString(clusterObj * self,char * snippet)1952 int clusterObj_updateFromString(clusterObj *self, char *snippet)
1953 {
1954   return msUpdateClusterFromString(self, snippet);
1955 }
1956 
clusterObj_convertToString(clusterObj * self)1957 char *clusterObj_convertToString(clusterObj *self)
1958 {
1959   return msWriteClusterToString(self);
1960 }
1961 
clusterObj_setGroup(clusterObj * self,char * string)1962 int clusterObj_setGroup(clusterObj *self, char *string)
1963 {
1964   if (!string || strlen(string) == 0) {
1965     msFreeExpression(&self->group);
1966     return MS_SUCCESS;
1967   } else return msLoadExpressionString(&self->group, string);
1968 }
1969 
clusterObj_getGroupString(clusterObj * self)1970 char *clusterObj_getGroupString(clusterObj *self)
1971 {
1972   return msGetExpressionString(&(self->group));
1973 }
1974 
clusterObj_setFilter(clusterObj * self,char * string)1975 int clusterObj_setFilter(clusterObj *self, char *string)
1976 {
1977   if (!string || strlen(string) == 0) {
1978     msFreeExpression(&self->filter);
1979     return MS_SUCCESS;
1980   } else return msLoadExpressionString(&self->filter, string);
1981 }
1982 
clusterObj_getFilterString(clusterObj * self)1983 char *clusterObj_getFilterString(clusterObj *self)
1984 {
1985   return msGetExpressionString(&(self->filter));
1986 }
1987 
outputFormatObj_new(const char * driver,char * name)1988 outputFormatObj* outputFormatObj_new(const char *driver, char *name)
1989 {
1990   outputFormatObj *format;
1991 
1992   format = msCreateDefaultOutputFormat(NULL, driver, name);
1993 
1994   /* in the case of unsupported formats, msCreateDefaultOutputFormat
1995      should return NULL */
1996   if (!format) {
1997     msSetError(MS_MISCERR, "Unsupported format driver: %s",
1998                "outputFormatObj()", driver);
1999     return NULL;
2000   }
2001 
2002   msInitializeRendererVTable(format);
2003 
2004   /* Else, continue */
2005   format->refcount++;
2006   format->inmapfile = MS_TRUE;
2007 
2008   return format;
2009 }
2010 
outputFormatObj_destroy(outputFormatObj * self)2011 void  outputFormatObj_destroy(outputFormatObj* self)
2012 {
2013   if ( --self->refcount < 1 )
2014     msFreeOutputFormat( self );
2015 }
2016 
symbolObj_getImage(symbolObj * self,outputFormatObj * input_format)2017 imageObj *symbolObj_getImage(symbolObj *self, outputFormatObj *input_format)
2018 {
2019   imageObj *image = NULL;
2020   outputFormatObj *format = NULL;
2021   rendererVTableObj *renderer = NULL;
2022   int retval;
2023 
2024   if (self->type != MS_SYMBOL_PIXMAP) {
2025     msSetError(MS_SYMERR, "Can't return image from non-pixmap symbol",
2026                "getImage()");
2027     return NULL;
2028   }
2029 
2030   if (input_format) {
2031     format = input_format;
2032   } else {
2033     format = msCreateDefaultOutputFormat(NULL, "AGG/PNG", "png");
2034 
2035     if (format)
2036       msInitializeRendererVTable(format);
2037   }
2038 
2039   if (format == NULL) {
2040     msSetError(MS_IMGERR, "Could not create output format",
2041                "getImage()");
2042     return NULL;
2043   }
2044 
2045   renderer = format->vtable;
2046   msPreloadImageSymbol(renderer, self);
2047   if (self->pixmap_buffer) {
2048     image = msImageCreate(self->pixmap_buffer->width, self->pixmap_buffer->height, format, NULL, NULL,
2049                           MS_DEFAULT_RESOLUTION, MS_DEFAULT_RESOLUTION, NULL);
2050     if(!image) {
2051       return NULL;
2052     }
2053     retval = renderer->mergeRasterBuffer(image, self->pixmap_buffer, 1.0, 0, 0, 0, 0,
2054                                 self->pixmap_buffer->width, self->pixmap_buffer->height);
2055     if(retval != MS_SUCCESS) {
2056       msFreeImage(image);
2057       return NULL;
2058     }
2059   }
2060 
2061   return image;
2062 }
2063 
symbolObj_setImage(symbolObj * self,imageObj * image)2064 int symbolObj_setImage(symbolObj *self, imageObj *image)
2065 {
2066   rendererVTableObj *renderer = NULL;
2067 
2068   renderer = image->format->vtable;
2069 
2070   if (self->pixmap_buffer) {
2071     msFreeRasterBuffer(self->pixmap_buffer);
2072     free(self->pixmap_buffer);
2073   }
2074 
2075   self->pixmap_buffer = (rasterBufferObj*)malloc(sizeof(rasterBufferObj));
2076   if (!self->pixmap_buffer) {
2077     msSetError(MS_MEMERR, NULL, "setImage()");
2078     return MS_FAILURE;
2079   }
2080   self->type = MS_SYMBOL_PIXMAP;
2081   if(renderer->getRasterBufferCopy(image, self->pixmap_buffer) != MS_SUCCESS)
2082     return MS_FAILURE;
2083 
2084   return MS_SUCCESS;
2085 }
2086