1 |
# -*- coding:latin1 -*- |
2 |
# Copyright (C) 2004 by Intevation GmbH |
3 |
# Authors: |
4 |
# Jan Schüngel <[email protected]> |
5 |
# |
6 |
# This program is free software under the GPL (>=v2) |
7 |
# Read the file COPYING coming with Thuban for details. |
8 |
|
9 |
""" |
10 |
Classes to represent '.map'-file Objects. |
11 |
|
12 |
The following Classes, which are implemented in |
13 |
mapscript are not implemented yet in this extension: |
14 |
|
15 |
DBFInfo, errorObj, fontSetObj, graticuleObj, imageObj, itemObj, |
16 |
labelCacheMemberObj, labelCacheObj, |
17 |
markerCacheMembet, msTiledSHPLayerInfo, queryMapObj, |
18 |
referenzMapObj, resultCacheMemberObj, resultCacheObj, |
19 |
shapefileObj, shapeObj, VectorObj |
20 |
|
21 |
the following are only used to create a necessary object. They are not |
22 |
realy created as a MF_Object. |
23 |
|
24 |
lineObj, pointObj |
25 |
""" |
26 |
|
27 |
__version__ = "$Revision$" |
28 |
# $Source$ |
29 |
# $Id$ |
30 |
|
31 |
|
32 |
# ################################################## |
33 |
# |
34 |
# import necessary modules from python and/or thuban |
35 |
# |
36 |
# ################################################## |
37 |
|
38 |
import os |
39 |
|
40 |
from Thuban.Model.color import Color, Transparent |
41 |
|
42 |
from Thuban.Model.classification import ClassGroupDefault, \ |
43 |
ClassGroupSingleton, ClassGroupRange |
44 |
|
45 |
from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, symbolObj, \ |
46 |
pointObj, lineObj |
47 |
|
48 |
from Thuban.Model.layer import RasterLayer |
49 |
|
50 |
# ################################### |
51 |
# |
52 |
# Definition of dictionaries |
53 |
# |
54 |
# the dictonaries are like in mapscript and are used to make it |
55 |
# easear to unterstand the key from mapscript for the settings |
56 |
# |
57 |
# ################################### |
58 |
|
59 |
shp_type = { 0:'point', |
60 |
1:'line', |
61 |
2:'polygon', |
62 |
3:'raster', |
63 |
4:'annotation', |
64 |
5:'circle', |
65 |
6:'query'} |
66 |
|
67 |
unit_type = { 0:"inches", |
68 |
1:"feet", |
69 |
2:"miles", |
70 |
3:"meters", |
71 |
4:"kilometers", |
72 |
5:"dd"} |
73 |
|
74 |
legend_status_type = { 0:"OFF", |
75 |
1:"ON", |
76 |
3:"embed" } |
77 |
# 2 = Default but is not allowed here |
78 |
|
79 |
scalebar_status_type = { 0:"OFF", |
80 |
1:"ON", |
81 |
3:"embed" } |
82 |
# 2 = Default but is not allowed here |
83 |
|
84 |
scalebar_style_type = { 0:"0", |
85 |
1:"1" } |
86 |
|
87 |
scalebar_position_type = { 0:"ul", |
88 |
1:"lr", |
89 |
2:"ur", |
90 |
3:"ll", |
91 |
6:"uc", |
92 |
7:"lc"} |
93 |
|
94 |
layer_status_type = { 0:"OFF", |
95 |
1:"ON", |
96 |
2:"default"} |
97 |
|
98 |
legend_position_type = { 0:"ul", |
99 |
1:"lr", |
100 |
2:"ur", |
101 |
3:"ll", |
102 |
6:"uc", |
103 |
7:"lc"} |
104 |
|
105 |
label_size_type = { 0:"tiny", |
106 |
1:"small", |
107 |
2:"medium", |
108 |
3:"large", |
109 |
4:"giant" } |
110 |
|
111 |
#TODO: build in truetype (0:"truetype") support |
112 |
label_font_type = { 1:"bitmap" } |
113 |
|
114 |
label_position_type = { 0:"ul", |
115 |
1:"lr", |
116 |
2:"ur", |
117 |
3:"ll", |
118 |
4:"cr", |
119 |
5:"cl", |
120 |
6:"uc", |
121 |
7:"lc", |
122 |
8:"cc", |
123 |
10:"auto"} |
124 |
|
125 |
|
126 |
# ################################################## |
127 |
# |
128 |
# Class Definition |
129 |
# |
130 |
# ################################################## |
131 |
|
132 |
# ################################################## |
133 |
# General Classes that are not all explicitly defined through |
134 |
# a mapfile, but rather some helper-classes. |
135 |
|
136 |
class MF_Rectangle: |
137 |
""" |
138 |
Represents an rectanle with the bottom left |
139 |
and top right corner. |
140 |
""" |
141 |
def __init__(self,mf_rect): |
142 |
self._rect = mf_rect |
143 |
|
144 |
def get_minx(self): |
145 |
return self._rect.minx |
146 |
|
147 |
def get_miny(self): |
148 |
return self._rect.miny |
149 |
|
150 |
def get_maxx(self): |
151 |
return self._rect.maxx |
152 |
|
153 |
def get_maxy(self): |
154 |
return self._rect.maxy |
155 |
|
156 |
def get_rect(self): |
157 |
return (self._rect.minx,self._rect.miny,self._rect.maxx,self._rect.maxy) |
158 |
|
159 |
def set_rect(self, minx, miny, maxx, maxy): |
160 |
self._rect.minx = minx |
161 |
self._rect.miny = miny |
162 |
self._rect.maxx = maxx |
163 |
self._rect.maxy = maxy |
164 |
|
165 |
class MF_Color: |
166 |
""" |
167 |
The corresponding MapScript object contains also the |
168 |
attribute pen which defines the stroke of the feature. |
169 |
But this actually has nothing to do with the color and |
170 |
therefore is not support here. |
171 |
|
172 |
It needs to be discussed with the MapServer developers |
173 |
whether pen would better be moved to another class. |
174 |
|
175 |
The hex color definition which is also supported by |
176 |
mapscript and Thuban is not supported as it does |
177 |
not add any capability. |
178 |
|
179 |
color is definied as RGB 0..255 |
180 |
""" |
181 |
def __init__(self, mf_color): |
182 |
self._color = mf_color |
183 |
self._tbc_red = (float(self.get_red())/255) |
184 |
self._tbc_green = (float(self.get_green())/255) |
185 |
self._tbc_blue = (float(self.get_blue())/255) |
186 |
self._thubancolor = Color(self._tbc_red, |
187 |
self._tbc_green, |
188 |
self._tbc_blue) |
189 |
|
190 |
# TODO : Check if it is necessary to use rgb colors alone |
191 |
# or whether it is sufficient to only use the Thuban Color. |
192 |
# In some it is necessary as red == -1 indicates that no color |
193 |
# is set. |
194 |
def get_red(self): |
195 |
return self._color.red |
196 |
|
197 |
def get_green(self): |
198 |
return self._color.green |
199 |
|
200 |
def get_blue(self): |
201 |
return self._color.blue |
202 |
|
203 |
def set_rgbcolor(self, red, green, blue): |
204 |
self._color.red = red |
205 |
self._color.green = green |
206 |
self._color.blue = blue |
207 |
|
208 |
self._tbc_red = (float(self.get_red())/255) |
209 |
self._tbc_green = (float(self.get_green())/255) |
210 |
self._tbc_blue = (float(self.get_blue())/255) |
211 |
self._thubancolor = Color(self._tbc_red, |
212 |
self._tbc_green, |
213 |
self._tbc_blue) |
214 |
|
215 |
def get_mfcolor(self): |
216 |
return self._color |
217 |
|
218 |
def get_thubancolor(self): |
219 |
return self._thubancolor |
220 |
|
221 |
def set_thubancolor(self, thuban_color): |
222 |
if thuban_color != Transparent: |
223 |
self._color.red = int(thuban_color.red * 255) |
224 |
self._color.green = int(thuban_color.green * 255) |
225 |
self._color.blue = int(thuban_color.blue * 255) |
226 |
self._thubancolor = thuban_color |
227 |
|
228 |
|
229 |
class MF_Metadata: |
230 |
""" |
231 |
Metadata is not a Object in mapscript witch can be used |
232 |
by ease. Only the infos can get with the functions |
233 |
"getFirstMetaDataKey", "getNextMetaDataKey" and "getMetaData". |
234 |
To get some special Metadata you need a key. So there is a special |
235 |
function which create a list of the metadatakeys. |
236 |
""" |
237 |
def __init__(self, mapobj): |
238 |
self.mapobj = mapobj |
239 |
|
240 |
def remove_allmetadata(self): |
241 |
keylist = self.get_metadatakeys() |
242 |
if keylist: |
243 |
for key in keylist: |
244 |
self.mapobj.removeMetaData(key) |
245 |
|
246 |
def get_metadatakeys(self): |
247 |
keylist = [] |
248 |
try: |
249 |
metafkey =self.mapobj.getFirstMetaDataKey() |
250 |
keylist.append(metafkey) |
251 |
except: |
252 |
return None |
253 |
else: |
254 |
if metafkey: |
255 |
while metafkey: |
256 |
metafkey = self.mapobj.getNextMetaDataKey(metafkey) |
257 |
if metafkey: |
258 |
keylist.append(metafkey) |
259 |
return keylist |
260 |
|
261 |
def get_metadata(self): |
262 |
keylist = self.get_metadatakeys() |
263 |
metadatalist = [] |
264 |
if keylist: |
265 |
for key in keylist: |
266 |
metadatalist.append([key,self.mapobj.getMetaData(key)]) |
267 |
return metadatalist |
268 |
else: |
269 |
return None |
270 |
|
271 |
def get_metadatabykey(self, key): |
272 |
return self.mapobj.getMetaData(key) |
273 |
|
274 |
def remove_metadatabykey(self, key): |
275 |
self.mapobj.removeMetaData(key) |
276 |
|
277 |
def add_metadata(self, key, data): |
278 |
self.mapobj.setMetaData(key,data) |
279 |
|
280 |
# ################################################ |
281 |
# Classes for MapServer Objects as they are |
282 |
# explicitly defined in a mapfile |
283 |
|
284 |
class MF_Outputformat: |
285 |
""" |
286 |
The Outputformat defines which and how the image is |
287 |
created by the mapserver. |
288 |
|
289 |
The following settings are used: |
290 |
name |
291 |
|
292 |
The following settings are not used: |
293 |
mimetye, driver, extension, renderer, imagemode, transparent, |
294 |
bands, numfrotmatoptions, formatoptions, refcount, inmapfile |
295 |
setExtension(), setMimetype(), setOption(), getOption() |
296 |
""" |
297 |
def __init__(self, mf_outputformat): |
298 |
self._outputformat = mf_outputformat |
299 |
|
300 |
def get_name(self): |
301 |
return self._outputformat.name |
302 |
|
303 |
|
304 |
class MF_Symbol: |
305 |
""" |
306 |
defines a single symbol which is used in the Symbolset |
307 |
|
308 |
the following settings are used: |
309 |
name, type, |
310 |
|
311 |
the following settings are not used: |
312 |
sizex, sizey, points, numpoints, filled, stylelength, |
313 |
style, imagepath, transparent, transparentcolor, character, antialias, |
314 |
font, gap, position, linecap, linejoin, linejoinmaxsize, setPoints(), |
315 |
getPoints(), setStyle() |
316 |
""" |
317 |
def __init__(self, mf_symbol = "newone"): |
318 |
# create a circle Object like shown in Thuban |
319 |
# because Thuban don't support other symbols |
320 |
|
321 |
# TODO: include the options to create a symbol, but |
322 |
# first implement a methode to edit Symbols in Thuban |
323 |
if mf_symbol == "newone": |
324 |
mf_symbol = symbolObj("") |
325 |
newpoint = pointObj() |
326 |
newpoint.x = 1 |
327 |
newpoint.y = 1 |
328 |
newline = lineObj() |
329 |
newline.add(newpoint) |
330 |
mf_symbol.setPoints(newline) |
331 |
|
332 |
self._symbol = mf_symbol |
333 |
|
334 |
def get_symbolObj(self): |
335 |
return self._symbol |
336 |
|
337 |
def get_name(self): |
338 |
return self._symbol.name |
339 |
|
340 |
def set_name(self, new_name): |
341 |
self._symbol.name = new_name |
342 |
|
343 |
def get_type(self): |
344 |
return self._symbol.type |
345 |
|
346 |
def set_type(self, new_type): |
347 |
# TODO include a function to set the type by a string |
348 |
self._symbol.type = new_type |
349 |
|
350 |
def get_filled(self): |
351 |
return self._symbol.filled |
352 |
|
353 |
def set_filled(self, new_filled): |
354 |
if new_filled: |
355 |
self._symbol.filled = 1 |
356 |
else: |
357 |
self._symbol.filled = 0 |
358 |
|
359 |
|
360 |
class MF_SymbolSet: |
361 |
""" |
362 |
defines a set of symbols, may be there can only be one |
363 |
|
364 |
the following settings are used: |
365 |
numsymbols, |
366 |
appendSymbol() |
367 |
|
368 |
filename, imagecachesize, symbol, getSymbol(), |
369 |
getSymbolByName(), index(), removeSymbol(), |
370 |
save() |
371 |
""" |
372 |
def __init__(self, mf_symbolset): |
373 |
self._symbolset = mf_symbolset |
374 |
|
375 |
# Initial Symbol List |
376 |
self._symbols = [] |
377 |
self._i = 1 |
378 |
while self._i < self._symbolset.numsymbols: |
379 |
self._symbols.append(MF_Symbol(self._symbolset.getSymbol(self._i))) |
380 |
self._i += 1 |
381 |
|
382 |
def add_symbol(self, new_symbol): |
383 |
self._symbolset.appendSymbol(new_symbol.get_symbolObj()) |
384 |
self._symbols.append(new_symbol) |
385 |
# the save function must be run to set the symbols to the |
386 |
# mapfile. I don't know why this ist so but it must be. |
387 |
# the file is empty then an we can delete it |
388 |
self._symbolset.save("tempsymbol") |
389 |
os.remove("tempsymbol") |
390 |
|
391 |
def get_symbol(self, symbolnr): |
392 |
if symbolnr < self._symbolset.numsymbols: |
393 |
return self._symbols[symbolnr-1] |
394 |
else: |
395 |
return None |
396 |
|
397 |
|
398 |
class MF_Class: |
399 |
""" |
400 |
The following parameters and functions, which the mapscript style obj |
401 |
contains, are used: |
402 |
styles, numstyles, name, status, keyimage, layer, |
403 |
getExpressionString(), setExpression(), getMetaData(), getFirstMetaDataKey(), |
404 |
getNextMetaDataKey(), getStyle() |
405 |
|
406 |
The following parameters and functions are not used: |
407 |
label, title, template, type, minscale, maxscale, debug, |
408 |
setExpression(), setText(), setMetaData(), drawLegendIcon(), |
409 |
createLegendIcon(), insertStyle(), removeStyle(), moveStyleUp(), |
410 |
moveStyleDown() |
411 |
""" |
412 |
def __init__(self, mf_class): |
413 |
""" |
414 |
Initialized a class from them given mapscript Class Object |
415 |
with a list of the included styles. |
416 |
Metadata Object will be created from the Metadata informations |
417 |
wich are holt as a List i think. |
418 |
""" |
419 |
self._clazz = mf_class |
420 |
self._styles = [] |
421 |
self._numstyles = mf_class.numstyles |
422 |
for i in range(0,self._numstyles,1): |
423 |
self._styles.append(MF_Style(mf_class.getStyle(i))) |
424 |
|
425 |
if self._clazz.getExpressionString() == '"(null)"': |
426 |
self._expression = None |
427 |
else: |
428 |
self._expression = self._clazz.getExpressionString() |
429 |
|
430 |
self.metadata = MF_Metadata(self._clazz) |
431 |
|
432 |
def get_styles(self): |
433 |
return self._styles |
434 |
|
435 |
def get_name(self): |
436 |
return self._clazz.name |
437 |
|
438 |
def get_keyimage(self): |
439 |
return self._clazz.keyimage |
440 |
|
441 |
def get_expressionstring(self): |
442 |
return self._expression |
443 |
|
444 |
def set_name(self, newname): |
445 |
self._clazz.name = newname |
446 |
|
447 |
def set_expressionstring(self, newstring): |
448 |
self._clazz.setExpression(newstring) |
449 |
self._expression = self._clazz.getExpressionString() |
450 |
|
451 |
def get_status(self): |
452 |
if self._clazz.status == 1: |
453 |
return True |
454 |
else: |
455 |
return False |
456 |
|
457 |
def set_status(self, new_status): |
458 |
if new_status: |
459 |
self._clazz.status = 1 |
460 |
else: |
461 |
self._clazz.status = 0 |
462 |
|
463 |
def add_thubanstyle(self, tb_style, type="default"): |
464 |
""" |
465 |
added a thuban style object to the mapobject |
466 |
""" |
467 |
new_styleobj = MF_Style(styleObj(self._clazz)) |
468 |
if type == "line": |
469 |
new_styleobj.set_color(tb_style.GetLineColor()) |
470 |
elif type == "point": |
471 |
# set a default symbol to show circles not only a small dot |
472 |
# symbol "circle" must create before |
473 |
# TODO: create a Symbol (more see MF_SymbolSet) |
474 |
# first the default symbol circle will be created and the size 8 |
475 |
new_styleobj.set_symbolname('circle') |
476 |
new_styleobj.set_size(8) |
477 |
if tb_style.GetLineColor() != Transparent: |
478 |
new_styleobj.set_linecolor(tb_style.GetLineColor()) |
479 |
new_styleobj.set_color(tb_style.GetFill()) |
480 |
else: |
481 |
new_styleobj.set_size(tb_style.GetLineWidth()) |
482 |
if tb_style.GetLineColor() != Transparent: |
483 |
new_styleobj.set_linecolor(tb_style.GetLineColor()) |
484 |
new_styleobj.set_color(tb_style.GetFill()) |
485 |
|
486 |
|
487 |
|
488 |
class MF_Layer: |
489 |
""" |
490 |
The following parameters and functions, which the mapscript style obj |
491 |
contains, are used: |
492 |
|
493 |
classitem, numclasses, name, data, type |
494 |
getClass(), getProjection(), getExtent(), getMetaData(), |
495 |
getFirstMetaDataKey(), getNextMetaDataKey(), status, |
496 |
|
497 |
|
498 |
The following paramters and functions are not used: |
499 |
index, map, header, footer, template, groupe, tolerance, |
500 |
toleranceunits, symbolscale, minscale, maxscale, labelminscale |
501 |
labelmaxscale, sizeunits, maxfeatures, offsite, transform, labelcache |
502 |
postlabelcache, labelitem, labelsizeitem, labelangleitem, labelitemindex |
503 |
labelsizeitemindex, labelangleitemindex, tileitem, tileindex, units |
504 |
connection, connectiontype, numitems, filteritem, styleitem, requires |
505 |
labelrequires, transparency, dump, debug, numprocessing, numjoins, |
506 |
removeClass(), open(), close(), getShape(), getNumResults(), getResult() |
507 |
getItem(), promote(), demote(), draw(), drawQuery(), queryByAttributes() |
508 |
queryByPoint(), queryByRect(), queryByFeatures(), queryByShape(), |
509 |
setFilter(), setFilterString(), setWKTProjection(), setProjection() |
510 |
addFeature(), getNumFeatures(), setMetaData(), removeMetaData(), |
511 |
getWMSFeatureInfoURL(), executeWFSGetFeature(), applySLD(), applySLDURL() |
512 |
enerateSLD(), moveClassUp(), moveClassDown(), setProcessing(), |
513 |
getProcessing(), clearProcessing() |
514 |
""" |
515 |
|
516 |
def __init__(self, mf_layer): |
517 |
""" |
518 |
Creates the Layer Object from the mapscript Layer Object. |
519 |
the class objects in the layer object will be stored in |
520 |
an array. The metadata are created as a new object. |
521 |
""" |
522 |
self._mf_layer = mf_layer |
523 |
|
524 |
# Create Classes |
525 |
# there could be more then 1 |
526 |
i = -1 |
527 |
self._classes = [] |
528 |
while i < self._mf_layer.numclasses-1: |
529 |
i += 1 |
530 |
self._classes.append(MF_Class(self._mf_layer.getClass(i))) |
531 |
|
532 |
self._projection = MF_Projection(self._mf_layer.getProjection()) |
533 |
|
534 |
# Create Metadata |
535 |
self._metadata = MF_Metadata(self._mf_layer) |
536 |
|
537 |
def get_index(self): |
538 |
return self._mf_layer.index |
539 |
|
540 |
def get_name(self): |
541 |
return self._mf_layer.name |
542 |
|
543 |
def get_data(self): |
544 |
return self._mf_layer.data |
545 |
|
546 |
def get_classes(self): |
547 |
return self._classes |
548 |
|
549 |
def set_classes(self, new_classes): |
550 |
self._classes = new_classes |
551 |
|
552 |
def get_metadata(self): |
553 |
return self._metadata |
554 |
|
555 |
def set_metadata(self, new_metadata): |
556 |
self._metadata = new_metadata |
557 |
|
558 |
def get_type(self): |
559 |
return shp_type[self._mf_layer.type] |
560 |
|
561 |
def get_classitem(self): |
562 |
return self._mf_layer.classitem |
563 |
|
564 |
def get_projection(self): |
565 |
return self._projection |
566 |
|
567 |
def get_status(self): |
568 |
# returns a integer value |
569 |
# 0 = off, 1 = on, 2 = default(always on) |
570 |
if self._mf_layer.status == 0: |
571 |
return False |
572 |
else: |
573 |
return True |
574 |
|
575 |
def get_group(self): |
576 |
return self._mf_layer.group |
577 |
|
578 |
def set_group(self, new_group): |
579 |
self._mf_layer.group = new_group |
580 |
|
581 |
def set_name(self, newname): |
582 |
self._mf_layer.name = newname |
583 |
|
584 |
def set_data(self, newdata, type="shape"): |
585 |
if type == "raster": |
586 |
self._mf_layer.data = newdata |
587 |
else: |
588 |
self._mf_layer.data = newdata[:-4] |
589 |
|
590 |
def set_status(self, newstatus): |
591 |
# status can set to true or false from thuban. |
592 |
# but mapserver supports the default value |
593 |
self._mf_layer.status = newstatus |
594 |
|
595 |
def set_classitem(self, tb_field): |
596 |
self._mf_layer.classitem = tb_field |
597 |
|
598 |
def set_type(self, tb_type): |
599 |
# if type = arc its a in shapetype line |
600 |
if tb_type == "arc": |
601 |
self._mf_layer.type = 1 |
602 |
if tb_type == "raster": |
603 |
self._mf_layer.type = 3 |
604 |
if shp_type.has_key(tb_type): |
605 |
self._mf_layer.type = tb_type |
606 |
else: |
607 |
for shp_paar_nr in shp_type: |
608 |
if shp_type[shp_paar_nr] == tb_type: |
609 |
self._mf_layer.type = shp_paar_nr |
610 |
return |
611 |
|
612 |
def set_projection(self, newprojection): |
613 |
self._mfnewprojstring = "" |
614 |
if newprojection: |
615 |
self._newparams = newprojection.GetAllParameters() |
616 |
for field in self._newparams: |
617 |
self._mfnewprojstring = self._mfnewprojstring+ "," + field |
618 |
self._mf_layer.setProjection(self._mfnewprojstring[1:]) |
619 |
self._projection.set_projection(newprojection) |
620 |
|
621 |
def add_thubanclass(self, tb_class, type=""): |
622 |
""" |
623 |
Add a thuban class object |
624 |
""" |
625 |
new_class = MF_Class(classObj(self._mf_layer)) |
626 |
self._classes.append(new_class) |
627 |
# set the class name to the Label form thuban if given, |
628 |
# else set it to the value |
629 |
if tb_class.GetLabel() != "": |
630 |
new_class.set_name(tb_class.GetLabel()) |
631 |
else: |
632 |
if isinstance(tb_class, ClassGroupDefault): |
633 |
new_class.set_name("default") |
634 |
elif isinstance(tb_class, ClassGroupSingleton): |
635 |
new_class.set_name(str(tb_class.GetValue())) |
636 |
else: |
637 |
new_class.set_name(None) |
638 |
if self.get_type() == "line": |
639 |
new_class.add_thubanstyle(tb_class.GetProperties(), type="line") |
640 |
elif self.get_type() == "point": |
641 |
new_class.add_thubanstyle(tb_class.GetProperties(), type="point") |
642 |
else: |
643 |
new_class.add_thubanstyle(tb_class.GetProperties()) |
644 |
if (type == "default"): |
645 |
return |
646 |
# removed the following two lines to check if the expressionstring |
647 |
# is needed for points, because if expressionstring is a range type, |
648 |
# no expressionstring in the default group is allowed |
649 |
elif (tb_class.Matches("DEFAULT")): |
650 |
return |
651 |
# new_class.set_expressionstring('/./') |
652 |
else: |
653 |
#check which type of expression |
654 |
if isinstance(tb_class, ClassGroupRange): |
655 |
# get the needed infos from the Range-String |
656 |
self._range_begin = tb_class.GetRange()[0] |
657 |
self._range_min = str(tb_class.GetMin()) |
658 |
self._range_max = str(tb_class.GetMax()) |
659 |
self._range_end = tb_class.GetRange()[len(tb_class.GetRange())-1] |
660 |
self._range_umn = "" |
661 |
self._range_classitem = self.get_classitem() |
662 |
# generate the operator |
663 |
if self._range_begin == "[": |
664 |
self._range_op1 = ">=" |
665 |
elif self._range_begin == "]": |
666 |
self._range_op1 = ">" |
667 |
else: |
668 |
print "error in Thuban class properties" |
669 |
#build op1 string for the lower limit |
670 |
self._range_op1 = "[" + self._range_classitem + "] " + \ |
671 |
self._range_op1 + " " +\ |
672 |
self._range_min |
673 |
# build op2 string for the upper limit |
674 |
if self._range_end == "[": |
675 |
self._range_op2 = "<" |
676 |
elif self._range_end == "]": |
677 |
self._range_op2 = "<=" |
678 |
else: |
679 |
print "error in Thuban class properties" |
680 |
|
681 |
self._range_op2 = "[" + self._range_classitem + "] " + \ |
682 |
self._range_op2 + " " +\ |
683 |
self._range_max |
684 |
# we only need AND here at the moment, becaus of the limits |
685 |
# in thuban |
686 |
self._range_combine = "AND" |
687 |
# check if the one limit is set to inf and then |
688 |
# remove the second expression becaus is not needed. |
689 |
if self._range_min == "-inf": |
690 |
self._range_combine = "" |
691 |
self._range_op1 = "" |
692 |
elif self._range_max == "inf": |
693 |
self._range_combine = "" |
694 |
self._range_op2 = "" |
695 |
# build the expression together |
696 |
self._range_umn = "(" + self._range_umn + \ |
697 |
self._range_op1 + " " +\ |
698 |
self._range_combine + \ |
699 |
self._range_op2 + " )" |
700 |
|
701 |
#set the expression to the mapscript |
702 |
new_class.set_expressionstring(self._range_umn) |
703 |
else: |
704 |
new_class.set_expressionstring(str(tb_class.GetValue())) |
705 |
new_class.set_status(tb_class.IsVisible()) |
706 |
|
707 |
def remove_allclasses(self): |
708 |
for i in range(0,len(self.get_classes()), 1): |
709 |
self._mf_layer.removeClass(i) |
710 |
self.set_classes([]) |
711 |
|
712 |
class MF_Scalebar: |
713 |
""" |
714 |
Represent the scalebar for a map |
715 |
|
716 |
The following settings are used: |
717 |
label, color, imagecolor, style, intervals, units, |
718 |
status, position, height, width |
719 |
|
720 |
The following settings are (not) used: |
721 |
backgroundcolor,outlinecolor, postlabelcache |
722 |
""" |
723 |
def __init__(self, mf_scalebar): |
724 |
self._scalebar = mf_scalebar |
725 |
self._color = MF_Color(self._scalebar.color) |
726 |
self._imagecolor = MF_Color(self._scalebar.imagecolor) |
727 |
self._label = MF_Label(self._scalebar.label) |
728 |
|
729 |
def get_label(self): |
730 |
return self._label |
731 |
|
732 |
def get_color(self): |
733 |
return self._color |
734 |
|
735 |
def get_imagecolor(self): |
736 |
return self._imagecolor |
737 |
|
738 |
def get_style(self): |
739 |
return self._scalebar.style |
740 |
|
741 |
def set_style(self, new_style): |
742 |
self._scalebar.style = new_style |
743 |
|
744 |
def get_size(self): |
745 |
#returns the size |
746 |
return (self._scalebar.width, self._scalebar.height) |
747 |
|
748 |
def set_size(self, new_width, new_height): |
749 |
self._scalebar.width = new_width |
750 |
self._scalebar.height = new_height |
751 |
|
752 |
def get_intervals(self): |
753 |
return self._scalebar.intervals |
754 |
|
755 |
def set_intervals(self, new_intervals): |
756 |
self._scalebar.intervals = new_intervals |
757 |
|
758 |
def get_units(self): |
759 |
#returns the unittype |
760 |
return unit_type[self._scalebar.units] |
761 |
|
762 |
def set_units(self, units): |
763 |
if unit_type.has_key(units): |
764 |
self._scalebar.units = units |
765 |
else: |
766 |
for unit_paar_nr in unit_type: |
767 |
if unit_type[unit_paar_nr] == units: |
768 |
self._scalebar.units = unit_paar_nr |
769 |
|
770 |
def get_status(self, mode="integer"): |
771 |
if mode == "string": |
772 |
return scalebar_status_type[self._scalebar.status] |
773 |
else: |
774 |
return self._scalebar.status |
775 |
|
776 |
def set_status(self, new_status): |
777 |
if scalebar_status_type.has_key(new_status): |
778 |
self._scalebar.status = new_status |
779 |
else: |
780 |
for scalebar_status_type_nr in scalebar_status_type: |
781 |
if scalebar_status_type[scalebar_status_type_nr] == new_status: |
782 |
self._scalebar.status = scalebar_status_type_nr |
783 |
|
784 |
def get_position(self, mode="integer"): |
785 |
if mode == "string": |
786 |
return scalebar_position_type[self._scalebar.position] |
787 |
else: |
788 |
return self._scalebar.position |
789 |
|
790 |
def set_position(self, new_position): |
791 |
if scalebar_position_type.has_key(new_position): |
792 |
self._scalebar.position = new_position |
793 |
else: |
794 |
for scalebar_position_type_nr in legend_position_type: |
795 |
if scalebar_position_type[scalebar_position_type_nr] \ |
796 |
== new_position: |
797 |
self._scalebar.position = scalebar_position_type_nr |
798 |
|
799 |
|
800 |
class MF_Map: |
801 |
""" |
802 |
The following parameters and functions, which the mapscript style obj |
803 |
contains, are used: |
804 |
|
805 |
name, numlayers, extent, shapepath, imagecolor, imagetype, units, getLayer, |
806 |
status, getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey, |
807 |
save(), setExtent(), height, width, setProjection(), setImageType(), |
808 |
|
809 |
The following parameters and functions are not used: |
810 |
maxsize, layers, symbolset, fontset, labelcache, |
811 |
transparent, interlace, imagequality, cellsize, debug, datapattern, |
812 |
templatepattern, configoptions |
813 |
zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(), |
814 |
clone(), removeLayer(), getLayerByName(), getSymbolByName(), |
815 |
prepareQuery(), prepareImage(), setOutputFormat(), draw(), |
816 |
drawQuery(), drawLegend(), drawScalebar(), embedLegend(), drawLabelCache(), |
817 |
nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(), |
818 |
queryByShape(), setWKTProjection(), saveQuery(), saveQueryASGML(), |
819 |
setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(), |
820 |
setFontSet(), saveMapContext(), loadMapContext(), moveLayerUp(), |
821 |
moveLayerDown(), getLayersDrawingOrder(), setLayersDrawingOrder(), |
822 |
setConfigOption(), getConfigOption(), applyConfigOptions(), applySLD(), |
823 |
applySLDURL(), gernerateSLD(), procecssTemplate(), processLegemdTemplate(), processQueryTemplate(), |
824 |
getOutputFormatByName(), appendOutputFormat(), removeOutputFormat(), |
825 |
""" |
826 |
def __init__(self, mf_map): |
827 |
""" |
828 |
Create the map object from the mapfile mapobject which is given. |
829 |
|
830 |
All layers in the mapfile will be written to an array. |
831 |
""" |
832 |
self._mf_map = mf_map |
833 |
self._extent = MF_Rectangle(self._mf_map.extent) |
834 |
self._imagecolor = MF_Color(self._mf_map.imagecolor) |
835 |
self._web = MF_Web(self._mf_map.web) |
836 |
self._legend = MF_Legend(self._mf_map.legend) |
837 |
self._scalebar = MF_Scalebar(self._mf_map.scalebar) |
838 |
|
839 |
# TODO: generate the list dynamical by alle supported formats. |
840 |
# At the moment outputformat only get by name, but in a next |
841 |
# version there may be a function to get the outputformat by id |
842 |
# then there is no need to define the formattypes here |
843 |
image_types = ['gif', 'png', 'png24', 'jpeg', 'wbmp', \ |
844 |
'swf', 'pdf', 'imagemap'] |
845 |
self._alloutputformats = [] |
846 |
self._imagetype = self._mf_map.imagetype |
847 |
# create a temp imagtype, because the function getOutputFormatByName() |
848 |
# set the imagetype to the received OutputFormat |
849 |
for fmtname in image_types: |
850 |
theformat = self._mf_map.getOutputFormatByName(fmtname) |
851 |
if theformat: |
852 |
self._alloutputformats.append(MF_Outputformat(theformat)) |
853 |
self._mf_map.setImageType(self._imagetype) |
854 |
|
855 |
self._outputformat = MF_Outputformat(self._mf_map.outputformat) |
856 |
|
857 |
# symbols |
858 |
self._symbolset = MF_SymbolSet(self._mf_map.symbolset) |
859 |
|
860 |
# if the map name is not set it will return a MS string. |
861 |
if self._mf_map.name != "MS": |
862 |
self._name = self._mf_map.name |
863 |
else: |
864 |
self._name = None |
865 |
|
866 |
self._projection = MF_Projection(self._mf_map.getProjection()) |
867 |
|
868 |
# Initial Layer List |
869 |
self._layers = [] |
870 |
self._i = 0 |
871 |
while self._i < self._mf_map.numlayers: |
872 |
self._layers.append(MF_Layer(self._mf_map.getLayer(self._i))) |
873 |
self._i += 1 |
874 |
|
875 |
# Shapepath if not set, shapepath will be empty |
876 |
if self._mf_map.shapepath: |
877 |
self._shapepath = self._mf_map.shapepath |
878 |
else: |
879 |
self._shapepath = "" |
880 |
|
881 |
# Create Metadata |
882 |
self._metadata = MF_Metadata(self._mf_map) |
883 |
|
884 |
def create_new_layer(self): |
885 |
""" |
886 |
the new layer must create inside the mapobj, because mapscript |
887 |
need the mapscript object as parameter for layerObj |
888 |
""" |
889 |
new_layer = MF_Layer(layerObj(self._mf_map)) |
890 |
self._layers.append(new_layer) |
891 |
# the new created layer must remove from the mapobject |
892 |
# because all layer will create new in export. |
893 |
#self._mf_map.removeLayer(self._mf_map.numlayers-1) |
894 |
return new_layer |
895 |
|
896 |
def get_mappath(self): |
897 |
return self._mf_map.mappath |
898 |
|
899 |
def set_mappath(self, new_mappath): |
900 |
self._mf_map.mappath = new_mappath |
901 |
|
902 |
def get_outputformat(self): |
903 |
return self._outputformat |
904 |
|
905 |
def get_alloutputformats(self): |
906 |
return self._alloutputformats |
907 |
|
908 |
def get_imagetype(self): |
909 |
return self._mf_map.imagetype |
910 |
|
911 |
def set_imagetype(self, new_imagetype): |
912 |
self._mf_map.setImageType(new_imagetype) |
913 |
|
914 |
def get_symbolset(self): |
915 |
return self._symbolset |
916 |
|
917 |
def get_status(self): |
918 |
if self._mf_map.status == 1: |
919 |
return True |
920 |
else: |
921 |
return False |
922 |
|
923 |
def set_status(self, new_status): |
924 |
if new_status: |
925 |
self._mf_map.status = 1 |
926 |
else: |
927 |
self._mf_map.status = 0 |
928 |
|
929 |
def get_scalebar(self): |
930 |
return self._scalebar |
931 |
|
932 |
def get_web(self): |
933 |
return self._web |
934 |
|
935 |
def get_legend(self): |
936 |
return self._legend |
937 |
|
938 |
def get_extent(self): |
939 |
return self._extent |
940 |
|
941 |
def get_layers(self): |
942 |
return self._layers |
943 |
|
944 |
def get_numlayers(self): |
945 |
return self._mf_map.numlayers |
946 |
|
947 |
def get_projection(self): |
948 |
return self._projection |
949 |
|
950 |
def get_name(self): |
951 |
return self._name |
952 |
|
953 |
def get_shapepath(self): |
954 |
# where are the shape files located. |
955 |
return self._shapepath |
956 |
|
957 |
def set_shapepath(self, new_shapepath): |
958 |
# where are the shape files located.. |
959 |
self._shapepath = new_shapepath |
960 |
|
961 |
def get_imagetype(self): |
962 |
return self._mf_map.imagetype |
963 |
|
964 |
def get_layerorder(self): |
965 |
# shows the order of layer as list |
966 |
return self._mf_map.getLayerOrder() |
967 |
|
968 |
def set_layerorder(self, new_order): |
969 |
self._mf_map.setLayerOrder(new_order) |
970 |
|
971 |
def get_size(self): |
972 |
#returns the size |
973 |
return (self._mf_map.width, self._mf_map.height) |
974 |
|
975 |
def get_units(self): |
976 |
#returns the unittype |
977 |
return unit_type[self._mf_map.units] |
978 |
|
979 |
def get_imagecolor(self): |
980 |
return self._imagecolor |
981 |
|
982 |
def set_name(self, newname): |
983 |
# whitespace musst be replaced, either no |
984 |
# mapfile will be shown in the mapserver |
985 |
if newname: |
986 |
newname = newname.replace(" ","_") |
987 |
self._name = newname |
988 |
self._mf_map.name = newname |
989 |
|
990 |
def set_extent(self, newextent): |
991 |
# TODO: add the shown extend here instead of the total |
992 |
# if no size is set or if it is zero, the size will set to 1. |
993 |
if self.get_size()[0] == - 1: |
994 |
print "define the size first to set extent" |
995 |
print "size is now set to (1,1)" |
996 |
self.set_size(1,1) |
997 |
# if an empty map is export newextent will be none |
998 |
if newextent: |
999 |
self._newrect = MF_Rectangle(rectObj(newextent[0],newextent[1], \ |
1000 |
newextent[2],newextent[3])) |
1001 |
self._mf_map.setExtent(newextent[0],newextent[1], \ |
1002 |
newextent[2],newextent[3]) |
1003 |
|
1004 |
def set_size(self, newwidth, newheight): |
1005 |
self._mf_map.width = newwidth |
1006 |
self._mf_map.height = newheight |
1007 |
|
1008 |
def set_projection(self, projection): |
1009 |
self._mfnewprojstring = "" |
1010 |
self._newparams = projection.GetAllParameters() |
1011 |
for field in self._newparams: |
1012 |
self._mfnewprojstring = self._mfnewprojstring+ "," + field |
1013 |
self._mf_map.setProjection(self._mfnewprojstring[1:]) |
1014 |
self._projection.set_projection(projection) |
1015 |
|
1016 |
def set_units(self, units): |
1017 |
if unit_type.has_key(units): |
1018 |
self._mf_map.units = units |
1019 |
else: |
1020 |
for unit_paar_nr in unit_type: |
1021 |
if unit_type[unit_paar_nr] == units: |
1022 |
self._mf_map.units = unit_paar_nr |
1023 |
|
1024 |
def get_metadata(self): |
1025 |
return self._metadata |
1026 |
|
1027 |
def add_thubanlayer(self, tb_layer): |
1028 |
""" |
1029 |
Add a thuban layer |
1030 |
""" |
1031 |
# this import statement placed here, because if it is placed at the |
1032 |
# beginning of this file, it produced the following error: |
1033 |
# NameError: global name 'AnnotationLayer' is not defined |
1034 |
# don't know why this error is produced and why it works |
1035 |
# if it is placed here instead of the beginning. |
1036 |
from Extensions.umn_mapserver.mf_import import AnnotationLayer |
1037 |
if hasattr(tb_layer,"extension_umn_layerobj"): |
1038 |
#print tb_layer.extension_umn_layerobj |
1039 |
#new_layer = MF_Layer(layerObj(self._mf_map)) |
1040 |
new_layer = tb_layer.extension_umn_layerobj |
1041 |
else: |
1042 |
new_layer = MF_Layer(layerObj(self._mf_map)) |
1043 |
self._layers.append(new_layer) |
1044 |
tb_layer.extension_umn_layerobj = new_layer |
1045 |
new_layer.remove_allclasses() |
1046 |
# init a list to set the layerorder |
1047 |
new_layer.get_index() |
1048 |
new_layer.set_name(tb_layer.Title()) |
1049 |
# TODO: implement relative pathnames |
1050 |
# yet only absolute pathnames in the LayerObj are set |
1051 |
if isinstance(tb_layer, RasterLayer ): |
1052 |
new_layer.set_data(tb_layer.GetImageFilename(), type="raster") |
1053 |
new_layer.set_type("raster") |
1054 |
new_layer.set_status(tb_layer.Visible()) |
1055 |
elif isinstance(tb_layer, AnnotationLayer): |
1056 |
new_layer.set_type("annotation") |
1057 |
new_layer.set_status(tb_layer.Visible()) |
1058 |
new_layer.set_data(tb_layer.ShapeStore().FileName()) |
1059 |
else: |
1060 |
new_layer.set_data(tb_layer.ShapeStore().FileName()) |
1061 |
new_layer.set_status(tb_layer.Visible()) |
1062 |
new_layer.set_type(tb_layer.ShapeType()) |
1063 |
if tb_layer.GetClassificationColumn(): |
1064 |
new_layer.set_classitem(tb_layer.GetClassificationColumn()) |
1065 |
if tb_layer.GetProjection(): |
1066 |
new_layer.set_projection(tb_layer.GetProjection()) |
1067 |
if tb_layer.GetClassification().GetNumGroups() > 0: |
1068 |
singletonexists = False |
1069 |
for group in range(0, \ |
1070 |
tb_layer.GetClassification().GetNumGroups(), 1): |
1071 |
if isinstance(tb_layer.GetClassification().GetGroup(group), \ |
1072 |
ClassGroupSingleton): |
1073 |
singletonexists = True |
1074 |
new_layer.add_thubanclass( \ |
1075 |
tb_layer.GetClassification().GetGroup(group)) |
1076 |
new_layer.add_thubanclass( \ |
1077 |
tb_layer.GetClassification().GetDefaultGroup()) |
1078 |
# remove the classitem if one singleton exists |
1079 |
if singletonexists == False: |
1080 |
new_layer.set_classitem(None) |
1081 |
else: |
1082 |
new_layer.add_thubanclass( \ |
1083 |
tb_layer.GetClassification().GetDefaultGroup(), \ |
1084 |
type="default") |
1085 |
# set the projection to the layer. |
1086 |
# if the layer has its own definition use it, |
1087 |
# else use the main projection |
1088 |
if tb_layer.GetProjection(): |
1089 |
new_layer.set_projection(tb_layer.GetProjection()) |
1090 |
else: |
1091 |
new_layer.set_projection(self._projection.get_projection()) |
1092 |
|
1093 |
def remove_layer(self, delnr): |
1094 |
if delnr < len(self._layers): |
1095 |
# if a layer is removed, the links for the mapscript layer and |
1096 |
# the metadata must set new |
1097 |
# TODO: All other object in a layer obj must set a new, e.g proj. |
1098 |
for ll in range(len(self._layers)-1, delnr, -1): |
1099 |
self._layers[ll]._mf_layer = self._layers[ll-1]._mf_layer |
1100 |
self._layers[ll].set_metadata(self._layers[ll-1].get_metadata()) |
1101 |
|
1102 |
self._mf_map.removeLayer(delnr) |
1103 |
self._layers.pop(delnr) |
1104 |
|
1105 |
def save_map(self, filepath): |
1106 |
# save the Map |
1107 |
# maybe an own saver can implement here |
1108 |
self._mf_map.save(filepath) |
1109 |
|
1110 |
|
1111 |
class MF_Web: |
1112 |
""" |
1113 |
Save the Web settings |
1114 |
|
1115 |
The following parametes are used: |
1116 |
imagepath, imageurl, queryformat, |
1117 |
|
1118 |
The following parameters are not used: |
1119 |
log, map, template, header, footer, empty, error, extent, |
1120 |
minscale, maxscale, mintemplate, maxtemplate |
1121 |
""" |
1122 |
def __init__(self, mf_web): |
1123 |
self._mf_web = mf_web |
1124 |
|
1125 |
def get_imagepath(self): |
1126 |
return self._mf_web.imagepath |
1127 |
|
1128 |
def set_imagepath(self, new_imagepath): |
1129 |
self._mf_web.imagepath = new_imagepath |
1130 |
|
1131 |
def get_imageurl(self): |
1132 |
return self._mf_web.imageurl |
1133 |
|
1134 |
def get_template(self): |
1135 |
return self._mf_web.template |
1136 |
|
1137 |
def set_template(self, new_template): |
1138 |
self._mf_web.template = new_template |
1139 |
|
1140 |
def set_imageurl(self, new_imageurl): |
1141 |
self._mf_web.imageurl = new_imageurl |
1142 |
|
1143 |
def get_queryformat(self): |
1144 |
return self._mf_web.queryformat |
1145 |
|
1146 |
def set_queryformat(self, new_queryformat): |
1147 |
self._mf_web.imagepath = new_queryformat |
1148 |
|
1149 |
|
1150 |
class MF_Label: |
1151 |
""" |
1152 |
The following parameters from mapscript are used: |
1153 |
type, color, size, offsetx, offsety, partials, force, buffer, |
1154 |
minfeaturesize, mindistance, |
1155 |
|
1156 |
The following parameters are not used: |
1157 |
font, outlinecolor, shadowcolor, shadowsizex, shadowsizey, |
1158 |
backgroundcolor, backgroundshadowcolor, backgroundshadowsizex, |
1159 |
backgroundshadowsizey, sizescaled, minsize, maxsize, position, angle, |
1160 |
autoangle, antialias, wrap, autominfeaturesize, |
1161 |
""" |
1162 |
def __init__(self, mf_label): |
1163 |
""" |
1164 |
Create a legend obj from the existing mapfile |
1165 |
""" |
1166 |
self._label = mf_label |
1167 |
self._color = MF_Color(self._label.color) |
1168 |
|
1169 |
def get_size(self): |
1170 |
return self._label.size |
1171 |
|
1172 |
def set_size(self, new_size): |
1173 |
if label_size_type.has_key(new_size): |
1174 |
self._label.size = new_size |
1175 |
for label_size_type_nr in label_size_type: |
1176 |
if label_size_type[label_size_type_nr] == new_size: |
1177 |
self._label.size = label_size_type_nr |
1178 |
else: |
1179 |
self._label.size = new_size |
1180 |
|
1181 |
def get_color(self): |
1182 |
return self._color |
1183 |
|
1184 |
def get_partials(self): |
1185 |
if self._label.partials == 1: |
1186 |
return True |
1187 |
else: |
1188 |
return False |
1189 |
|
1190 |
def set_partials(self, new_partials): |
1191 |
# if partials = True |
1192 |
if new_partials: |
1193 |
self._label.partials = 1 |
1194 |
elif new_partials == False: |
1195 |
self._label.partials = 0 |
1196 |
else: |
1197 |
print "must be boolean" |
1198 |
|
1199 |
def get_buffer(self): |
1200 |
return self._label.buffer |
1201 |
|
1202 |
def set_buffer(self, new_buffer): |
1203 |
self._label.buffer = new_buffer |
1204 |
|
1205 |
def get_mindistance(self): |
1206 |
return self._label.mindistance |
1207 |
|
1208 |
def set_mindistance(self, new_mindistance): |
1209 |
self._label.mindistance = new_mindistance |
1210 |
|
1211 |
def get_minfeaturesize(self): |
1212 |
return self._label.minfeaturesize |
1213 |
|
1214 |
def set_minfeaturesize(self, new_minfeaturesize): |
1215 |
self._label.minfeaturesize = new_minfeaturesize |
1216 |
|
1217 |
def get_position(self, mode="integer"): |
1218 |
if mode == "string": |
1219 |
return label_position_type[self._label.position] |
1220 |
else: |
1221 |
return self._label.position |
1222 |
|
1223 |
def set_position(self, new_position): |
1224 |
if label_position_type.has_key(new_position): |
1225 |
self._label.position = new_position |
1226 |
else: |
1227 |
for label_position_type_nr in label_position_type: |
1228 |
if label_position_type[label_position_type_nr] == new_position: |
1229 |
self._label.position = label_position_type_nr |
1230 |
|
1231 |
def get_force(self): |
1232 |
if self._label.force == 1: |
1233 |
return True |
1234 |
else: |
1235 |
return False |
1236 |
|
1237 |
def set_force(self, new_force): |
1238 |
if new_force: |
1239 |
self._label.force = 1 |
1240 |
else: |
1241 |
self._label.force = 0 |
1242 |
|
1243 |
def get_type(self): |
1244 |
return label_font_type[self._label.type] |
1245 |
|
1246 |
def set_type(self, new_type): |
1247 |
if label_font_type.has_key(new_type): |
1248 |
self._label.type = new_type |
1249 |
else: |
1250 |
for label_font_type_nr in label_font_type: |
1251 |
if label_font_type[label_font_type_nr] == new_type: |
1252 |
self._label.type = label_font_type_nr |
1253 |
|
1254 |
def get_offset(self): |
1255 |
return (self._label.offsetx, self._label.offsety) |
1256 |
|
1257 |
def set_offset(self, new_offsetx, new_offsety): |
1258 |
self._label.offsetx = new_offsetx |
1259 |
self._label.offsety = new_offsety |
1260 |
|
1261 |
|
1262 |
class MF_Legend: |
1263 |
""" |
1264 |
The following parameters are (not) used: |
1265 |
imagecolor, label, keysizex, keysizey, status, position, |
1266 |
|
1267 |
The following parameters are not used: |
1268 |
keyspacingx, keyspacingy, |
1269 |
outlinecolor, height, width, postlabelcache, template, map |
1270 |
""" |
1271 |
def __init__(self, mf_legend): |
1272 |
""" |
1273 |
Create a legend obj from the existing mapfile |
1274 |
""" |
1275 |
self._mf_legend = mf_legend |
1276 |
self._imagecolor = MF_Color(self._mf_legend.imagecolor) |
1277 |
self._label = MF_Label(self._mf_legend.label) |
1278 |
|
1279 |
def get_imagecolor(self): |
1280 |
return self._imagecolor |
1281 |
|
1282 |
def get_label(self): |
1283 |
return self._label |
1284 |
|
1285 |
def get_keysize(self): |
1286 |
return (self._mf_legend.keysizex, self._mf_legend.keysizey) |
1287 |
|
1288 |
def set_keysize(self, new_keysizex, new_keysizey): |
1289 |
self._mf_legend.keysizex = new_keysizex |
1290 |
self._mf_legend.keysizey = new_keysizey |
1291 |
|
1292 |
def get_keyspacing(self): |
1293 |
return (self._mf_legend.keyspacingx, self._mf_legend.keyspacingy) |
1294 |
|
1295 |
def set_keyspacing(self, new_keyspacingx, new_keyspacingy): |
1296 |
self._mf_legend.keyspacingx = new_keyspacingx |
1297 |
self._mf_legend.keyspacingy = new_keyspacingy |
1298 |
|
1299 |
def get_status(self, mode="integer"): |
1300 |
if mode == "string": |
1301 |
return legend_status_type[self._mf_legend.status] |
1302 |
else: |
1303 |
return self._mf_legend.status |
1304 |
|
1305 |
def set_status(self, new_status): |
1306 |
if legend_status_type.has_key(new_status): |
1307 |
self._mf_legend.status = new_status |
1308 |
else: |
1309 |
for legend_status_type_nr in legend_status_type: |
1310 |
if legend_status_type[legend_status_type_nr] == new_status: |
1311 |
self._mf_legend.status = legend_status_type_nr |
1312 |
|
1313 |
def get_position(self, mode="integer"): |
1314 |
if mode == "string": |
1315 |
return legend_position_type[self._mf_legend.position] |
1316 |
else: |
1317 |
return self._mf_legend.position |
1318 |
|
1319 |
def set_position(self, new_position): |
1320 |
if legend_position_type.has_key(new_position): |
1321 |
self._mf_legend.position = new_position |
1322 |
else: |
1323 |
for legend_position_type_nr in legend_position_type: |
1324 |
if legend_position_type[legend_position_type_nr]== new_position: |
1325 |
self._mf_legend.position = legend_position_type_nr |
1326 |
|
1327 |
class MF_Projection: |
1328 |
""" |
1329 |
The following parameter, which the mapscript style obj contains is used: |
1330 |
|
1331 |
numargs |
1332 |
""" |
1333 |
|
1334 |
def __init__(self, mf_projection): |
1335 |
""" |
1336 |
Create a projection object from the given mapscript projection |
1337 |
object. If it is a epsg code the extracted from the string |
1338 |
(e.g."init=epsg:xxxx"), else the projection parameters will |
1339 |
be splitted and an array with the parameters will be creaded. |
1340 |
""" |
1341 |
self._mfprojstring = mf_projection |
1342 |
self._projstring = self._mfprojstring |
1343 |
self._epsgcode = None |
1344 |
self._params = None |
1345 |
if self._mfprojstring: |
1346 |
if self._mfprojstring.find("init=epsg:") != -1: |
1347 |
self._initcode, self._epsgcode = self._mfprojstring.split(':') |
1348 |
else: |
1349 |
self._params = [] |
1350 |
self._params = self._mfprojstring.split("+") |
1351 |
if self._params[0] == "": |
1352 |
self._params.remove("") |
1353 |
|
1354 |
def epsg_code_to_projection(self, epsg): |
1355 |
""" |
1356 |
Find the projection for the given epsg code. |
1357 |
|
1358 |
Copied from Extension/wms/layer.py |
1359 |
|
1360 |
epsg -- EPSG code as string |
1361 |
""" |
1362 |
#Needed only for this function |
1363 |
from Thuban.Model.resource import get_system_proj_file, EPSG_PROJ_FILE,\ |
1364 |
EPSG_DEPRECATED_PROJ_FILE |
1365 |
|
1366 |
proj_file, warnings = get_system_proj_file(EPSG_PROJ_FILE) |
1367 |
|
1368 |
for proj in proj_file.GetProjections(): |
1369 |
if proj.EPSGCode() == epsg: |
1370 |
return proj |
1371 |
|
1372 |
proj_file, warnings = get_system_proj_file(EPSG_DEPRECATED_PROJ_FILE) |
1373 |
for proj in proj_file.GetProjections(): |
1374 |
if proj.EPSGCode() == epsg: |
1375 |
return proj |
1376 |
return None |
1377 |
|
1378 |
def get_params(self): |
1379 |
#Parameter from the mf_projectionstring as Array |
1380 |
return self._params |
1381 |
|
1382 |
def get_epsgcode(self): |
1383 |
# returnes the epsg number |
1384 |
return self._epsgcode |
1385 |
|
1386 |
def get_epsgproj(self): |
1387 |
# get an epsg projectionobject |
1388 |
return self.epsg_code_to_projection(self._epsgcode) |
1389 |
|
1390 |
def get_projection(self): |
1391 |
return self._projstring |
1392 |
|
1393 |
def set_projection(self, newprojection): |
1394 |
self._projstring = newprojection |
1395 |
self._params = newprojection.GetAllParameters() |
1396 |
self._mfnewprojstring = "" |
1397 |
for field in self._params: |
1398 |
self._mfnewprojstring = self._mfnewprojstring+ "+" + field |
1399 |
self._mfprojstring = self._mfnewprojstring |
1400 |
|
1401 |
|
1402 |
class MF_Style: |
1403 |
""" |
1404 |
The following parameters, which the mapscript style obj |
1405 |
contains, are used: |
1406 |
color, backgroundcolor, outlinecolor, size, symbolname |
1407 |
|
1408 |
The following are not used: |
1409 |
symbol, sizescaled, minsize, maxsize, offsetx, offsety, |
1410 |
antialias |
1411 |
""" |
1412 |
|
1413 |
def __init__(self, mf_style): |
1414 |
""" |
1415 |
Create a style object from the given mapscript style object. |
1416 |
The color Object from the color and the outlinecolor parameter |
1417 |
will be created. if the color (red, green or blue) is -1 there |
1418 |
is no definition in the mapfile and so there is no color object, |
1419 |
it will set to 'None'. |
1420 |
""" |
1421 |
self._style = mf_style |
1422 |
if self._style.color.red == -1: |
1423 |
self._color = None |
1424 |
else: |
1425 |
self._color = MF_Color(self._style.color) |
1426 |
if self._style.outlinecolor.red == -1: |
1427 |
self._outlinecolor = None |
1428 |
else: |
1429 |
self._outlinecolor = MF_Color(self._style.outlinecolor) |
1430 |
|
1431 |
def get_color(self): |
1432 |
return self._color |
1433 |
|
1434 |
def get_outlinecolor(self): |
1435 |
return self._outlinecolor |
1436 |
|
1437 |
def get_size(self): |
1438 |
return self._style.size |
1439 |
|
1440 |
def set_linecolor(self, tb_color): |
1441 |
self._color = tb_color |
1442 |
new_linecolor = MF_Color(colorObj()) |
1443 |
new_linecolor.set_thubancolor(tb_color) |
1444 |
self._outlinecolor = new_linecolor |
1445 |
self._style.outlinecolor = new_linecolor.get_mfcolor() |
1446 |
|
1447 |
def set_color(self, tb_color): |
1448 |
self._color = tb_color |
1449 |
new_color = MF_Color(colorObj()) |
1450 |
new_color.set_thubancolor(tb_color) |
1451 |
self._color = new_color |
1452 |
self._style.color = new_color.get_mfcolor() |
1453 |
|
1454 |
def set_size(self, newsize): |
1455 |
self._style.size = newsize |
1456 |
|
1457 |
def set_symbolname(self, newsymbol): |
1458 |
# its possible to use stringnames instead of numbers |
1459 |
self._style.symbolname = newsymbol |
1460 |
|