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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2251 by jschuengel, Thu Jun 10 12:27:48 2004 UTC revision 2252 by jschuengel, Wed Jun 23 12:39:52 2004 UTC
# Line 30  __version__ = "$Revision$" Line 30  __version__ = "$Revision$"
30  #  #
31  # ##################################################  # ##################################################
32    
33    import os
34    
35  from Thuban.Model.color import Color  from Thuban.Model.color import Color, Transparent
36    
37    from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, \
38                          colorObj
39    
40  # ###################################  # ###################################
41  #  #
# Line 56  shp_type = { 0:'point', Line 60  shp_type = { 0:'point',
60  # ##################################################  # ##################################################
61    
62  # ##################################################  # ##################################################
63  # General Classes that are not explicitly defined through  # General Classes that are not all explicitly defined through
64  # a mapfile, but rather some helper-classes.  # a mapfile, but rather some helper-classes.
65    
66  class MF_Rectangle:  class MF_Rectangle:
# Line 78  class MF_Rectangle: Line 82  class MF_Rectangle:
82    
83      def get_maxy(self):      def get_maxy(self):
84          return self._rect.maxy          return self._rect.maxy
85        
86        def get_rect(self):
87            return (self._rect.minx,self._rect.miny,self._rect.maxx,self._rect.maxy)
88    
89        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    
95  class MF_Color:  class MF_Color:
96      """      """
# Line 95  class MF_Color: Line 107  class MF_Color:
107      not add any capability.      not add any capability.
108            
109      color is definied as RGB 0..255      color is definied as RGB 0..255
110      """      """    
111      def __init__(self, mf_color):      def __init__(self, mf_color):
112          self._color = mf_color          self._color = mf_color
113    
# Line 116  class MF_Color: Line 128  class MF_Color:
128    
129      def get_blue(self):      def get_blue(self):
130          return self._color.blue          return self._color.blue
131            
132        def get_mfcolor(self):
133            return self._color
134    
135      def get_thubancolor(self):      def get_thubancolor(self):
136          return self._thubancolor          return self._thubancolor    
137    
138      def set_thubancolor(self, thuban_color):      def set_thubancolor(self, thuban_color):
139          self._color.red = int(thuban_color.red * 255)          if thuban_color != Transparent:
140          self._color.green = int(thuban_color.green * 255)              self._color.red = int(thuban_color.red * 255)
141          self._color.blue = int(thuban_color.blue * 255)              self._color.green = int(thuban_color.green * 255)
142          self._thubancolor = thuban_color              self._color.blue = int(thuban_color.blue * 255)
143                self._thubancolor = thuban_color
144    
145    
146  class MF_Size:  class MF_Size:
# Line 143  class MF_Size: Line 159  class MF_Size:
159            
160      def get_height(self):      def get_height(self):
161          return self._height          return self._height
162        
163        def set_size(self, newwidth, newheight):
164            self._width = newwidth
165            self._height = newheight
166    
167    
168  class MF_Metadata:  class MF_Metadata:
# Line 182  class MF_Metadata: Line 202  class MF_Metadata:
202      def add_metadata(self, key, data):      def add_metadata(self, key, data):
203          self.data[key] = data          self.data[key] = data
204    
   
205  # ##################################################  # ##################################################
206  # Classes for MapServer Objects as they are  # Classes for MapServer Objects as they are
207  # explicitly defined in a mapfile.  # explicitly defined in a mapfile
208    
209    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  class MF_Class:  class MF_Class:
239      """      """
240      The following parameters and functions, which the mapscript style obj      The following parameters and functions, which the mapscript style obj
241      contains, are used:      contains, are used:
242      styles, numstyles, name,      styles, numstyles, name,
243      getExpressionString(), getMetaData(), getFirstMetaDataKey(),      getExpressionString(), setExpression(), getMetaData(), getFirstMetaDataKey(),
244      getNextMetaDataKey(), getStyle()      getNextMetaDataKey(), getStyle()
245    
246      The following parameters and functions are not used:      The following parameters and functions are not used:
# Line 202  class MF_Class: Line 250  class MF_Class:
250      createLegendIcon(), insertStyle(), removeStyle(), moveStyleUp(),      createLegendIcon(), insertStyle(), removeStyle(), moveStyleUp(),
251      moveStyleDown()      moveStyleDown()
252      """      """
       
