jschuengel: thuban/Extensions/umn_mapserver mapfile.py,1.2,1.3
cvs@intevation.de
cvs at intevation.de
Thu Jul 1 16:39:02 CEST 2004
Author: jschuengel
Update of /thubanrepository/thuban/Extensions/umn_mapserver
In directory doto:/tmp/cvs-serv4209
Modified Files:
mapfile.py
Log Message:
Added new types which are need for the editing functions.
Added needed set-functions for the editing functions.
Added the possibility to export rasterimages.
Added new classes (MF_Web, MF_Label, MF_Legend, MF_Symbol, MF_SymbolSet).
MF_Symbol and MF_SymbolSet are not needed at the moment.
(MF_Class.set_thubanstyle): Now point layers will set to a default symbol
to show a circle in mapserver and not only a 1px dot. (MF_Style.__init__): Fixed a bug with the color. Color was not set correct
before.
(MF_Size): Removed, because it is not needed.
Index: mapfile.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/umn_mapserver/mapfile.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mapfile.py 23 Jun 2004 12:39:52 -0000 1.2
+++ mapfile.py 1 Jul 2004 14:39:00 -0000 1.3
@@ -13,10 +13,10 @@
mapscript are not implemented yet in this extension:
DBFInfo, errorObj, fontSetObj, graticuleObj, imageObj, itemObj,
- labelCacheMemberObj, labelCacheObj, labelObj, legendObj, lineObj,
+ labelCacheMemberObj, labelCacheObj, lineObj,
markerCacheMembet, msTiledSHPLayerInfo, OutputFormat, pointObj, queryMapObj,
referenzMapObj, resultCacheMemberObj, resultCacheObj, scalebarObj,
- shapefileObj, shapeObj, styleObj, symbolObj, symbolSetObj, VectorObj, WebObj
+ shapefileObj, shapeObj, VectorObj, WebObj
"""
__version__ = "$Revision$"
@@ -34,8 +34,8 @@
from Thuban.Model.color import Color, Transparent
-from mapscript import layerObj, classObj, colorObj, styleObj, rectObj, \
- colorObj
+from mapscript import layerObj, classObj, colorObj, styleObj, rectObj
+
# ###################################
#
@@ -51,6 +51,38 @@
5:'circle',
6:'query'}
+unit_type = { 0:"inches",
+ 1:"feet",
+ 2:"miles",
+ 3:"meters",
+ 4:"kilometers",
+ 5:"dd"}
+
+legend_status_type = { 0:"OFF",
+ 1:"ON",
+ 3:"embed" }
+ # 2 = Default but will not be imported because
+ # mapscript dont support it and its not allowed
+
+layer_status_type = { 0:"OFF",
+ 1:"ON",
+ 2:"default"}
+
+legend_position_type = { 0:"ul",
+ 1:"lr",
+ 2:"ur",
+ 3:"ll",
+ 6:"uc",
+ 7:"lc"}
+
+label_size_type = { 0:"tiny",
+ 1:"small",
+ 2:"medium",
+ 3:"large",
+ 4:"giant" }
+
+label_font_type = { 0:"truetype",
+ 1:"bitmap" }
# ##################################################
@@ -129,6 +161,16 @@
def get_blue(self):
return self._color.blue
+ def set_rgbcolor(self, red, green, blue):
+ self._color.red = red
+ self._color.green = green
+ self._color.blue = blue
+
+ self._tbc_red = (float(self.get_red())/255)
+ self._tbc_green = (float(self.get_green())/255)
+ self._tbc_blue = (float(self.get_blue())/255)
+ self._thubancolor = Color(self._tbc_red, self._tbc_green, self._tbc_blue)
+
def get_mfcolor(self):
return self._color
@@ -143,28 +185,6 @@
self._thubancolor = thuban_color
-class MF_Size:
- """
- Handle sizes.
- This is not implemented as a Class in mapscript but
- seems to be helpful.
- """
-
- def __init__(self, mf_width, mf_height):
- self._width = mf_width
- self._height = mf_height
-
- def get_width(self):
- return self._width
-
- def get_height(self):
- return self._height
-
- def set_size(self, newwidth, newheight):
- self._width = newwidth
- self._height = newheight
-
-
class MF_Metadata:
"""
Metadata is not a Object in mapscript witch can be used
@@ -299,14 +319,22 @@
self._expression = self._clazz.getExpressionString()
def add_thubanstyle(self, tb_style, type="default"):
+ """
+ added a thuban style object to the mapobject
+ """
new_styleobj = MF_Style(styleObj(self._clazz))
if type == "line":
new_styleobj.set_color(tb_style.GetLineColor())
- elif type == "circle":
+ elif type == "point":
# set a default symbol to show circles not only a small dot
# symbol "circle" must create before
# TODO: create a Symbol (more see MF_SymbolSet)
- new_styleobj.set_symbol('circle')
+ # first the default symbol circle will be created and the size 8
+ new_styleobj.set_symbolname('circle')
+ new_styleobj.set_size(8)
+ if tb_style.GetLineColor() != Transparent:
+ new_styleobj.set_linecolor(tb_style.GetLineColor())
+ new_styleobj.set_color(tb_style.GetFill())
else:
new_styleobj.set_size(tb_style.GetLineWidth())
new_styleobj.set_linecolor(tb_style.GetLineColor())
@@ -411,8 +439,12 @@
def set_name(self, newname):
self._mf_layer.name = newname
- def set_data(self, newdata):
- self._mf_layer.data = newdata[:-4]
+ def set_data(self, newdata, type="shape"):
+ if type == "raster":
+ self._mf_layer.data = newdata
+ else:
+ self._mf_layer.data = newdata[:-4]
+
def set_status(self, newstatus):
# status can set to true or false from thuban.
@@ -426,6 +458,8 @@
# if type = arc its a in shapetype line
if tb_type == "arc":
self._mf_layer.type = 1
+ if tb_type == "raster":
+ self._mf_layer.type = 3
if shp_type.has_key(tb_type):
self._mf_layer.type = tb_type
else:
@@ -442,36 +476,41 @@
self._mfnewprojstring = self._mfnewprojstring+ "," + field
self._mf_layer.setProjection(self._mfnewprojstring[1:])
self._projection.set_projection(newprojection)
- else:
- print "no projection"
- def add_thubanclass(self, tb_class):
+ def add_thubanclass(self, tb_class, type=""):
+ """
+ Add a thuban class object
+ """
new_class = MF_Class(classObj(self._mf_layer))
new_class.set_name(tb_class.GetLabel())
if self.get_type() == "line":
new_class.add_thubanstyle(tb_class.GetProperties(), type="line")
+ elif self.get_type() == "point":
+ new_class.add_thubanstyle(tb_class.GetProperties(), type="point")
else:
new_class.add_thubanstyle(tb_class.GetProperties())
- if tb_class.GetDisplayText() == "DEFAULT":
+ if (type == "default"):
return
- #new_class.set_expressionstring('/./')
+ elif (tb_class.Matches("DEFAULT")):
+ new_class.set_expressionstring('/./')
else:
- new_class.set_expressionstring(str(tb_class.GetDisplayText()))
+ new_class.set_expressionstring(str(tb_class.GetValue()))
self._classes.append(new_class)
+
class MF_Map:
"""
The following parameters and functions, which the mapscript style obj
contains, are used:
- name, numlayers, extent, shapepath, imagecolor, imagetype, getLayer,
- getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey,
+ name, numlayers, extent, shapepath, imagecolor, imagetype, units, getLayer,
+ status, getProjection, getMetaData, getFirstMetaDataKey, getNextMetaDataKey,
save(), setExtent(), height, width, setProjection()
The following parameters and functions are not used:
- status, maxsize, layers, symbolset, fontset, labelcache,
- transparent, interlace, imagequality, cellsize, units, debug, datapattern,
+ maxsize, layers, symbolset, fontset, labelcache,
+ transparent, interlace, imagequality, cellsize, debug, datapattern,
templatepattern, configoptions
zoomPoint(), zoomRectangle(), zoomScale(), getLayerOrder(), setLayerOrder(),
clone(), removeLayer(), getLayerByName(), getSymbolByName(),
@@ -497,6 +536,8 @@
self._mf_map = mf_map
self._extent = MF_Rectangle(self._mf_map.extent)
self._imagecolor = MF_Color(self._mf_map.imagecolor)
+ self._web = MF_Web(self._mf_map.web)
+ self._legend = MF_Legend(self._mf_map.legend)
# if the map name is not set it will return a MS string.
if self._mf_map.name != "MS":
@@ -532,6 +573,18 @@
self._metadata.add_metadata(self._metafkey,self._metakeydata)
self._metafkey = self._mf_map.getNextMetaDataKey(self._metafkey)
+ def get_status(self):
+ if layer_status_type[self._mf_map.status] == "OFF":
+ return false
+ else:
+ return true
+
+ def get_web(self):
+ return self._web
+
+ def get_legend(self):
+ return self._legend
+
def get_extent(self):
return self._extent
@@ -552,7 +605,18 @@
def get_layerorder(self):
# shows the order of layer as list
- return self._mf_map.getLayerOrder()
+ return self._mf_map.getLayerOrder()
+
+ def get_size(self):
+ #returns the size
+ return (self._mf_map.width, self._mf_map.height)
+
+ def get_units(self):
+ #returns the unittype
+ return unit_type[self._mf_map.units]
+
+ def get_imagecolor(self):
+ return self._imagecolor
def set_name(self, newname):
# whitespace musst be replaced, either no
@@ -564,8 +628,11 @@
def set_extent(self, newextent):
# TODO: add the shown extend here instead of the total
self._newrect = MF_Rectangle(rectObj())
- self._newrect.set_rect(newextent[0],newextent[1],newextent[2],newextent[3])
- self._mf_map.setExtent(newextent[0],newextent[1],newextent[2],newextent[3])
+ try:
+ self._newrect.set_rect(newextent[0],newextent[1],newextent[2],newextent[3])
+ self._mf_map.setExtent(newextent[0],newextent[1],newextent[2],newextent[3])
+ except:
+ return
def set_size(self, newwidth, newheight):
self._mf_map.width = newwidth
@@ -578,42 +645,215 @@
self._mfnewprojstring = self._mfnewprojstring+ "," + field
self._mf_map.setProjection(self._mfnewprojstring[1:])
self._projection.set_projection(projection)
+
+ def set_units(self, units):
+ if unit_type.has_key(units):
+ self._mf_map.units = units
+ else:
+ for unit_paar_nr in unit_type:
+ if unit_type[unit_paar_nr] == units:
+ self._mf_map.units = unit_paar_nr
def add_thubanlayer(self, tb_layer):
+ """
+ Add a thuban layer
+ """
new_layer = MF_Layer(layerObj(self._mf_map))
new_layer.set_name(tb_layer.Title())
# TODO: implement relative pathnames
# yet only absolute pathnames in the LayerObj are set
- new_layer.set_data(tb_layer.ShapeStore().FileName())
-
- new_layer.set_status(tb_layer.Visible())
- new_layer.set_type(tb_layer.ShapeType())
+ try:
+ new_layer.set_data(tb_layer.ShapeStore().FileName())
+ except:
+ new_layer.set_data(tb_layer.GetImageFilename(), type="raster")
+ new_layer.set_type("raster")
+ else:
+ new_layer.set_status(tb_layer.Visible())
+ new_layer.set_type(tb_layer.ShapeType())
+ if tb_layer.GetClassificationColumn():
+ new_layer.set_classitem(tb_layer.GetClassificationColumn())
+ if tb_layer.GetProjection():
+ new_layer.set_projection(tb_layer.GetProjection())
+ if tb_layer.GetClassification().GetNumGroups() > 0:
+ for group in range(0, tb_layer.GetClassification().GetNumGroups(), 1):
+ new_layer.add_thubanclass(tb_layer.GetClassification().GetGroup(group))
+ new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
+ else:
+ new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup(), type="default")
+
# set the projection to the layer.
# if the layer has its own definition use is, else use the main projection
if tb_layer.GetProjection():
new_layer.set_projection(tb_layer.GetProjection())
else:
new_layer.set_projection(self._projection.get_projection())
-
- if tb_layer.GetClassificationColumn():
- new_layer.set_classitem(tb_layer.GetClassificationColumn())
- if tb_layer.GetProjection():
- new_layer.set_projection(tb_layer.GetProjection())
- if tb_layer.GetClassification().GetNumGroups() > 0:
- for group in range(0, tb_layer.GetClassification().GetNumGroups(), 1):
- new_layer.add_thubanclass(tb_layer.GetClassification().GetGroup(group))
- new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
- else:
- new_layer.add_thubanclass(tb_layer.GetClassification().GetDefaultGroup())
self._layers.append(new_layer)
+ def remove_layer(self, nr):
+ self._mf_map.removeLayer(nr)
+ self._numlayers -= 1
+ self._layers.remove(self._layers[nr])
+
def save_map(self, filepath):
# save the Map
# maybe an own saver can implement here
self._mf_map.save(filepath)
+
+
+class MF_Web:
+ """
+ Save the Web settings
+
+ The following parametes are used:
+ imagepath, imageurl
+
+ The following parameters are not used:
+ log, map, template, queryformat, header, footer, empty, error, extent,
+ minscale, maxscale, mintemplate, maxtemplate
+ """
+ def __init__(self, mf_web):
+ self._mf_web = mf_web
+
+ def get_imagepath(self):
+ return self._mf_web.imagepath
+
+ def set_imagepath(self, new_imagepath):
+ self._mf_web.imagepath = new_imagepath
+
+ def get_imageurl(self):
+ return self._mf_web.imageurl
+
+ def set_imageurl(self, new_imageurl):
+ self._mf_web.imagepath = new_imageurl
+
+ def get_queryformat(self):
+ return self._mf_web.queryformat
+
+ def set_queryformat(self, new_queryformat):
+ self._mf_web.imagepath = new_queryformat
+
+
+class MF_Label:
+ """
+ The following parameters from mapscript are used:
+ type, color, size, offsetx, offsety,
+
+ The following parameters are not used:
+ font, outlinecolor, shadowcolor, shadowsizex, shadowsizey,
+ backgroundcolor, backgroundshadowcolor, backgroundshadowsizex,
+ backgroundshadowsizey, sizescaled, minsize, maxsize, position, angle,
+ autoangle, buffer, antialias, wrap, minfeaturesize,
+ autominfeaturesize, mindistance, partials, force
+ """
+ def __init__(self, mf_label):
+ """
+ Create a legend obj from the existing mapfile
+ """
+ self._label = mf_label
+ self._color = MF_Color(self._label.color)
+
+ def get_size(self):
+ return self._label.size
+
+ def set_size(self, new_size):
+ if label_size_type.has_key(new_size):
+ self._label.size = new_size
+ for label_size_type_nr in label_size_type:
+ if label_size_type[label_size_type_nr] == new_size:
+ self._label.size = label_size_type_nr
+ else:
+ self._label.size = new_size
+
+ def get_color(self):
+ return self._color
+
+ def get_type(self):
+ return label_font_type[self._label.type]
+
+ def set_type(self, new_type):
+ if label_font_type.has_key(new_type):
+ self._label.type = new_type
+ else:
+ for label_font_type_nr in label_font_type:
+ if label_font_type[label_font_type_nr] == new_type:
+ self._label.type = label_font_type_nr
+
+ def get_offset(self):
+ return (self._label.offsetx, self._label.offsety)
+
+ def set_offset(self, new_offsetx, new_offsety):
+ self._label.offsetx = new_offsetx
+ self._label.offsety = new_offsety
+
+
+class MF_Legend:
+ """
+ The following parameters are (not) used:
+ imagecolor, label, keysizex, keysizey, status, position,
+
+ The following parameters are not used:
+ keyspacingx, keyspacingy,
+ outlinecolor, height, width, postlabelcache, template, map
+ """
+ def __init__(self, mf_legend):
+ """
+ Create a legend obj from the existing mapfile
+ """
+ self._mf_legend = mf_legend
+ self._imagecolor = MF_Color(self._mf_legend.imagecolor)
+ self._label = MF_Label(self._mf_legend.label)
+ def get_imagecolor(self):
+ return self._imagecolor
+
+ def get_label(self):
+ return self._label
+
+ def get_keysize(self):
+ return (self._mf_legend.keysizex, self._mf_legend.keysizey)
+
+ def set_keysize(self, new_keysizex, new_keysizey):
+ self._mf_legend.keysizex = new_keysizex
+ self._mf_legend.keysizey = new_keysizey
+
+ def get_keyspacing(self):
+ return (self._mf_legend.keyspacingx, self._mf_legend.keyspacingy)
+
+ def set_keyspacing(self, new_keyspacingx, new_keyspacingy):
+ self._mf_legend.keyspacingx = new_keyspacingx
+ self._mf_legend.keyspacingy = new_keyspacingy
+
+ def get_status(self, art="integer"):
+ if art == "string":
+ return legend_status_type[self._mf_legend.status]
+ else:
+ return self._mf_legend.status
+
+ def set_status(self, new_status):
+ if legend_status_type.has_key(new_status):
+ self._mf_legend.status = new_status
+ else:
+ for legend_status_type_nr in legend_status_type:
+ if legend_status_type[legend_status_type_nr] == new_status:
+ self._mf_legend.status = legend_status_type_nr
+
+ def get_position(self, art="integer"):
+ if art == "string":
+ return legend_position_type[self._mf_legend.position]
+ else:
+ return self._mf_legend.position
+
+ def set_position(self, new_position):
+ if legend_position_type.has_key(new_position):
+ self._mf_legend.position = new_position
+ else:
+ for legend_position_type_nr in legend_position_type:
+ if legend_position_type[legend_position_type_nr] == new_position:
+ self._mf_legend.position = legend_position_type_nr
+
+
class MF_Projection:
"""
The following parameter, which the mapscript style obj contains is used:
@@ -624,10 +864,10 @@
def __init__(self, mf_projection):
"""
Create a projection object from the given mapscript projection
- object. If it is a epsg code the extracted from the string
- (e.g."init=epsg:xxxx"), else the projection parameters will
- be splitted and an array with the parameters will be creaded.
- """
+ object. If it is a epsg code the extracted from the string
+ (e.g."init=epsg:xxxx"), else the projection parameters will
+ be splitted and an array with the parameters will be creaded.
+ """
self._mfprojstring = mf_projection
self._projstring = self._mfprojstring
self._epsgcode = None
@@ -688,11 +928,11 @@
self._mfnewprojstring = self._mfnewprojstring+ "+" + field
self._mfprojstring = self._mfnewprojstring
+
class MF_Style:
"""
The following parameters, which the mapscript style obj
contains, are used:
-
color, backgroundcolor, outlinecolor, size, symbolname
The following are not used:
@@ -710,10 +950,9 @@
"""
self._style = mf_style
if self._style.color.red == -1:
- self._maincolor = None
+ self._color = None
else:
- self._maincolor = MF_Color(self._style.color)
- self._color = MF_Color(self._style.color)
+ self._color = MF_Color(self._style.color)
if self._style.outlinecolor.red == -1:
self._outlinecolor = None
else:
@@ -747,5 +986,5 @@
def set_symbolname(self, newsymbol):
# its possible to use stringnames instead of numbers
- self._style.symbolname = 'circle'
+ self._style.symbolname = newsymbol
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)