| 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 |
#include "mapserver.h" |
|---|
| 32 |
|
|---|
| 33 |
#ifdef USE_GDAL |
|---|
| 34 |
# include "gdal.h" |
|---|
| 35 |
# include "cpl_conv.h" |
|---|
| 36 |
#endif |
|---|
| 37 |
|
|---|
| 38 |
MS_CVSID("$Id$") |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
int msInsertClass(layerObj *layer, classObj *classobj, int nIndex) |
|---|
| 47 |
{ |
|---|
| 48 |
int i; |
|---|
| 49 |
|
|---|
| 50 |
if (!classobj) |
|---|
| 51 |
{ |
|---|
| 52 |
msSetError(MS_CHILDERR, "Cannot insert NULL class", "msInsertClass()"); |
|---|
| 53 |
return -1; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
if (msGrowLayerClasses(layer) == NULL) { |
|---|
| 58 |
return -1; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
else if (nIndex >= layer->numclasses) { |
|---|
| 62 |
msSetError(MS_CHILDERR, "Cannot insert class beyond index %d", |
|---|
| 63 |
"msInsertClass()", layer->numclasses-1); |
|---|
| 64 |
return -1; |
|---|
| 65 |
} |
|---|
| 66 |
else if (nIndex < 0) { |
|---|
| 67 |
#ifndef __cplusplus |
|---|
| 68 |
layer->class[layer->numclasses]=classobj; |
|---|
| 69 |
#else |
|---|
| 70 |
layer->_class[layer->numclasses]=classobj; |
|---|
| 71 |
#endif |
|---|
| 72 |
MS_REFCNT_INCR(classobj); |
|---|
| 73 |
layer->numclasses++; |
|---|
| 74 |
return layer->numclasses-1; |
|---|
| 75 |
} |
|---|
| 76 |
else if (nIndex >= 0 && nIndex < layer->numclasses) { |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
#ifndef __cplusplus |
|---|
| 82 |
for (i=layer->numclasses-1; i>=nIndex; i--) |
|---|
| 83 |
layer->class[i+1] = layer->class[i]; |
|---|
| 84 |
layer->class[nIndex]=classobj; |
|---|
| 85 |
#else |
|---|
| 86 |
for (i=layer->numclasses-1; i>=nIndex; i--) |
|---|
| 87 |
layer->_class[i+1] = layer->_class[i]; |
|---|
| 88 |
layer->_class[nIndex]=classobj; |
|---|
| 89 |
#endif |
|---|
| 90 |
|
|---|
| 91 |
MS_REFCNT_INCR(classobj); |
|---|
| 92 |
|
|---|
| 93 |
layer->numclasses++; |
|---|
| 94 |
return nIndex; |
|---|
| 95 |
} |
|---|
| 96 |
else { |
|---|
| 97 |
msSetError(MS_CHILDERR, "Invalid index", "msInsertClass()"); |
|---|
| 98 |
return -1; |
|---|
| 99 |
} |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
classObj *msRemoveClass(layerObj *layer, int nIndex) |
|---|
| 109 |
{ |
|---|
| 110 |
int i; |
|---|
| 111 |
classObj *classobj; |
|---|
| 112 |
|
|---|
| 113 |
if (nIndex < 0 || nIndex >= layer->numclasses) |
|---|
| 114 |
{ |
|---|
| 115 |
msSetError(MS_CHILDERR, "Cannot remove class, invalid index %d", |
|---|
| 116 |
"removeClass()", nIndex); |
|---|
| 117 |
return NULL; |
|---|
| 118 |
} |
|---|
| 119 |
else |
|---|
| 120 |
{ |
|---|
| 121 |
#ifndef __cplusplus |
|---|
| 122 |
classobj=layer->class[nIndex]; |
|---|
| 123 |
#else |
|---|
| 124 |
classobj=layer->_class[nIndex]; |
|---|
| 125 |
#endif |
|---|
| 126 |
classobj->layer=NULL; |
|---|
| 127 |
MS_REFCNT_DECR(classobj); |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
for (i=nIndex; i<layer->numclasses-1; i++) |
|---|
| 131 |
{ |
|---|
| 132 |
#ifndef __cplusplus |
|---|
| 133 |
layer->class[i]=layer->class[i+1]; |
|---|
| 134 |
#else |
|---|
| 135 |
layer->_class[i]=layer->_class[i+1]; |
|---|
| 136 |
#endif |
|---|
| 137 |
} |
|---|
| 138 |
#ifndef __cplusplus |
|---|
| 139 |
layer->class[i]=NULL; |
|---|
| 140 |
#else |
|---|
| 141 |
layer->_class[i]=NULL; |
|---|
| 142 |
#endif |
|---|
| 143 |
|
|---|
| 144 |
|
|---|
| 145 |
layer->numclasses--; |
|---|
| 146 |
return classobj; |
|---|
| 147 |
} |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
int msMoveClassUp(layerObj *layer, int nClassIndex) |
|---|
| 154 |
{ |
|---|
| 155 |
classObj *psTmpClass = NULL; |
|---|
| 156 |
if (layer && nClassIndex < layer->numclasses && nClassIndex >0) |
|---|
| 157 |
{ |
|---|
| 158 |
psTmpClass=layer->class[nClassIndex]; |
|---|
| 159 |
|
|---|
| 160 |
layer->class[nClassIndex] = layer->class[nClassIndex-1]; |
|---|
| 161 |
|
|---|
| 162 |
layer->class[nClassIndex-1] = psTmpClass; |
|---|
| 163 |
|
|---|
| 164 |
return(MS_SUCCESS); |
|---|
| 165 |
} |
|---|
| 166 |
msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveClassUp()", |
|---|
| 167 |
nClassIndex); |
|---|
| 168 |
return (MS_FAILURE); |
|---|
| 169 |
} |
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
int msMoveClassDown(layerObj *layer, int nClassIndex) |
|---|
| 176 |
{ |
|---|
| 177 |
classObj *psTmpClass = NULL; |
|---|
| 178 |
if (layer && nClassIndex < layer->numclasses-1 && nClassIndex >=0) |
|---|
| 179 |
{ |
|---|
| 180 |
psTmpClass=layer->class[nClassIndex]; |
|---|
| 181 |
|
|---|
| 182 |
layer->class[nClassIndex] = layer->class[nClassIndex+1]; |
|---|
| 183 |
|
|---|
| 184 |
layer->class[nClassIndex+1] = psTmpClass; |
|---|
| 185 |
|
|---|
| 186 |
return(MS_SUCCESS); |
|---|
| 187 |
} |
|---|
| 188 |
msSetError(MS_CHILDERR, "Invalid index: %d", "msMoveClassDown()", |
|---|
| 189 |
nClassIndex); |
|---|
| 190 |
return (MS_FAILURE); |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
int msLayerSetExtent( layerObj *layer, |
|---|
| 198 |
double minx, double miny, double maxx, double maxy) |
|---|
| 199 |
{ |
|---|
| 200 |
|
|---|
| 201 |
layer->extent.minx = minx; |
|---|
| 202 |
layer->extent.miny = miny; |
|---|
| 203 |
layer->extent.maxx = maxx; |
|---|
| 204 |
layer->extent.maxy = maxy; |
|---|
| 205 |
|
|---|
| 206 |
if (minx == -1.0 && miny == -1.0 && maxx == -1.0 && maxy == -1.0) |
|---|
| 207 |
return(MS_SUCCESS); |
|---|
| 208 |
|
|---|
| 209 |
if (!MS_VALID_EXTENT(layer->extent)) { |
|---|
| 210 |
msSetError(MS_MISCERR, "Given layer extent is invalid. minx=%lf, miny=%lf, maxx=%lf, maxy=%lf.", "msLayerSetExtent()", layer->extent.minx, layer->extent.miny, layer->extent.maxx, layer->extent.maxy); |
|---|
| 211 |
return(MS_FAILURE); |
|---|
| 212 |
} |
|---|
| 213 |
|
|---|
| 214 |
return(MS_SUCCESS); |
|---|
| 215 |
} |
|---|