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