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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2284 - (hide annotations)
Wed Jul 14 10:38:08 2004 UTC (20 years, 7 months ago) by jschuengel
File MIME type: text/x-python
File size: 47902 byte(s)
Added ClassGroupDefault to import.
(MF_Symbolset): Removed the extra variable for numsymbols.
(MF_Class.__init__): Added a comment to the exception clause.
Removed the extent init, because it was not needed anymore.
(MF_Layer.add_thubanclass): Added the code to set the class name to the expression value from thuban if no label is defined.
Added the code to export Range expressions from thuban to the mapfile.
(MF_Map.set_extent): Removed the exception and replace it by some if code. If the size of a map is not defined the size will be set to 1,1. This is necessary because if the extent is set, mapscript checks if the size is greater than zero.
(MF_Web): Added the get and set function for the template.

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

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26