/[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 2252 - (hide annotations)
Wed Jun 23 12:39:52 2004 UTC (20 years, 8 months ago) by jschuengel
File MIME type: text/x-python
File size: 25635 byte(s)
Expand the classes to use with the export module. Especially added the possibility to add thuban objects directly to the map objects.

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     labelCacheMemberObj, labelCacheObj, labelObj, legendObj, lineObj,
17     markerCacheMembet, msTiledSHPLayerInfo, OutputFormat, pointObj, queryMapObj,
18     referenzMapObj, resultCacheMemberObj, resultCacheObj, scalebarObj,
19     shapefileObj, shapeObj, styleObj, symbolObj, symbolSetObj, 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 jschuengel 2252 import os
34 jschuengel 2235
35 jschuengel 2252 from Thuban.Model.color import Color, Transparent
36 jschuengel 2235
37 jschuengel 2252 from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, \
38     colorObj
39    
40 jschuengel 2235 # ###################################
41     #
42     # Definition of dictionaries
43     #
44     # ###################################
45    
46     shp_type = { 0:'point',
47     1:'line',
48     2:'polygon',
49     3:'raster',
50     4:'annotation',
51     5:'circle',
52     6:'query'}
53    
54    
55    
56     # ##################################################
57     #
58     # Class Definition
59     #
60     # ##################################################
61    
62     # ##################################################
63 jschuengel 2252 # General Classes that are not all explicitly defined through
64 jschuengel 2235 # a mapfile, but rather some helper-classes.
65    
66     class MF_Rectangle:
67     """
68     Represents an rectanle with the bottom left
69     and top right corner.
70     """
71     def __init__(self,mf_rect):
72     self._rect = mf_rect
73    
74     def get_minx(self):
75     return self._rect.minx
76    
77     def get_miny(self):
78     return self._rect.miny
79    
80     def get_maxx(self):
81     return self._rect.maxx
82    
83     def get_maxy(self):
84     return self._rect.maxy
85 jschuengel 2252
86     def get_rect(self):
87     return (self._rect.minx,self._rect.miny,self._rect.maxx,self._rect.maxy)
88 jschuengel 2235
89 jschuengel 2252 def set_rect(self, minx, miny, maxx, maxy):
90     self._rect.minx = minx
91     self._rect.miny = miny
92     self._rect.maxx = maxx
93     self._rect.maxy = maxy
94 jschuengel 2235
95     class MF_Color:
96     """
97     The corresponding MapScript object contains also the
98     attribute pen which defines the stroke of the feature.
99     But this actually has nothing to do with the color and
100     therefore is not support here.
101    
102     It needs to be discussed with the MapServer developers
103     whether pen would better be moved to another class.
104    
105     The hex color definition which is also supported by
106     mapscript and Thuban is not supported as it does
107     not add any capability.
108    
109     color is definied as RGB 0..255
110 jschuengel 2252 """
111 jschuengel 2235 def __init__(self, mf_color):
112     self._color = mf_color
113    
114     self._tbc_red = (float(self.get_red())/255)
115     self._tbc_green = (float(self.get_green())/255)
116     self._tbc_blue = (float(self.get_blue())/255)
117     self._thubancolor = Color(self._tbc_red, self._tbc_green, self._tbc_blue)
118    
119     # TODO : Check if it is necessary to use rgb colors alone
120     # or whether it is sufficient to only use the Thuban Color.
121     # In some it is necessary as red == -1 indicates that no color
122     # is set.
123     def get_red(self):
124     return self._color.red
125    
126     def get_green(self):
127     return self._color.green
128    
129     def get_blue(self):
130     return self._color.blue
131 jschuengel 2252
132     def get_mfcolor(self):
133     return self._color
134 jschuengel 2235
135     def get_thubancolor(self):
136 jschuengel 2252 return self._thubancolor
137 jschuengel 2235
138     def set_thubancolor(self, thuban_color):
139 jschuengel 2252 if thuban_color != Transparent:
140     self._color.red = int(thuban_color.red * 255)
141     self._color.green = int(thuban_color.green * 255)
142     self._color.blue = int(thuban_color.blue * 255)
143     self._thubancolor = thuban_color
144 jschuengel 2235
145    
146     class MF_Size:
147     """
148     Handle sizes.
149     This is not implemented as a Class in mapscript but
150     seems to be helpful.
151     """
152    
153     def __init__(self, mf_width, mf_height):
154     self._width = mf_width
155     self._height = mf_height
156    
157     def get_width(self):
158     return self._width
159    
160     def get_height(self):
161     return self._height
162 jschuengel 2252
163     def set_size(self, newwidth, newheight):
164     self._width = newwidth
165     self._height = newheight
166 jschuengel 2235
167    
168     class MF_Metadata:
169     """
170     Metadata is not a Object in mapscript witch can be used
171     by ease. Only the infos can get with the functions
172     "getFirstMetaDataKey", "getNextMetaDataKey" and "getMetaData".
173     To get some special Metadata you need a key. So the metadata will
174     saved as an dictionary to geht the information with the key here.
175    
176     The metadata obj will be created and filled with infos like
177     the following code sample:
178    
179     self.metadata = MF_Metadata()
180     try:
181     self.metafkey = varia.getFirstMetaDataKey()
182     except:
183     self.metadata = None
184     else:
185     while self.metafkey:
186     self.metakeydata = varia.getMetaData(self.metafkey)
187     self.metadata.add_metadata(self.metafkey,self.metakeydata)
188     self.metafkey = varia.getNextMetaDataKey(self.metafkey)
189    
190     Metadata are not really needed at the moment.
191     """
192    
193     def __init__(self):
194     self.data = {}
195    
196     def get_metadata(self):
197     return self.data
198    
199     def get_metadatabykey(self, key):
200     return self.data[key]
201    
202     def add_metadata(self, key, data):
203     self.data[key] = data
204    
205     # ##################################################
206     # Classes for MapServer Objects as they are
207 jschuengel 2252 # explicitly defined in a mapfile
208 jschuengel 2235
209 jschuengel 2252 class MF_Symbol:
210     """
211     defines a single symbol which is used in the Symbolset
212    
213     name, type, sizex, sizey, points, numpoints, filled, stylelength,
214     style, imagepath, transparent, transparentcolor, character, antialias,
215     font, gap, position, linecap, linejoin, linejoinmaxsize, setPoints(),
216     getPoints(), setStyle()
217     """
218    
219     def __init__(self, mf_symbol):
220     print "nothing"
221    
222     class MF_SymbolSet:
223     """
224     defines a set of symbols, may be there can only be one
225    
226     filename, imagecachesize, numsymbols, symbol, getSymbol(),
227     getSymbolByName(), index(), appendSymbol(), removeSymbol(),
228     save()
229     """
230    
231     # TODO: include the symbolset, but found only the possibility to
232     # create an extra symbol file and not to include it direct to the
233     # mapfile itself
234     def __init__(self, mf_symbolset):
235     print "nothing"
236    
237    
238 jschuengel 2235 class MF_Class:
239     """
240     The following parameters and functions, which the mapscript style obj
241     contains, are used:
242     styles, numstyles, name,
243 jschuengel 2252 getExpressionString(), setExpression(), getMetaData(), getFirstMetaDataKey(),
244 jschuengel 2235 getNextMetaDataKey(), getStyle()
245    
246     The following parameters and functions are not used:
247     status, label, title, template, type, minscale, maxscale, layer,
248     debig, keyimage,
249     setExpression(), setText(), setMetaData(), drawLegendIcon(),
250     createLegendIcon(), insertStyle(), removeStyle(), moveStyleUp(),
251     moveStyleDown()
252     """
253     def __init__(self, mf_class):
254     """
255     Initialized a class from them given mapscript Class Object
256     with a list of the included styles.
257     Metadata Object will be created from the Metadata informations
258     wich are holt as a List i think.
259     """
260     self._clazz = mf_class
261     self._styles = []
262     self._numstyles = mf_class.numstyles
263     for i in range(0,self._numstyles,1):
264     self._styles.append(MF_Style(mf_class.getStyle(i)))
265    
266     if self._clazz.getExpressionString() == '"(null)"':
267     self._expression = None
268     else:
269     self._expression = self._clazz.getExpressionString()
270    
271     self.metadata = MF_Metadata()
272     try:
273     self.metafkey = mf_class.getFirstMetaDataKey()
274     except:
275     self.metadata = None
276     else:
277     while self.metafkey:
278     self.metakeydata = mf_class.getMetaData(self.metafkey)
279     self.metadata.add_metadata(self.metafkey,self.metakeydata)
280     self.metafkey = mf_class.getNextMetaDataKey(self.metafkey)
281    
282     def get_styles(self):
283     return self._styles
284    
285     def get_name(self):
286     return self._clazz.name
287    
288     def get_keyimage(self):
289     return self._clazz.keyimage
290    
291     def get_expressionstring(self):
292     return self._expression
293 jschuengel 2252
294     def set_name(self, newname):
295     self._clazz.name = newname
296    
297     def set_expressionstring(self, newstring):
298     self._clazz.setExpression(newstring)
299     self._expression = self._clazz.getExpressionString()
300    
301     def add_thubanstyle(self, tb_style, type="default"):
302     new_styleobj = MF_Style(styleObj(self._clazz))
303     if type == "line":
304     new_styleobj.set_color(tb_style.GetLineColor())
305     elif type == "circle":
306     # set a default symbol to show circles not only a small dot
307     # symbol "circle" must create before
308     # TODO: create a Symbol (more see MF_SymbolSet)
309     new_styleobj.set_symbol('circle')
310     else:
311     new_styleobj.set_size(tb_style.GetLineWidth())
312     new_styleobj.set_linecolor(tb_style.GetLineColor())
313     new_styleobj.set_color(tb_style.GetFill())
314 jschuengel 2235
315    
316     class MF_Layer:
317     """
318     The following parameters and functions, which the mapscript style obj
319     contains, are used:
320    
321     classitem, numclasses, name, data, type
322     getClass(), getProjection(), getExtent(), getMetaData(),
323 jschuengel 2252 getFirstMetaDataKey(), getNextMetaDataKey(), status,
324 jschuengel 2235
325    
326     The following paramters and functions are not used:
327 jschuengel 2252 index, map, header, footer, template, groupe, tolerance,
328 jschuengel 2235 toleranceunits, symbolscale, minscale, maxscale, labelminscale
329     labelmaxscale, sizeunits, maxfeatures, offsite, transform, labelcache
330     postlabelcache, labelitem, labelsizeitem, labelangleitem, labelitemindex
331     labelsizeitemindex, labelangleitemindex, tileitem, tileindex, units
332     connection, connectiontype, numitems, filteritem, styleitem, requires
333     labelrequires, transparency, dump, debug, numprocessing, numjoins,
334     removeClass(), open(), close(), getShape(), getNumResults(), getResult()
335     getItem(), promote(), demote(), draw(), drawQuery(), queryByAttributes()
336     queryByPoint(), queryByRect(), queryByFeatures(), queryByShape(),
337     setFilter(), setFilterString(), setWKTProjection(), setProjection()
338     addFeature(), getNumFeatures(), setMetaData(), removeMetaData(),
339     getWMSFeatureInfoURL(), executeWFSGetFeature(), applySLD(), applySLDURL()
340     enerateSLD(), moveClassUp(), moveClassDown(), setProcessing(),
341     getProcessing(), clearProcessing()
342     """
343    
344     def __init__(self, mf_layer):
345     """
346     Creates the Layer Object from the mapscript Layer Object.
347     the class objects in the layer object will be stored in
348     an array. The metadata are created as a new object.
349     """
350    
351     self._mf_layer = mf_layer
352    
353     # Create Classes
354     # there could be more then 1
355     self._numclasses = mf_layer.numclasses
356     i = -1
357     self._classes = []
358     while i < self._numclasses-1:
359     i += 1
360     self._classes.append(MF_Class(self._mf_layer.getClass(i)))
361    
362     self._projection = MF_Projection(self._mf_layer.getProjection())
363    
364     # Variable extent will not used for RasterLayer
365     # this variable is not necessary, because it comes directly
366     # from the shp file
367     try:
368     self._extent = MF_Rectangle(self._mf_layer.getExtent())
369     except:
370     self._extent = None
371    
372     # Create Metadata
373     self._metadata = MF_Metadata()
374     try:
375     self._metafkey = self._mf_layer.getFirstMetaDataKey()
376     except:
377     self._metadata = None
378     else:
379     while self._metafkey:
380     self._metakeydata = self._mf_layer.getMetaData(self._metafkey)
381     self._metadata.add_metadata(self._metafkey,self._metakeydata)
382     self._metafkey = self._mf_layer.getNextMetaDataKey(self._metafkey)
383    
384     def get_name(self):
385     return self._mf_layer.name
386    
387     def get_data(self):
388     return self._mf_layer.data
389    
390     def get_classes(self):
391     return self._classes
392    
393     def get_type(self):
394     return shp_type[self._mf_layer.type]
395    
396     def get_classitem(self):
397     return self._mf_layer.classitem
398    
399     def get_projection(self):
400     return self._projection
401 jschuengel 2252
402     def get_status(self):
403     # returns a integer value
404     # 0 = off, 1 = on, 2 = default(always on)
405     if self._mf_layer.status == 0:
406     return False
407     else:
408     return True
409     #return self._mf_layer.status
410    
411     def set_name(self, newname):
412     self._mf_layer.name = newname
413    
414     def set_data(self, newdata):
415     self._mf_layer.data = newdata[:-4]
416    
417     def set_status(self, newstatus):
418     # status can set to true or false from thuban.
419     # but mapserver supports the default value
420     self._mf_layer.status = newstatus
421    
422     def set_classitem(self, tb_field):
423     self._mf_layer.classitem = tb_field
424    
425     def set_type(self, tb_type):
426     # if type = arc its a in shapetype line
427     if tb_type == "arc":
428     self._mf_layer.type = 1
429     if shp_type.has_key(tb_type):
430     self._mf_layer.type = tb_type
431     else:
432     for shp_paar_nr in shp_type:
433     if shp_type[shp_paar_nr] == tb_type:
434     self._mf_layer.type = shp_paar_nr
435     return
436    
437     def set_projection(self, newprojection):
438     self._mfnewprojstring = ""
439     if newprojection:
440     self._newparams = newprojection.GetAllParameters()
441     for field in self._newparams:
442     self._mfnewprojstring = self._mfnewprojstring+ "," + field
443     self._mf_layer.setProjection(self._mfnewprojstring[1:])
444     self._projection.set_projection(newprojection)
445     else:
446     print "no projection"
447    
448     def add_thubanclass(self, tb_class):
449     new_class = MF_Class(classObj(self._mf_layer))
450     new_class.set_name(tb_class.GetLabel())
451     if self.get_type() == "line":
452     new_class.add_thubanstyle(tb_class.GetProperties(), type="line")
453     else:
454     new_class.add_thubanstyle(tb_class.GetProperties())
455     if tb_class.GetDisplayText() == "DEFAULT":
456     return
457     #new_class.set_expressionstring('/./')
458     else:
459     new_class.set_expressionstring(str(tb_class.GetDisplayText()))
460     self._classes.append(new_class)
461 jschuengel 2235
462     class MF_Map:
463     """
464     The following parameters and functions, which the mapscript style obj
465     contains, are used:
466    
467     name, numlayers, extent, shapepath, imagecolor, imagetype, getLayer,
468 jschuengel 2252 getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey,
469     save(), setExtent(), height, width, setProjection()
470 jschuengel 2235
471    
472     The following parameters and functions are not used:
473 jschuengel 2252 status, maxsize, layers, symbolset, fontset, labelcache,
474 jschuengel 2235 transparent, interlace, imagequality, cellsize, units, debug, datapattern,
475     templatepattern, configoptions
476     zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(),
477 jschuengel 2252 clone(), removeLayer(), getLayerByName(), getSymbolByName(),
478 jschuengel 2235 prepareQuery(), prepareImage(), setImageType(), setOutputFormat(), draw(),
479     drawQuery(), drawLegend(), drawScalebar(), embedLegend(), drawLabelCache(),
480     nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(), queryByShape(),
481 jschuengel 2252 setWKTProjection(), saveQuery(), saveQueryASGML(),
482 jschuengel 2235 setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(), setFontSet(),
483     saveMapContext(), loadMapContext(), moveLayerUp(), moveLayerDown(),
484     getLayersDrawingOrder(), setLayersDrawingOrder(), setConfigOption(),
485     getConfigOption(), applyConfigOptions(), applySLD(), applySLDURL(), gernerateSLD(),
486     procecssTemplate(), processLegemdTemplate(), processQueryTemplate(),
487     getOutputFormatByName(), appendOutputFormat(), removeOutputFormat(),
488     """
489    
490     def __init__(self, mf_map):
491     """
492 jschuengel 2252 Create the map object from the mapfile mapobject which is given.
493 jschuengel 2235
494     All layers in the mapfile will be written to an array.
495     """
496    
497     self._mf_map = mf_map
498     self._extent = MF_Rectangle(self._mf_map.extent)
499     self._imagecolor = MF_Color(self._mf_map.imagecolor)
500    
501     # if the map name is not set it will return a MS string.
502     if self._mf_map.name != "MS":
503     self._name = self._mf_map.name
504     else:
505     self._name = None
506    
507     self._projection = MF_Projection(self._mf_map.getProjection())
508    
509     # Initial Layer List
510     self._layers = []
511     self._numlayers = self._mf_map.numlayers
512     self._i = 0
513     while self._i < self._numlayers:
514     self._layers.append(MF_Layer(self._mf_map.getLayer(self._i)))
515     self._i += 1
516    
517     # Shapepath if not set, shapepath will be empty
518     if self._mf_map.shapepath:
519     self._shapepath = self._mf_map.shapepath
520     else:
521     self._shapepath = ""
522    
523     # Create Metadata
524     self._metadata = MF_Metadata()
525     try:
526     self._metafkey = self._mf_map.getFirstMetaDataKey()
527     except:
528     self._metadata = None
529     else:
530     while self._metafkey:
531     self._metakeydata = self._mf_map.getMetaData(self._metafkey)
532     self._metadata.add_metadata(self._metafkey,self._metakeydata)
533     self._metafkey = self._mf_map.getNextMetaDataKey(self._metafkey)
534 jschuengel 2252
535 jschuengel 2235 def get_extent(self):
536     return self._extent
537    
538     def get_layers(self):
539     return self._layers
540    
541     def get_projection(self):
542     return self._projection
543    
544     def get_name(self):
545     return self._name
546    
547     def get_shapepath(self):
548     return self._shapepath # where are the shape files located..
549    
550     def get_imagetype(self):
551     return self._imagetype
552 jschuengel 2252
553 jschuengel 2235 def get_layerorder(self):
554     # shows the order of layer as list
555     return self._mf_map.getLayerOrder()
556 jschuengel 2252
557     def set_name(self, newname):
558     # whitespace musst be replaced, either no
559     # mapfile will be shown in the mapserver
560     newname = newname.replace(" ","_")
561     self._name = newname
562     self._mf_map.name = newname
563    
564     def set_extent(self, newextent):
565     # TODO: add the shown extend here instead of the total
566     self._newrect = MF_Rectangle(rectObj())
567     self._newrect.set_rect(newextent[0],newextent[1],newextent[2],newextent[3])
568     self._mf_map.setExtent(newextent[0],newextent[1],newextent[2],newextent[3])
569    
570     def set_size(self, newwidth, newheight):
571     self._mf_map.width = newwidth
572     self._mf_map.height = newheight
573    
574     def set_projection(self, projection):
575     self._mfnewprojstring = ""
576     self._newparams = projection.GetAllParameters()
577     for field in self._newparams:
578     self._mfnewprojstring = self._mfnewprojstring+ "," + field
579     self._mf_map.setProjection(self._mfnewprojstring[1:])
580     self._projection.set_projection(projection)
581    
582     def add_thubanlayer(self, tb_layer):
583     new_layer = MF_Layer(layerObj(self._mf_map))
584     new_layer.set_name(tb_layer.Title())
585    
586     # TODO: implement relative pathnames
587     # yet only absolute pathnames in the LayerObj are set
588     new_layer.set_data(tb_layer.ShapeStore().FileName())
589    
590     new_layer.set_status(tb_layer.Visible())
591     new_layer.set_type(tb_layer.ShapeType())
592    
593     # set the projection to the layer.
594     # if the layer has its own definition use is, else use the main projection
595     if tb_layer.GetProjection():
596     new_layer.set_projection(tb_layer.GetProjection())
597     else:
598     new_layer.set_projection(self._projection.get_projection())
599    
600     if tb_layer.GetClassificationColumn():
601     new_layer.set_classitem(tb_layer.GetClassificationColumn())
602     if tb_layer.GetProjection():
603     new_layer.set_projection(tb_layer.GetProjection())
604     if tb_layer.GetClassification().GetNumGroups() > 0:
605     for group in range(0, tb_layer.GetClassification().GetNumGroups(), 1):
606     new_layer.add_thubanclass(tb_layer.GetClassification().GetGroup(group))
607     new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
608     else:
609     new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
610     self._layers.append(new_layer)
611    
612     def save_map(self, filepath):
613     # save the Map
614     # maybe an own saver can implement here
615     self._mf_map.save(filepath)
616    
617 jschuengel 2235 class MF_Projection:
618     """
619     The following parameter, which the mapscript style obj contains is used:
620    
621     numargs
622     """
623    
624     def __init__(self, mf_projection):
625     """
626     Create a projection object from the given mapscript projection
627     object. If it is a epsg code the extracted from the string
628     (e.g."init=epsg:xxxx"), else the projection parameters will
629     be splitted and an array with the parameters will be creaded.
630     """
631     self._mfprojstring = mf_projection
632 jschuengel 2252 self._projstring = self._mfprojstring
633 jschuengel 2235 self._epsgcode = None
634     self._params = None
635     if self._mfprojstring:
636     if self._mfprojstring.find("init=epsg:") != -1:
637     self._initcode, self._epsgcode = self._mfprojstring.split(':')
638     else:
639     self._params = []
640     self._params = self._mfprojstring.split("+")
641     if self._params[0] == "":
642     self._params.remove("")
643    
644     def epsg_code_to_projection(self, epsg):
645     """
646     Find the projection for the given epsg code.
647    
648     Copied from Extension/wms/layer.py
649    
650     epsg -- EPSG code as string
651     """
652     #Needed only for this function
653     from Thuban.Model.resource import get_system_proj_file, EPSG_PROJ_FILE, \
654     EPSG_DEPRECATED_PROJ_FILE
655    
656     proj_file, warnings = get_system_proj_file(EPSG_PROJ_FILE)
657    
658     for proj in proj_file.GetProjections():
659     if proj.EPSGCode() == epsg:
660     return proj
661    
662     proj_file, warnings = get_system_proj_file(EPSG_DEPRECATED_PROJ_FILE)
663     for proj in proj_file.GetProjections():
664     if proj.EPSGCode() == epsg:
665     return proj
666     return None
667    
668     def get_params(self):
669     #Parameter from the mf_projectionstring as Array
670     return self._params
671    
672     def get_epsgcode(self):
673     # returnes the epsg number
674     return self._epsgcode
675    
676     def get_epsgproj(self):
677     # get an epsg projectionobject
678     return self.epsg_code_to_projection(self._epsgcode)
679 jschuengel 2252
680     def get_projection(self):
681     return self._projstring
682    
683     def set_projection(self, newprojection):
684     self._projstring = newprojection
685     self._params = newprojection.GetAllParameters()
686     self._mfnewprojstring = ""
687     for field in self._params:
688     self._mfnewprojstring = self._mfnewprojstring+ "+" + field
689     self._mfprojstring = self._mfnewprojstring
690 jschuengel 2235
691     class MF_Style:
692     """
693     The following parameters, which the mapscript style obj
694     contains, are used:
695    
696 jschuengel 2252 color, backgroundcolor, outlinecolor, size, symbolname
697 jschuengel 2235
698     The following are not used:
699 jschuengel 2252 symbol, sizescaled, minsize, maxsize, offsetx, offsety,
700 jschuengel 2235 antialias
701     """
702    
703     def __init__(self, mf_style):
704     """
705     Create a style object from the given mapscript style object.
706     The color Object from the color and the outlinecolor parameter
707     will be created. if the color (red, green or blue) is -1 there
708     is no definition in the mapfile and so there is no color object,
709     it will set to 'None'.
710     """
711     self._style = mf_style
712     if self._style.color.red == -1:
713 jschuengel 2252 self._maincolor = None
714 jschuengel 2235 else:
715 jschuengel 2252 self._maincolor = MF_Color(self._style.color)
716     self._color = MF_Color(self._style.color)
717 jschuengel 2235 if self._style.outlinecolor.red == -1:
718     self._outlinecolor = None
719     else:
720     self._outlinecolor = MF_Color(self._style.outlinecolor)
721    
722     def get_color(self):
723     return self._color
724    
725     def get_outlinecolor(self):
726     return self._outlinecolor
727    
728     def get_size(self):
729     return self._style.size
730 jschuengel 2252
731     def set_linecolor(self, tb_color):
732     self._color = tb_color
733     new_linecolor = MF_Color(colorObj())
734     new_linecolor.set_thubancolor(tb_color)
735     self._outlinecolor = new_linecolor
736     self._style.outlinecolor = new_linecolor.get_mfcolor()
737    
738     def set_color(self, tb_color):
739     self._color = tb_color
740     new_color = MF_Color(colorObj())
741     new_color.set_thubancolor(tb_color)
742     self._color = new_color
743     self._style.color = new_color.get_mfcolor()
744    
745     def set_size(self, newsize):
746     self._style.size = newsize
747    
748     def set_symbolname(self, newsymbol):
749     # its possible to use stringnames instead of numbers
750     self._style.symbolname = 'circle'
751    

Properties

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26