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