253      def __init__(self, mf_class):      def __init__(self, mf_class):
254          """          """
255          Initialized a class from them given mapscript Class Object          Initialized a class from them given mapscript Class Object
# Line 216  class MF_Class: Line 263  class MF_Class:
263          for i in range(0,self._numstyles,1):          for i in range(0,self._numstyles,1):
264              self._styles.append(MF_Style(mf_class.getStyle(i)))              self._styles.append(MF_Style(mf_class.getStyle(i)))
265                    
           
266          if self._clazz.getExpressionString() == '"(null)"':          if self._clazz.getExpressionString() == '"(null)"':
267              self._expression = None              self._expression = None
268          else:          else:
# Line 244  class MF_Class: Line 290  class MF_Class:
290                    
291      def get_expressionstring(self):      def get_expressionstring(self):
292          return self._expression          return self._expression
293        
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    
315    
316  class MF_Layer:  class MF_Layer:
# Line 253  class MF_Layer: Line 320  class MF_Layer:
320    
321      classitem, numclasses, name, data, type      classitem, numclasses, name, data, type
322      getClass(), getProjection(), getExtent(), getMetaData(),      getClass(), getProjection(), getExtent(), getMetaData(),
323      getFirstMetaDataKey(), getNextMetaDataKey()      getFirstMetaDataKey(), getNextMetaDataKey(), status,
324    
325    
326      The following paramters and functions are not used:      The following paramters and functions are not used:
327      index, map, header, footer, template, groupe, status, tolerance,      index, map, header, footer, template, groupe, tolerance,
328      toleranceunits, symbolscale, minscale, maxscale, labelminscale      toleranceunits, symbolscale, minscale, maxscale, labelminscale
329      labelmaxscale, sizeunits, maxfeatures, offsite, transform, labelcache      labelmaxscale, sizeunits, maxfeatures, offsite, transform, labelcache
330      postlabelcache, labelitem, labelsizeitem, labelangleitem, labelitemindex      postlabelcache, labelitem, labelsizeitem, labelangleitem, labelitemindex
# Line 331  class MF_Layer: Line 398  class MF_Layer:
398    
399      def get_projection(self):      def get_projection(self):
400          return self._projection          return self._projection
401        
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    
462  class MF_Map:  class MF_Map:
463      """      """
# Line 338  class MF_Map: Line 465  class MF_Map:
465      contains, are used:      contains, are used:
466    
467      name, numlayers, extent, shapepath, imagecolor, imagetype, getLayer,      name, numlayers, extent, shapepath, imagecolor, imagetype, getLayer,
468      getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey      getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey,
469        save(), setExtent(), height, width, setProjection()
470    
471            
472      The following parameters and functions are not used:      The following parameters and functions are not used:
473      status, height, width, maxsize, layers, symbolset, fontset, labelcache,      status, maxsize, layers, symbolset, fontset, labelcache,
474      transparent, interlace, imagequality, cellsize, units, debug, datapattern,      transparent, interlace, imagequality, cellsize, units, debug, datapattern,
475      templatepattern, configoptions      templatepattern, configoptions
476      zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(),      zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(),
477      clone(), setExtent(), removeLayer(), getLayerByName(), getSymbolByName(),      clone(), removeLayer(), getLayerByName(), getSymbolByName(),
478      prepareQuery(), prepareImage(), setImageType(), setOutputFormat(), draw(),      prepareQuery(), prepareImage(), setImageType(), setOutputFormat(), draw(),
479      drawQuery(), drawLegend(), drawScalebar(), embedLegend(), drawLabelCache(),      drawQuery(), drawLegend(), drawScalebar(), embedLegend(), drawLabelCache(),
480      nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(), queryByShape(),      nextLabel(), queryByPoint(), queryByRecht(), queryByFeatures(), queryByShape(),
481      setWKTProjection(), setProjection(), save(), saveQuery(), saveQueryASGML(),      setWKTProjection(), saveQuery(), saveQueryASGML(),
482      setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(), setFontSet(),      setMetaData(), removeMetaData(), setSymbolSet(), getNumSymbols(), setFontSet(),
483      saveMapContext(), loadMapContext(), moveLayerUp(), moveLayerDown(),      saveMapContext(), loadMapContext(), moveLayerUp(), moveLayerDown(),
484      getLayersDrawingOrder(), setLayersDrawingOrder(), setConfigOption(),      getLayersDrawingOrder(), setLayersDrawingOrder(), setConfigOption(),
# Line 361  class MF_Map: Line 489  class MF_Map:
489            
490      def __init__(self, mf_map):      def __init__(self, mf_map):
491          """          """
492          Create the map object from the mapfile mapobject witch is given.          Create the map object from the mapfile mapobject which is given.
493    
494          All layers in the mapfile will be written to an array.          All layers in the mapfile will be written to an array.
495          """          """
# Line 403  class MF_Map: Line 531  class MF_Map:
531                  self._metakeydata = self._mf_map.getMetaData(self._metafkey)                  self._metakeydata = self._mf_map.getMetaData(self._metafkey)
532                  self._metadata.add_metadata(self._metafkey,self._metakeydata)                  self._metadata.add_metadata(self._metafkey,self._metakeydata)
533                  self._metafkey = self._mf_map.getNextMetaDataKey(self._metafkey)                  self._metafkey = self._mf_map.getNextMetaDataKey(self._metafkey)
534                    
   
