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