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