/
layer.i
640 lines (538 loc) · 17 KB
/
layer.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/* ===========================================================================
$Id$
Project: MapServer
Purpose: SWIG interface file for mapscript layerObj extensions
Author: Steve Lime
Sean Gillies, sgillies@frii.com
===========================================================================
Copyright (c) 1996-2001 Regents of the University of Minnesota.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
===========================================================================
*/
%extend layerObj
{
layerObj(mapObj *map=NULL)
{
layerObj *layer;
int result;
if (!map) {
layer = (layerObj *) malloc(sizeof(layerObj));
if (!layer) {
msSetError(MS_MEMERR, "Failed to initialize Layer",
"layerObj()");
return NULL;
}
result = initLayer(layer, NULL);
if (result == MS_SUCCESS) {
layer->index = -1;
return layer;
}
else {
msSetError(MS_MEMERR, "Failed to initialize Layer",
"layerObj()");
return NULL;
}
}
else {
if(msGrowMapLayers(map) == NULL)
return(NULL);
if (initLayer((map->layers[map->numlayers]), map) == -1)
return(NULL);
map->layers[map->numlayers]->index = map->numlayers;
map->layerorder[map->numlayers] = map->numlayers;
map->numlayers++;
MS_REFCNT_INCR(map->layers[map->numlayers-1]);
return (map->layers[map->numlayers-1]);
}
}
~layerObj()
{
/*if (!self->map) {*/
if (self) {
if(freeLayer(self)==MS_SUCCESS) {
free(self);
}
}
}
#ifdef SWIGJAVA
%newobject cloneLayer;
layerObj *cloneLayer()
#else
%newobject clone;
layerObj *clone()
#endif
{
layerObj *layer;
int result;
layer = (layerObj *) malloc(sizeof(layerObj));
if (!layer) {
msSetError(MS_MEMERR, "Failed to initialize Layer",
"layerObj()");
return NULL;
}
result = initLayer(layer, NULL);
if (result != MS_SUCCESS) {
msSetError(MS_MEMERR, "Failed to initialize Layer",
"layerObj()");
return NULL;
}
if (msCopyLayer(layer, self) != MS_SUCCESS) {
freeLayer(layer);
free(layer);
layer = NULL;
}
layer->map = NULL;
layer->index = -1;
return layer;
}
int updateFromString(char *snippet)
{
return msUpdateLayerFromString(self, snippet, MS_FALSE);
}
#ifdef SWIGCSHARP
%apply SWIGTYPE *SETREFERENCE {classObj *classobj};
#endif
int insertClass(classObj *classobj, int index=-1)
{
return msInsertClass(self, classobj, index);
}
#ifdef SWIGCSHARP
%clear classObj *classobj;
#endif
/* removeClass() */
%newobject removeClass;
classObj *removeClass(int index)
{
classObj* c = msRemoveClass(self, index);
if (c != NULL) {
MS_REFCNT_INCR(c);
}
return c;
}
int open()
{
int status;
status = msLayerOpen(self);
if (status == MS_SUCCESS) {
return msLayerGetItems(self);
}
return status;
}
int whichShapes(rectObj rect)
{
int oldconnectiontype = self->connectiontype;
self->connectiontype = MS_INLINE;
if(msLayerWhichItems(self, MS_TRUE, NULL) != MS_SUCCESS) {
self->connectiontype = oldconnectiontype;
return MS_FAILURE;
}
self->connectiontype = oldconnectiontype;
return msLayerWhichShapes(self, rect);
}
%newobject nextShape;
shapeObj *nextShape()
{
int status;
shapeObj *shape;
shape = (shapeObj *)malloc(sizeof(shapeObj));
if (!shape) return NULL;
msInitShape(shape);
status = msLayerNextShape(self, shape);
if(status != MS_SUCCESS) {
msFreeShape(shape);
free(shape);
return NULL;
} else
return shape;
}
void close()
{
msLayerClose(self);
}
%newobject getFeature;
shapeObj *getFeature(int shapeindex, int tileindex=-1)
{
/* This version properly returns shapeObj and also has its
* arguments properly ordered so that users can ignore the
* tileindex if they are not accessing a tileindexed layer.
* See bug 586:
* http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=586 */
int retval;
shapeObj *shape;
shape = (shapeObj *)malloc(sizeof(shapeObj));
if (!shape)
return NULL;
msInitShape(shape);
shape->type = self->type;
retval = msLayerGetShape(self, shape, tileindex, shapeindex);
return shape;
}
int getShape(shapeObj *shape, int tileindex, int shapeindex)
{
return msLayerGetShape(self, shape, tileindex, shapeindex);
}
int resultsGetShape(shapeObj *shape, int shapeindex, int tileindex=-1)
{
return msLayerResultsGetShape(self, shape, tileindex, shapeindex);
}
int getNumResults()
{
if (!self->resultcache) return 0;
return self->resultcache->numresults;
}
resultCacheMemberObj *getResult(int i)
{
if (!self->resultcache) return NULL;
if (i >= 0 && i < self->resultcache->numresults)
return &self->resultcache->results[i];
else
return NULL;
}
%newobject getClass;
classObj *getClass(int i)
{
classObj *result=NULL;
if (i >= 0 && i < self->numclasses) {
result=self->class[i];
MS_REFCNT_INCR(result);
}
return result;
}
char *getItem(int i)
{
if (i >= 0 && i < self->numitems)
return (char *) (self->items[i]);
else
return NULL;
}
int draw(mapObj *map, imageObj *image)
{
return msDrawLayer(map, self, image);
}
int drawQuery(mapObj *map, imageObj *image)
{
return msDrawQueryLayer(map, self, image);
}
/* For querying, we switch layer status ON and then back to original
value before returning. */
int queryByFilter(mapObj *map, char *string)
{
int status;
int retval;
msInitQuery(&(map->query));
map->query.type = MS_QUERY_BY_FILTER;
map->query.filter = (expressionObj *) malloc(sizeof(expressionObj));
map->query.filter->string = strdup(string);
map->query.filter->type = 2000; /* MS_EXPRESSION: lot's of conflicts in mapfile.h */
map->query.layer = self->index;
map->query.rect = map->extent;
status = self->status;
self->status = MS_ON;
retval = msQueryByFilter(map);
self->status = status;
return retval;
}
int queryByAttributes(mapObj *map, char *qitem, char *qstring, int mode)
{
int status;
int retval;
msInitQuery(&(map->query));
map->query.type = MS_QUERY_BY_ATTRIBUTE;
map->query.mode = mode;
if(qitem) map->query.item = strdup(qitem);
if(qstring) map->query.str = strdup(qstring);
map->query.layer = self->index;
map->query.rect = map->extent;
status = self->status;
self->status = MS_ON;
retval = msQueryByAttributes(map);
self->status = status;
return retval;
}
int queryByPoint(mapObj *map, pointObj *point, int mode, double buffer)
{
int status;
int retval;
msInitQuery(&(map->query));
map->query.type = MS_QUERY_BY_POINT;
map->query.mode = mode;
map->query.point = *point;
map->query.buffer = buffer;
map->query.layer = self->index;
status = self->status;
self->status = MS_ON;
retval = msQueryByPoint(map);
self->status = status;
return retval;
}
int queryByRect(mapObj *map, rectObj rect)
{
int status;
int retval;
msInitQuery(&(map->query));
map->query.type = MS_QUERY_BY_RECT;
map->query.mode = MS_QUERY_MULTIPLE;
map->query.rect = rect;
map->query.layer = self->index;
status = self->status;
self->status = MS_ON;
retval = msQueryByRect(map);
self->status = status;
return retval;
}
int queryByFeatures(mapObj *map, int slayer)
{
int status;
int retval;
map->query.slayer = slayer;
map->query.layer = self->index;
status = self->status;
self->status = MS_ON;
retval = msQueryByFeatures(map);
self->status = status;
return retval;
}
int queryByShape(mapObj *map, shapeObj *shape)
{
int status;
int retval;
msInitQuery(&(map->query));
map->query.type = MS_QUERY_BY_SHAPE;
map->query.mode = MS_QUERY_MULTIPLE;
map->query.shape = (shapeObj *) malloc(sizeof(shapeObj));
msInitShape(map->query.shape);
msCopyShape(shape, map->query.shape);
map->query.layer = self->index;
status = self->status;
self->status = MS_ON;
retval = msQueryByShape(map);
self->status = status;
return retval;
}
int queryByIndex(mapObj *map, int tileindex, int shapeindex, int bAddToQuery=MS_FALSE)
{
int status;
int retval;
msInitQuery(&(map->query));
map->query.type = MS_QUERY_BY_INDEX;
map->query.mode = MS_QUERY_SINGLE;
map->query.tileindex = tileindex;
map->query.shapeindex = shapeindex;
map->query.clear_resultcache = !bAddToQuery;
map->query.layer = self->index;
status = self->status;
self->status = MS_ON;
retval = msQueryByIndex(map);
self->status = status;
return retval;
}
resultCacheObj *getResults(void)
{
return self->resultcache;
}
int setFilter(char *filter)
{
if (!filter || strlen(filter) == 0) {
freeExpression(&self->filter);
return MS_SUCCESS;
}
else return msLoadExpressionString(&self->filter, filter);
}
%newobject getFilterString;
char *getFilterString()
{
return msGetExpressionString(&(self->filter));
}
int setWKTProjection(char *wkt)
{
self->project = MS_TRUE;
return msOGCWKT2ProjectionObj(wkt, &(self->projection), self->debug);
}
%newobject getProjection;
char *getProjection()
{
return (char *) msGetProjectionString(&(self->projection));
}
int setProjection(char *proj4)
{
self->project = MS_TRUE;
return msLoadProjectionString(&(self->projection), proj4);
}
int addFeature(shapeObj *shape)
{
self->connectiontype = MS_INLINE;
if(self->features != NULL && self->features->tailifhead != NULL)
shape->index = self->features->tailifhead->shape.index + 1;
else
shape->index = 0;
if (insertFeatureList(&(self->features), shape) == NULL)
return MS_FAILURE;
return MS_SUCCESS;
}
/*
Returns the number of inline feature of a layer
*/
int getNumFeatures()
{
return msLayerGetNumFeatures(self);
}
%newobject getExtent;
rectObj *getExtent()
{
rectObj *extent;
extent = (rectObj *) malloc(sizeof(rectObj));
msLayerGetExtent(self, extent);
return extent;
}
int setExtent(double minx=-1.0, double miny=-1.0,
double maxx=-1.0, double maxy=-1.0)
{
if (minx > maxx || miny > maxy) {
msSetError(MS_RECTERR,
"{ 'minx': %f , 'miny': %f , 'maxx': %f , 'maxy': %f }",
"layerObj::setExtent()", minx, miny, maxx, maxy);
return MS_FAILURE;
}
return msLayerSetExtent(self, minx, miny, maxx, maxy);
}
/*
The following metadata methods are no longer needed since we have
promoted the metadata member of layerObj to a first-class mapscript
object. See hashtable.i. Not yet scheduled for deprecation but
perhaps in the next major release? --SG
*/
char *getMetaData(char *name)
{
char *value = NULL;
if (!name) {
msSetError(MS_HASHERR, "NULL key", "getMetaData");
}
value = (char *) msLookupHashTable(&(self->metadata), name);
/*
Umberto, 05/17/2006
Exceptions should be reserved for situations when a serious error occurred
and normal program flow must be interrupted.
In this case returning null should be more that enough.
*/
#ifndef SWIGJAVA
if (!value) {
msSetError(MS_HASHERR, "Key %s does not exist", "getMetaData", name);
return NULL;
}
#endif
return value;
}
int setMetaData(char *name, char *value)
{
if (msInsertHashTable(&(self->metadata), name, value) == NULL)
return MS_FAILURE;
return MS_SUCCESS;
}
int removeMetaData(char *name)
{
return(msRemoveHashTable(&(self->metadata), name));
}
char *getFirstMetaDataKey()
{
return (char *) msFirstKeyFromHashTable(&(self->metadata));
}
char *getNextMetaDataKey(char *lastkey)
{
return (char *) msNextKeyFromHashTable(&(self->metadata), lastkey);
}
%newobject getWMSFeatureInfoURL;
char *getWMSFeatureInfoURL(mapObj *map, int click_x, int click_y,
int feature_count, char *info_format)
{
return (char *) msWMSGetFeatureInfoURL(map, self, click_x, click_y,
feature_count, info_format);
}
%newobject executeWFSGetFeature;
char *executeWFSGetFeature(layerObj *layer)
{
return (char *) msWFSExecuteGetFeature(layer);
}
int applySLD(char *sld, char *stylelayer)
{
return msSLDApplySLD(self->map, sld, self->index, stylelayer);
}
int applySLDURL(char *sld, char *stylelayer)
{
return msSLDApplySLDURL(self->map, sld, self->index, stylelayer);
}
%newobject generateSLD;
char *generateSLD()
{
return (char *) msSLDGenerateSLD(self->map, self->index, NULL);
}
int isVisible()
{
if (!self->map)
{
msSetError(MS_MISCERR,
"visibility has no meaning outside of a map context",
"isVisible()");
return MS_FAILURE;
}
return msLayerIsVisible(self->map, self);
}
int moveClassUp(int index)
{
return msMoveClassUp(self, index);
}
int moveClassDown(int index)
{
return msMoveClassDown(self, index);
}
void setProcessingKey(const char *key, const char *value)
{
msLayerSetProcessingKey( self, key, value );
}
/* this method is deprecated ... should use addProcessing() */
void setProcessing(const char *directive )
{
msLayerAddProcessing( self, directive );
}
void addProcessing(const char *directive )
{
msLayerAddProcessing( self, directive );
}
char *getProcessing(int index)
{
return (char *) msLayerGetProcessing(self, index);
}
char *getProcessingKey(const char *key)
{
return (char *) msLayerGetProcessingKey(self, key);
}
int clearProcessing()
{
return msLayerClearProcessing(self);
}
int setConnectionType(int connectiontype, const char *library_str)
{
/* Caller is responsible to close previous layer correctly before
* calling msConnectLayer()
*/
if (msLayerIsOpen(self))
msLayerClose(self);
return msConnectLayer(self, connectiontype, library_str);
}
int getClassIndex(shapeObj *shape, double scaledenom, int *classgroup=NULL, int numclasses=0) {
return msShapeGetClass(self, shape, scaledenom, classgroup, numclasses);
}
}