535      def get_extent(self):      def get_extent(self):
536          return self._extent          return self._extent
537                    
# Line 422  class MF_Map: Line 549  class MF_Map:
549            
550      def get_imagetype(self):      def get_imagetype(self):
551          return self._imagetype          return self._imagetype
552                
553      def get_layerorder(self):      def get_layerorder(self):
554          # shows the order of layer as list          # shows the order of layer as list
555          return self._mf_map.getLayerOrder()              return self._mf_map.getLayerOrder()    
556        
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  class MF_Projection:  class MF_Projection:
618      """      """
619      The following parameter, which the mapscript style obj contains is used:      The following parameter, which the mapscript style obj contains is used:
# Line 443  class MF_Projection: Line 629  class MF_Projection:
629          be splitted and an array with the parameters will be creaded.          be splitted and an array with the parameters will be creaded.
630          """          """
631          self._mfprojstring = mf_projection          self._mfprojstring = mf_projection
632            self._projstring = self._mfprojstring
633          self._epsgcode = None          self._epsgcode = None
634          self._params = None          self._params = None
635          if self._mfprojstring:          if self._mfprojstring:
# Line 489  class MF_Projection: Line 676  class MF_Projection:
676      def get_epsgproj(self):      def get_epsgproj(self):
677          # get an epsg projectionobject          # get an epsg projectionobject
678          return self.epsg_code_to_projection(self._epsgcode)          return self.epsg_code_to_projection(self._epsgcode)
679        
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    
691  class MF_Style:  class MF_Style:
692      """      """
693      The following parameters, which the mapscript style obj      The following parameters, which the mapscript style obj
694      contains, are used:      contains, are used:
695            
696      color, backgroundcolor, outlinecolor, size      color, backgroundcolor, outlinecolor, size, symbolname
697    
698      The following are not used:      The following are not used:
699      symbol, symbolname, sizescaled, minsize, maxsize, offsetx, offsety,      symbol, sizescaled, minsize, maxsize, offsetx, offsety,
700      antialias      antialias
701      """      """
702    
# Line 513  class MF_Style: Line 710  class MF_Style:
710          """          """
711          self._style = mf_style          self._style = mf_style
712          if self._style.color.red == -1:          if self._style.color.red == -1:
713              self._color = None              self._maincolor = None
714          else:          else:
715              self._color = MF_Color(self._style.color)              self._maincolor = MF_Color(self._style.color)
716          self._backgroundcolor = MF_Color(self._style.backgroundcolor)          self._color = MF_Color(self._style.color)
717          if self._style.outlinecolor.red == -1:          if self._style.outlinecolor.red == -1:
718              self._outlinecolor = None              self._outlinecolor = None
719          else:          else:
# Line 530  class MF_Style: Line 727  class MF_Style:
727        
728      def get_size(self):      def get_size(self):
729          return self._style.size          return self._style.size
730        
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    

Legend:
Removed from v.2251  
changed lines
  Added in v.2252

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26