/[thuban]/trunk/thuban/Extensions/umn_mapserver/mapfile.py
ViewVC logotype

Contents of /trunk/thuban/Extensions/umn_mapserver/mapfile.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2265 - (show annotations)
Tue Jul 6 14:28:52 2004 UTC (20 years, 8 months ago) by jschuengel
File MIME type: text/x-python
File size: 39615 byte(s)
Added the symbolObj, pointObj and line Obj and add the scalebar_status_type, scalebar_style_type and scalebar_position_type.
Added the symbol- and symbolsetObject (MF_Symbol,MF_Symbolset). The are only used to create a Symbol like the circle in Thuban.
Added the scalebarObject (MF_Scalebar)
(MF_Class): Added set_status and get_status.
(MF_Layer.add_thubanclass): Added code to set the class status
(MF_Map): Added code to handle the symbols and scalebar
(MF_Label): Added the set_partials and get_partials functions

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, lineObj,
17 markerCacheMembet, msTiledSHPLayerInfo, OutputFormat, pointObj, queryMapObj,
18 referenzMapObj, resultCacheMemberObj, resultCacheObj, scalebarObj,
19 shapefileObj, shapeObj, VectorObj, WebObj
20 """
21
22 __version__ = "$Revision$"
23 # $Source$
24 # $Id$
25
26
27 # ##################################################
28 #
29 # import necessary modules from python and/or thuban
30 #
31 # ##################################################
32
33 import os
34
35 from Thuban.Model.color import Color, Transparent
36
37 from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, symbolObj, \
38 pointObj, lineObj
39
40
41 # ###################################
42 #
43 # Definition of dictionaries
44 #
45 # ###################################
46
47 shp_type = { 0:'point',
48 1:'line',
49 2:'polygon',
50 3:'raster',
51 4:'annotation',
52 5:'circle',
53 6:'query'}
54
55 unit_type = { 0:"inches",
56 1:"feet",
57 2:"miles",
58 3:"meters",
59 4:"kilometers",
60 5:"dd"}
61
62 legend_status_type = { 0:"OFF",
63 1:"ON",
64 3:"embed" }
65 # 2 = Default but will not be imported because
66 # mapscript dont support it and its not allowed
67 scalebar_status_type = { 0:"OFF",
68 1:"ON",
69 3:"embed" }
70 # 2 = Default but will not be imported because
71 # mapscript dont support it and its not allowed
72
73 scalebar_style_type = { 0:"0",
74 1:"1" }
75
76 scalebar_position_type = { 0:"ul",
77 1:"lr",
78 2:"ur",
79 3:"ll",
80 6:"uc",
81 7:"lc"}
82
83 layer_status_type = { 0:"OFF",
84 1:"ON",
85 2:"default"}
86
87 legend_position_type = { 0:"ul",
88 1:"lr",
89 2:"ur",
90 3:"ll",
91 6:"uc",
92 7:"lc"}
93
94 label_size_type = { 0:"tiny",
95 1:"small",
96 2:"medium",
97 3:"large",
98 4:"giant" }
99
100 label_font_type = { 0:"truetype",
101 1:"bitmap" }
102
103
104 # ##################################################
105 #
106 # Class Definition
107 #
108 # ##################################################
109
110 # ##################################################
111 # General Classes that are not all explicitly defined through
112 # a mapfile, but rather some helper-classes.
113
114 class MF_Rectangle:
115 """
116 Represents an rectanle with the bottom left
117 and top right corner.
118 """
119 def __init__(self,mf_rect):
120 self._rect = mf_rect
121
122 def get_minx(self):
123 return self._rect.minx
124
125 def get_miny(self):
126 return self._rect.miny
127
128 def get_maxx(self):
129 return self._rect.maxx
130
131 def get_maxy(self):
132 return self._rect.maxy
133
134 def get_rect(self):
135 return (self._rect.minx,self._rect.miny,self._rect.maxx,self._rect.maxy)
136
137 def set_rect(self, minx, miny, maxx, maxy):
138 self._rect.minx = minx
139 self._rect.miny = miny
140 self._rect.maxx = maxx
141 self._rect.maxy = maxy
142
143 class MF_Color:
144 """
145 The corresponding MapScript object contains also the
146 attribute pen which defines the stroke of the feature.
147 But this actually has nothing to do with the color and
148 therefore is not support here.
149
150 It needs to be discussed with the MapServer developers
151 whether pen would better be moved to another class.
152
153 The hex color definition which is also supported by
154 mapscript and Thuban is not supported as it does
155 not add any capability.
156
157 color is definied as RGB 0..255
158 """
159 def __init__(self, mf_color):
160 self._color = mf_color
161
162 self._tbc_red = (float(self.get_red())/255)
163 self._tbc_green = (float(self.get_green())/255)
164 self._tbc_blue = (float(self.get_blue())/255)
165 self._thubancolor = Color(self._tbc_red, self._tbc_green, self._tbc_blue)
166
167 # TODO : Check if it is necessary to use rgb colors alone
168 # or whether it is sufficient to only use the Thuban Color.
169 # In some it is necessary as red == -1 indicates that no color
170 # is set.
171 def get_red(self):
172 return self._color.red
173
174 def get_green(self):
175 return self._color.green
176
177 def get_blue(self):
178 return self._color.blue
179
180 def set_rgbcolor(self, red, green, blue):
181 self._color.red = red
182 self._color.green = green
183 self._color.blue = blue
184
185 self._tbc_red = (float(self.get_red())/255)
186 self._tbc_green = (float(self.get_green())/255)
187 self._tbc_blue = (float(self.get_blue())/255)
188 self._thubancolor = Color(self._tbc_red, self._tbc_green, self._tbc_blue)
189
190 def get_mfcolor(self):
191 return self._color
192
193 def get_thubancolor(self):
194 return self._thubancolor
195
196 def set_thubancolor(self, thuban_color):
197 if thuban_color != Transparent:
198 self._color.red = int(thuban_color.red * 255)
199 self._color.green = int(thuban_color.green * 255)
200 self._color.blue = int(thuban_color.blue * 255)
201 self._thubancolor = thuban_color
202
203
204 class MF_Metadata:
205 """
206 Metadata is not a Object in mapscript witch can be used
207 by ease. Only the infos can get with the functions
208 "getFirstMetaDataKey", "getNextMetaDataKey" and "getMetaData".
209 To get some special Metadata you need a key. So the metadata will
210 saved as an dictionary to geht the information with the key here.
211
212 The metadata obj will be created and filled with infos like
213 the following code sample:
214
215 self.metadata = MF_Metadata()
216 try:
217 self.metafkey = varia.getFirstMetaDataKey()
218 except:
219 self.metadata = None
220 else:
221 while self.metafkey:
222 self.metakeydata = varia.getMetaData(self.metafkey)
223 self.metadata.add_metadata(self.metafkey,self.metakeydata)
224 self.metafkey = varia.getNextMetaDataKey(self.metafkey)
225
226 Metadata are not really needed at the moment.
227 """
228
229 def __init__(self):
230 self.data = {}
231
232 def get_metadata(self):
233 return self.data
234
235 def get_metadatabykey(self, key):
236 return self.data[key]
237
238 def add_metadata(self, key, data):
239 self.data[key] = data
240
241 # ##################################################
242 # Classes for MapServer Objects as they are
243 # explicitly defined in a mapfile
244
245 class MF_Symbol:
246 """
247 defines a single symbol which is used in the Symbolset
248
249 name, type, sizex, sizey, points, numpoints, filled, stylelength,
250 style, imagepath, transparent, transparentcolor, character, antialias,
251 font, gap, position, linecap, linejoin, linejoinmaxsize, setPoints(),
252 getPoints(), setStyle()
253 """
254
255 def __init__(self, mf_symbol = "newone"):
256 # create a circle Object like shown in Thuban
257 # because Thuban don't support other symbols
258 if mf_symbol == "newone":
259 mf_symbol = symbolObj("")
260 newpoint = pointObj()
261 newpoint.x = 1
262 newpoint.y = 1
263 newline = lineObj()
264 newline.add(newpoint)
265 mf_symbol.setPoints(newline)
266
267 self._symbol = mf_symbol
268
269 def get_symbolObj(self):
270 return self._symbol
271
272 def get_name(self):
273 return self._symbol.name
274
275 def set_name(self, new_name):
276 self._symbol.name = new_name
277
278 def set_type(self, new_type):
279 # TODO include a function to set the type by a string
280 self._symbol.type = new_type
281
282 def set_filled(self, new_filled):
283 if new_filled:
284 self._symbol.filled = 1
285 else:
286 self._symbol.filled = 0
287
288
289
290 class MF_SymbolSet:
291 """
292 defines a set of symbols, may be there can only be one
293
294 filename, imagecachesize, numsymbols, symbol, getSymbol(),
295 getSymbolByName(), index(), appendSymbol(), removeSymbol(),
296 save()
297 """
298
299 # TODO: include the symbolset, but found only the possibility to
300 # create an extra symbol file and not to include it direct to the
301 # mapfile itself
302 def __init__(self, mf_symbolset):
303 self._symbolset = mf_symbolset
304
305 # Initial Symbol List
306 self._symbols = []
307 self._numsymbols = self._symbolset.numsymbols
308 self._i = 1
309 while self._i < self._numsymbols:
310 self._symbols.append(MF_Symbol(self._symbolset.getSymbol(self._i)))
311 self._i += 1
312
313 # POINT
314 # 1 1
315 # END
316
317 def add_symbol(self, new_symbol):
318 self._symbolset.appendSymbol(new_symbol.get_symbolObj())
319 self._symbols.append(new_symbol)
320 # the save function must be run to set the symbols to the
321 # mapfile. I don't know why this ist so but it must be.
322 self._symbolset.save("tempsymbol")
323 os.remove("tempsymbol")
324
325 def get_symbol(self, symbolnr):
326 if symbolnr < self._numsymbols:
327 return self._symbols[symbolnr-1]
328 else:
329 return None
330
331 class MF_Class:
332 """
333 The following parameters and functions, which the mapscript style obj
334 contains, are used:
335 styles, numstyles, name,
336 getExpressionString(), setExpression(), getMetaData(), getFirstMetaDataKey(),
337 getNextMetaDataKey(), getStyle()
338
339 The following parameters and functions are not used:
340 status, label, title, template, type, minscale, maxscale, layer,
341 debig, keyimage,
342 setExpression(), setText(), setMetaData(), drawLegendIcon(),
343 createLegendIcon(), insertStyle(), removeStyle(), moveStyleUp(),
344 moveStyleDown()
345 """
346 def __init__(self, mf_class):
347 """
348 Initialized a class from them given mapscript Class Object
349 with a list of the included styles.
350 Metadata Object will be created from the Metadata informations
351 wich are holt as a List i think.
352 """
353 self._clazz = mf_class
354 self._styles = []
355 self._numstyles = mf_class.numstyles
356 for i in range(0,self._numstyles,1):
357 self._styles.append(MF_Style(mf_class.getStyle(i)))
358
359 if self._clazz.getExpressionString() == '"(null)"':
360 self._expression = None
361 else:
362 self._expression = self._clazz.getExpressionString()
363
364 self.metadata = MF_Metadata()
365 try:
366 self.metafkey = mf_class.getFirstMetaDataKey()
367 except:
368 self.metadata = None
369 else:
370 while self.metafkey:
371 self.metakeydata = mf_class.getMetaData(self.metafkey)
372 self.metadata.add_metadata(self.metafkey,self.metakeydata)
373 self.metafkey = mf_class.getNextMetaDataKey(self.metafkey)
374
375 def get_styles(self):
376 return self._styles
377
378 def get_name(self):
379 return self._clazz.name
380
381 def get_keyimage(self):
382 return self._clazz.keyimage
383
384 def get_expressionstring(self):
385 return self._expression
386
387 def set_name(self, newname):
388 self._clazz.name = newname
389
390 def set_expressionstring(self, newstring):
391 self._clazz.setExpression(newstring)
392 self._expression = self._clazz.getExpressionString()
393
394 def get_status(self):
395 if self._clazz.status == 1:
396 return True
397 else:
398 return False
399
400 def set_status(self, new_status):
401 if new_status:
402 self._clazz.status = 1
403 else:
404 self._clazz.status = 0
405
406 def add_thubanstyle(self, tb_style, type="default"):
407 """
408 added a thuban style object to the mapobject
409 """
410 new_styleobj = MF_Style(styleObj(self._clazz))
411 if type == "line":
412 new_styleobj.set_color(tb_style.GetLineColor())
413 elif type == "point":
414 # set a default symbol to show circles not only a small dot
415 # symbol "circle" must create before
416 # TODO: create a Symbol (more see MF_SymbolSet)
417 # first the default symbol circle will be created and the size 8
418 new_styleobj.set_symbolname('circle')
419 new_styleobj.set_size(8)
420 if tb_style.GetLineColor() != Transparent:
421 new_styleobj.set_linecolor(tb_style.GetLineColor())
422 new_styleobj.set_color(tb_style.GetFill())
423 else:
424 new_styleobj.set_size(tb_style.GetLineWidth())
425 new_styleobj.set_linecolor(tb_style.GetLineColor())
426 new_styleobj.set_color(tb_style.GetFill())
427
428
429
430 class MF_Layer:
431 """
432 The following parameters and functions, which the mapscript style obj
433 contains, are used:
434
435 classitem, numclasses, name, data, type
436 getClass(), getProjection(), getExtent(), getMetaData(),
437 getFirstMetaDataKey(), getNextMetaDataKey(), status,
438
439
440 The following paramters and functions are not used:
441 index, map, header, footer, template, groupe, tolerance,
442 toleranceunits, symbolscale, minscale, maxscale, labelminscale
443 labelmaxscale, sizeunits, maxfeatures, offsite, transform, labelcache
444 postlabelcache, labelitem, labelsizeitem, labelangleitem, labelitemindex
445 labelsizeitemindex, labelangleitemindex, tileitem, tileindex, units
446 connection, connectiontype, numitems, filteritem, styleitem, requires
447 labelrequires, transparency, dump, debug, numprocessing, numjoins,
448 removeClass(), open(), close(), getShape(), getNumResults(), getResult()
449 getItem(), promote(), demote(), draw(), drawQuery(), queryByAttributes()
450 queryByPoint(), queryByRect(), queryByFeatures(), queryByShape(),
451 setFilter(), setFilterString(), setWKTProjection(), setProjection()
452 addFeature(), getNumFeatures(), setMetaData(), removeMetaData(),
453 getWMSFeatureInfoURL(), executeWFSGetFeature(), applySLD(), applySLDURL()
454 enerateSLD(), moveClassUp(), moveClassDown(), setProcessing(),
455 getProcessing(), clearProcessing()
456 """
457
458 def __init__(self, mf_layer):
459 """
460 Creates the Layer Object from the mapscript Layer Object.
461 the class objects in the layer object will be stored in
462 an array. The metadata are created as a new object.
463 """
464
465 self._mf_layer = mf_layer
466
467 # Create Classes
468 # there could be more then 1
469 self._numclasses = mf_layer.numclasses
470 i = -1
471 self._classes = []
472 while i < self._numclasses-1:
473 i += 1
474 self._classes.append(MF_Class(self._mf_layer.getClass(i)))
475
476 self._projection = MF_Projection(self._mf_layer.getProjection())
477
478 # Variable extent will not used for RasterLayer
479 # this variable is not necessary, because it comes directly
480 # from the shp file
481 try:
482 self._extent = MF_Rectangle(self._mf_layer.getExtent())
483 except:
484 self._extent = None
485
486 # Create Metadata
487 self._metadata = MF_Metadata()
488 try:
489 self._metafkey = self._mf_layer.getFirstMetaDataKey()
490 except:
491 self._metadata = None
492 else:
493 while self._metafkey:
494 self._metakeydata = self._mf_layer.getMetaData(self._metafkey)
495 self._metadata.add_metadata(self._metafkey,self._metakeydata)
496 self._metafkey = self._mf_layer.getNextMetaDataKey(self._metafkey)
497
498 def get_name(self):
499 return self._mf_layer.name
500
501 def get_data(self):
502 return self._mf_layer.data
503
504 def get_classes(self):
505 return self._classes
506
507 def get_type(self):
508 return shp_type[self._mf_layer.type]
509
510 def get_classitem(self):
511 return self._mf_layer.classitem
512
513 def get_projection(self):
514 return self._projection
515
516 def get_status(self):
517 # returns a integer value
518 # 0 = off, 1 = on, 2 = default(always on)
519 if self._mf_layer.status == 0:
520 return False
521 else:
522 return True
523 #return self._mf_layer.status
524
525 def set_name(self, newname):
526 self._mf_layer.name = newname
527
528 def set_data(self, newdata, type="shape"):
529 if type == "raster":
530 self._mf_layer.data = newdata
531 else:
532 self._mf_layer.data = newdata[:-4]
533
534
535 def set_status(self, newstatus):
536 # status can set to true or false from thuban.
537 # but mapserver supports the default value
538 self._mf_layer.status = newstatus
539
540 def set_classitem(self, tb_field):
541 self._mf_layer.classitem = tb_field
542
543 def set_type(self, tb_type):
544 # if type = arc its a in shapetype line
545 if tb_type == "arc":
546 self._mf_layer.type = 1
547 if tb_type == "raster":
548 self._mf_layer.type = 3
549 if shp_type.has_key(tb_type):
550 self._mf_layer.type = tb_type
551 else:
552 for shp_paar_nr in shp_type:
553 if shp_type[shp_paar_nr] == tb_type:
554 self._mf_layer.type = shp_paar_nr
555 return
556
557 def set_projection(self, newprojection):
558 self._mfnewprojstring = ""
559 if newprojection:
560 self._newparams = newprojection.GetAllParameters()
561 for field in self._newparams:
562 self._mfnewprojstring = self._mfnewprojstring+ "," + field
563 self._mf_layer.setProjection(self._mfnewprojstring[1:])
564 self._projection.set_projection(newprojection)
565
566 def add_thubanclass(self, tb_class, type=""):
567 """
568 Add a thuban class object
569 """
570 new_class = MF_Class(classObj(self._mf_layer))
571 new_class.set_name(tb_class.GetLabel())
572 if self.get_type() == "line":
573 new_class.add_thubanstyle(tb_class.GetProperties(), type="line")
574 elif self.get_type() == "point":
575 new_class.add_thubanstyle(tb_class.GetProperties(), type="point")
576 else:
577 new_class.add_thubanstyle(tb_class.GetProperties())
578 if (type == "default"):
579 return
580 elif (tb_class.Matches("DEFAULT")):
581 new_class.set_expressionstring('/./')
582 else:
583 new_class.set_expressionstring(str(tb_class.GetValue()))
584 new_class.set_status(tb_class.IsVisible())
585 self._classes.append(new_class)
586
587 class MF_Scalebar:
588 """
589 The following settings are (not) used:
590 imagecolor, height, width, style, intervals, label, color, backgroundcolor,
591 outlinecolor, units, status, position, postlabelcache
592 """
593 def __init__(self, mf_scalebar):
594 self._scalebar = mf_scalebar
595 self._color = MF_Color(self._scalebar.color)
596 self._imagecolor = MF_Color(self._scalebar.imagecolor)
597 self._label = MF_Label(self._scalebar.label)
598
599 def get_label(self):
600 return self._label
601
602 def get_color(self):
603 return self._color
604
605 def get_imagecolor(self):
606 return self._imagecolor
607
608 def get_style(self):
609 return self._scalebar.style
610
611 def set_style(self, new_style):
612 self._scalebar.style = new_style
613
614 def get_size(self):
615 #returns the size
616 return (self._scalebar.width, self._scalebar.height)
617
618 def set_size(self, new_width, new_height):
619 self._scalebar.width = new_width
620 self._scalebar.height = new_height
621
622 def get_intervals(self):
623 return self._scalebar.intervals
624
625 def set_intervals(self, new_intervals):
626 self._scalebar.intervals = new_intervals
627
628 def get_units(self):
629 #returns the unittype
630 return unit_type[self._scalebar.units]
631
632 def set_units(self, units):
633 if unit_type.has_key(units):
634 self._scalebar.units = units
635 else:
636 for unit_paar_nr in unit_type:
637 if unit_type[unit_paar_nr] == units:
638 self._scalebar.units = unit_paar_nr
639
640 def get_status(self, art="integer"):
641 if art == "string":
642 return scalebar_status_type[self._scalebar.status]
643 else:
644 return self._scalebar.status
645
646 def set_status(self, new_status):
647 if scalebar_status_type.has_key(new_status):
648 self._scalebar.status = new_status
649 else:
650 for scalebar_status_type_nr in scalebar_status_type:
651 if scalebar_status_type[scalebar_status_type_nr] == new_status:
652 self._scalebar.status = scalebar_status_type_nr
653
654 def get_position(self, art="integer"):
655 if art == "string":
656 return scalebar_position_type[self._scalebar.position]
657 else:
658 return self._scalebar.position
659
660 def set_position(self, new_position):
661 if scalebar_position_type.has_key(new_position):
662 self._scalebar.position = new_position
663 else:
664 for scalebar_position_type_nr in legend_position_type:
665 if scalebar_position_type[scalebar_position_type_nr] == new_position:
666 self._scalebar.position = scalebar_position_type_nr
667
668 class MF_Map:
669 """
670 The following parameters and functions, which the mapscript style obj
671 contains, are used:
672
673 name, numlayers, extent, shapepath, imagecolor, imagetype, units, getLayer,
674 status, getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey,
675 save(), setExtent(), height, width, setProjection()
676
677
678 The following parameters and functions are not used:
679 maxsize, layers, symbolset, fontset, labelcache,
680 transparent, interlace, imagequality, cellsize, debug, datapattern,
681 templatepattern, configoptions
682 zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(),
683 clone(), removeLayer(), getLayerByName(), getSymbolByName(),
684 prepareQuery(), prepareImage(), setImageType(), setOutputFormat(), draw(),
685 drawQuery(), drawLegend(), drawScalebar(), embedLegend(), drawLabelCache(),
686 nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(), queryByShape(),
687 setWKTProjection(), saveQuery(), saveQueryASGML(),
688 setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(), setFontSet(),
689 saveMapContext(), loadMapContext(), moveLayerUp(), moveLayerDown(),
690 getLayersDrawingOrder(), setLayersDrawingOrder(), setConfigOption(),
691 getConfigOption(), applyConfigOptions(), applySLD(), applySLDURL(), gernerateSLD(),
692 procecssTemplate(), processLegemdTemplate(), processQueryTemplate(),
693 getOutputFormatByName(), appendOutputFormat(), removeOutputFormat(),
694 """
695
696 def __init__(self, mf_map):
697 """
698 Create the map object from the mapfile mapobject which is given.
699
700 All layers in the mapfile will be written to an array.
701 """
702
703 self._mf_map = mf_map
704 self._extent = MF_Rectangle(self._mf_map.extent)
705 self._imagecolor = MF_Color(self._mf_map.imagecolor)
706 self._web = MF_Web(self._mf_map.web)
707 self._legend = MF_Legend(self._mf_map.legend)
708 self._scalebar = MF_Scalebar(self._mf_map.scalebar)
709
710 # symbols
711 self._symbolset = MF_SymbolSet(self._mf_map.symbolset)
712
713 # if the map name is not set it will return a MS string.
714 if self._mf_map.name != "MS":
715 self._name = self._mf_map.name
716 else:
717 self._name = None
718
719 self._projection = MF_Projection(self._mf_map.getProjection())
720
721 # Initial Layer List
722 self._layers = []
723 self._numlayers = self._mf_map.numlayers
724 self._i = 0
725 while self._i < self._numlayers:
726 self._layers.append(MF_Layer(self._mf_map.getLayer(self._i)))
727 self._i += 1
728
729 # Shapepath if not set, shapepath will be empty
730 if self._mf_map.shapepath:
731 self._shapepath = self._mf_map.shapepath
732 else:
733 self._shapepath = ""
734
735 # Create Metadata
736 self._metadata = MF_Metadata()
737 try:
738 self._metafkey = self._mf_map.getFirstMetaDataKey()
739 except:
740 self._metadata = None
741 else:
742 while self._metafkey:
743 self._metakeydata = self._mf_map.getMetaData(self._metafkey)
744 self._metadata.add_metadata(self._metafkey,self._metakeydata)
745 self._metafkey = self._mf_map.getNextMetaDataKey(self._metafkey)
746
747 def get_symbolset(self):
748 return self._symbolset
749
750 def get_status(self):
751 if layer_status_type[self._mf_map.status] == "OFF":
752 return false
753 else:
754 return true
755
756 def get_scalebar(self):
757 return self._scalebar
758
759 def get_web(self):
760 return self._web
761
762 def get_legend(self):
763 return self._legend
764
765 def get_extent(self):
766 return self._extent
767
768 def get_layers(self):
769 return self._layers
770
771 def get_projection(self):
772 return self._projection
773
774 def get_name(self):
775 return self._name
776
777 def get_shapepath(self):
778 return self._shapepath # where are the shape files located..
779
780 def get_imagetype(self):
781 return self._imagetype
782
783 def get_layerorder(self):
784 # shows the order of layer as list
785 return self._mf_map.getLayerOrder()
786
787 def get_size(self):
788 #returns the size
789 return (self._mf_map.width, self._mf_map.height)
790
791 def get_units(self):
792 #returns the unittype
793 return unit_type[self._mf_map.units]
794
795 def get_imagecolor(self):
796 return self._imagecolor
797
798 def set_name(self, newname):
799 # whitespace musst be replaced, either no
800 # mapfile will be shown in the mapserver
801 newname = newname.replace(" ","_")
802 self._name = newname
803 self._mf_map.name = newname
804
805 def set_extent(self, newextent):
806 # TODO: add the shown extend here instead of the total
807 self._newrect = MF_Rectangle(rectObj())
808 try:
809 self._newrect.set_rect(newextent[0],newextent[1],newextent[2],newextent[3])
810 self._mf_map.setExtent(newextent[0],newextent[1],newextent[2],newextent[3])
811 except:
812 return
813
814 def set_size(self, newwidth, newheight):
815 self._mf_map.width = newwidth
816 self._mf_map.height = newheight
817
818 def set_projection(self, projection):
819 self._mfnewprojstring = ""
820 self._newparams = projection.GetAllParameters()
821 for field in self._newparams:
822 self._mfnewprojstring = self._mfnewprojstring+ "," + field
823 self._mf_map.setProjection(self._mfnewprojstring[1:])
824 self._projection.set_projection(projection)
825
826 def set_units(self, units):
827 if unit_type.has_key(units):
828 self._mf_map.units = units
829 else:
830 for unit_paar_nr in unit_type:
831 if unit_type[unit_paar_nr] == units:
832 self._mf_map.units = unit_paar_nr
833
834 def add_thubanlayer(self, tb_layer):
835 """
836 Add a thuban layer
837 """
838 new_layer = MF_Layer(layerObj(self._mf_map))
839 new_layer.set_name(tb_layer.Title())
840
841 # TODO: implement relative pathnames
842 # yet only absolute pathnames in the LayerObj are set
843 try:
844 new_layer.set_data(tb_layer.ShapeStore().FileName())
845 except:
846 new_layer.set_data(tb_layer.GetImageFilename(), type="raster")
847 new_layer.set_type("raster")
848 new_layer.set_status(tb_layer.Visible())
849 else:
850 new_layer.set_status(tb_layer.Visible())
851 new_layer.set_type(tb_layer.ShapeType())
852
853 if tb_layer.GetClassificationColumn():
854 new_layer.set_classitem(tb_layer.GetClassificationColumn())
855 if tb_layer.GetProjection():
856 new_layer.set_projection(tb_layer.GetProjection())
857 if tb_layer.GetClassification().GetNumGroups() > 0:
858 for group in range(0, tb_layer.GetClassification().GetNumGroups(), 1):
859 new_layer.add_thubanclass(tb_layer.GetClassification().GetGroup(group))
860 new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
861 else:
862 new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup(), type="default")
863
864 # set the projection to the layer.
865 # if the layer has its own definition use is, else use the main projection
866 if tb_layer.GetProjection():
867 new_layer.set_projection(tb_layer.GetProjection())
868 else:
869 new_layer.set_projection(self._projection.get_projection())
870 self._layers.append(new_layer)
871
872 def remove_layer(self, nr):
873 self._mf_map.removeLayer(nr)
874 self._numlayers -= 1
875 self._layers.remove(self._layers[nr])
876
877 def save_map(self, filepath):
878 # save the Map
879 # maybe an own saver can implement here
880 self._mf_map.save(filepath)
881
882
883 class MF_Web:
884 """
885 Save the Web settings
886
887 The following parametes are used:
888 imagepath, imageurl
889
890 The following parameters are not used:
891 log, map, template, queryformat, header, footer, empty, error, extent,
892 minscale, maxscale, mintemplate, maxtemplate
893 """
894 def __init__(self, mf_web):
895 self._mf_web = mf_web
896
897 def get_imagepath(self):
898 return self._mf_web.imagepath
899
900 def set_imagepath(self, new_imagepath):
901 self._mf_web.imagepath = new_imagepath
902
903 def get_imageurl(self):
904 return self._mf_web.imageurl
905
906 def set_imageurl(self, new_imageurl):
907 self._mf_web.imagepath = new_imageurl
908
909 def get_queryformat(self):
910 return self._mf_web.queryformat
911
912 def set_queryformat(self, new_queryformat):
913 self._mf_web.imagepath = new_queryformat
914
915
916 class MF_Label:
917 """
918 The following parameters from mapscript are used:
919 type, color, size, offsetx, offsety,
920
921 The following parameters are not used:
922 font, outlinecolor, shadowcolor, shadowsizex, shadowsizey,
923 backgroundcolor, backgroundshadowcolor, backgroundshadowsizex,
924 backgroundshadowsizey, sizescaled, minsize, maxsize, position, angle,
925 autoangle, buffer, antialias, wrap, minfeaturesize,
926 autominfeaturesize, mindistance, partials, force
927 """
928 def __init__(self, mf_label):
929 """
930 Create a legend obj from the existing mapfile
931 """
932 self._label = mf_label
933 self._color = MF_Color(self._label.color)
934
935 def get_size(self):
936 return self._label.size
937
938 def set_size(self, new_size):
939 if label_size_type.has_key(new_size):
940 self._label.size = new_size
941 for label_size_type_nr in label_size_type:
942 if label_size_type[label_size_type_nr] == new_size:
943 self._label.size = label_size_type_nr
944 else:
945 self._label.size = new_size
946
947 def get_color(self):
948 return self._color
949
950 def get_partials(self):
951 if self._label.partials == 1:
952 return True
953 else:
954 return False
955
956 def set_partials(self, new_partials):
957 # if partials = True
958 if new_partials:
959 self._label.partials = 1
960 elif new_partials == False:
961 self._label.partials = 0
962 else:
963 print "Boolean exspected"
964
965 def get_type(self):
966 return label_font_type[self._label.type]
967
968 def set_type(self, new_type):
969 if label_font_type.has_key(new_type):
970 self._label.type = new_type
971 else:
972 for label_font_type_nr in label_font_type:
973 if label_font_type[label_font_type_nr] == new_type:
974 self._label.type = label_font_type_nr
975
976 def get_offset(self):
977 return (self._label.offsetx, self._label.offsety)
978
979 def set_offset(self, new_offsetx, new_offsety):
980 self._label.offsetx = new_offsetx
981 self._label.offsety = new_offsety
982
983
984 class MF_Legend:
985 """
986 The following parameters are (not) used:
987 imagecolor, label, keysizex, keysizey, status, position,
988
989 The following parameters are not used:
990 keyspacingx, keyspacingy,
991 outlinecolor, height, width, postlabelcache, template, map
992 """
993 def __init__(self, mf_legend):
994 """
995 Create a legend obj from the existing mapfile
996 """
997 self._mf_legend = mf_legend
998 self._imagecolor = MF_Color(self._mf_legend.imagecolor)
999 self._label = MF_Label(self._mf_legend.label)
1000
1001 def get_imagecolor(self):
1002 return self._imagecolor
1003
1004 def get_label(self):
1005 return self._label
1006
1007 def get_keysize(self):
1008 return (self._mf_legend.keysizex, self._mf_legend.keysizey)
1009
1010 def set_keysize(self, new_keysizex, new_keysizey):
1011 self._mf_legend.keysizex = new_keysizex
1012 self._mf_legend.keysizey = new_keysizey
1013
1014 def get_keyspacing(self):
1015 return (self._mf_legend.keyspacingx, self._mf_legend.keyspacingy)
1016
1017 def set_keyspacing(self, new_keyspacingx, new_keyspacingy):
1018 self._mf_legend.keyspacingx = new_keyspacingx
1019 self._mf_legend.keyspacingy = new_keyspacingy
1020
1021 def get_status(self, art="integer"):
1022 if art == "string":
1023 return legend_status_type[self._mf_legend.status]
1024 else:
1025 return self._mf_legend.status
1026
1027 def set_status(self, new_status):
1028 if legend_status_type.has_key(new_status):
1029 self._mf_legend.status = new_status
1030 else:
1031 for legend_status_type_nr in legend_status_type:
1032 if legend_status_type[legend_status_type_nr] == new_status:
1033 self._mf_legend.status = legend_status_type_nr
1034
1035 def get_position(self, art="integer"):
1036 if art == "string":
1037 return legend_position_type[self._mf_legend.position]
1038 else:
1039 return self._mf_legend.position
1040
1041 def set_position(self, new_position):
1042 if legend_position_type.has_key(new_position):
1043 self._mf_legend.position = new_position
1044 else:
1045 for legend_position_type_nr in legend_position_type:
1046 if legend_position_type[legend_position_type_nr] == new_position:
1047 self._mf_legend.position = legend_position_type_nr
1048
1049 class MF_Projection:
1050 """
1051 The following parameter, which the mapscript style obj contains is used:
1052
1053 numargs
1054 """
1055
1056 def __init__(self, mf_projection):
1057 """
1058 Create a projection object from the given mapscript projection
1059 object. If it is a epsg code the extracted from the string
1060 (e.g."init=epsg:xxxx"), else the projection parameters will
1061 be splitted and an array with the parameters will be creaded.
1062 """
1063 self._mfprojstring = mf_projection
1064 self._projstring = self._mfprojstring
1065 self._epsgcode = None
1066 self._params = None
1067 if self._mfprojstring:
1068 if self._mfprojstring.find("init=epsg:") != -1:
1069 self._initcode, self._epsgcode = self._mfprojstring.split(':')
1070 else:
1071 self._params = []
1072 self._params = self._mfprojstring.split("+")
1073 if self._params[0] == "":
1074 self._params.remove("")
1075
1076 def epsg_code_to_projection(self, epsg):
1077 """
1078 Find the projection for the given epsg code.
1079
1080 Copied from Extension/wms/layer.py
1081
1082 epsg -- EPSG code as string
1083 """
1084 #Needed only for this function
1085 from Thuban.Model.resource import get_system_proj_file, EPSG_PROJ_FILE, \
1086 EPSG_DEPRECATED_PROJ_FILE
1087
1088 proj_file, warnings = get_system_proj_file(EPSG_PROJ_FILE)
1089
1090 for proj in proj_file.GetProjections():
1091 if proj.EPSGCode() == epsg:
1092 return proj
1093
1094 proj_file, warnings = get_system_proj_file(EPSG_DEPRECATED_PROJ_FILE)
1095 for proj in proj_file.GetProjections():
1096 if proj.EPSGCode() == epsg:
1097 return proj
1098 return None
1099
1100 def get_params(self):
1101 #Parameter from the mf_projectionstring as Array
1102 return self._params
1103
1104 def get_epsgcode(self):
1105 # returnes the epsg number
1106 return self._epsgcode
1107
1108 def get_epsgproj(self):
1109 # get an epsg projectionobject
1110 return self.epsg_code_to_projection(self._epsgcode)
1111
1112 def get_projection(self):
1113 return self._projstring
1114
1115 def set_projection(self, newprojection):
1116 self._projstring = newprojection
1117 self._params = newprojection.GetAllParameters()
1118 self._mfnewprojstring = ""
1119 for field in self._params:
1120 self._mfnewprojstring = self._mfnewprojstring+ "+" + field
1121 self._mfprojstring = self._mfnewprojstring
1122
1123
1124 class MF_Style:
1125 """
1126 The following parameters, which the mapscript style obj
1127 contains, are used:
1128 color, backgroundcolor, outlinecolor, size, symbolname
1129
1130 The following are not used:
1131 symbol, sizescaled, minsize, maxsize, offsetx, offsety,
1132 antialias
1133 """
1134
1135 def __init__(self, mf_style):
1136 """
1137 Create a style object from the given mapscript style object.
1138 The color Object from the color and the outlinecolor parameter
1139 will be created. if the color (red, green or blue) is -1 there
1140 is no definition in the mapfile and so there is no color object,
1141 it will set to 'None'.
1142 """
1143 self._style = mf_style
1144 if self._style.color.red == -1:
1145 self._color = None
1146 else:
1147 self._color = MF_Color(self._style.color)
1148 if self._style.outlinecolor.red == -1:
1149 self._outlinecolor = None
1150 else:
1151 self._outlinecolor = MF_Color(self._style.outlinecolor)
1152
1153 def get_color(self):
1154 return self._color
1155
1156 def get_outlinecolor(self):
1157 return self._outlinecolor
1158
1159 def get_size(self):
1160 return self._style.size
1161
1162 def set_linecolor(self, tb_color):
1163 self._color = tb_color
1164 new_linecolor = MF_Color(colorObj())
1165 new_linecolor.set_thubancolor(tb_color)
1166 self._outlinecolor = new_linecolor
1167 self._style.outlinecolor = new_linecolor.get_mfcolor()
1168
1169 def set_color(self, tb_color):
1170 self._color = tb_color
1171 new_color = MF_Color(colorObj())
1172 new_color.set_thubancolor(tb_color)
1173 self._color = new_color
1174 self._style.color = new_color.get_mfcolor()
1175
1176 def set_size(self, newsize):
1177 self._style.size = newsize
1178
1179 def set_symbolname(self, newsymbol):
1180 # its possible to use stringnames instead of numbers
1181 self._style.symbolname = newsymbol
1182

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26