gvsig-scripting / org.gvsig.scripting.app / trunk / org.gvsig.scripting.app / org.gvsig.scripting.app.extension / src / main / resources-plugin / scripting / lib / gvsig2_1_0 / vectorial / feature.py @ 447
History | View | Annotate | Download (5.03 KB)
1 |
|
---|---|
2 |
|
3 |
__docformat__ = "restructuredtext en"
|
4 |
|
5 |
from org.gvsig.fmap.dal.feature.impl import DefaultFeature as JFeature |
6 |
from org.gvsig.fmap.dal.feature.impl import DefaultEditableFeature as JEditableFeature |
7 |
|
8 |
class Feature(JFeature): |
9 |
"""
|
10 |
Represents feature.
|
11 |
|
12 |
Extends the `java Feature`_.
|
13 |
|
14 |
.. _`java Feature` : FIXME_URL
|
15 |
"""
|
16 |
|
17 |
@staticmethod
|
18 |
def geometry(self): |
19 |
"""
|
20 |
Returns the default geometry of the feature.
|
21 |
|
22 |
:return:
|
23 |
The geometry of the feature
|
24 |
:returntype:
|
25 |
Geometry
|
26 |
.. _Geometry : FIXME_URL
|
27 |
"""
|
28 |
return self.getDefaultGeometry() |
29 |
|
30 |
@staticmethod
|
31 |
def getValues(self): |
32 |
"""
|
33 |
Returns dictionary with the pair name, value, feature attributes
|
34 |
|
35 |
:return:
|
36 |
A dict with the pairs attribute-name,attribute-value.
|
37 |
:returntype:
|
38 |
dict
|
39 |
"""
|
40 |
descriptor = self.getType()
|
41 |
items = dict()
|
42 |
for attr in descriptor.getAttributeDescriptors(): |
43 |
name = attr.getName() |
44 |
value = self.get(attr.getName())
|
45 |
items[name] = value |
46 |
return items
|
47 |
|
48 |
@staticmethod
|
49 |
def edit(self): |
50 |
"""
|
51 |
This method is not supported from gvSIG 2.1.0
|
52 |
"""
|
53 |
raise Exception("Deprecated method, use import gvSIG_2_0_0 for compatibilitty with fvSIG 2.0.0") |
54 |
|
55 |
@staticmethod
|
56 |
def __getitem__(self,attributeName): |
57 |
"""
|
58 |
Get the value of an attribute of the feature.
|
59 |
|
60 |
:parameters:
|
61 |
attributeName : string
|
62 |
name of the attribute to retrieve the value
|
63 |
:return:
|
64 |
The value of the attribute specified as parameter
|
65 |
:returntype:
|
66 |
object
|
67 |
"""
|
68 |
return self.get(attributeName) |
69 |
|
70 |
@staticmethod
|
71 |
def __getattr__(self,attributeName): |
72 |
"""
|
73 |
Allow to get the value of an feature attribute as attribute of the python object.
|
74 |
|
75 |
:parameters:
|
76 |
attributeName : string
|
77 |
name of the feature attribute to retrieve the value
|
78 |
:return:
|
79 |
The value of the feature attribute specified as parameter
|
80 |
:returntype:
|
81 |
object
|
82 |
"""
|
83 |
#
|
84 |
# FIX console error when try to introspect feature object
|
85 |
if name in ('__methods__'): |
86 |
return dict() |
87 |
elif name in ('__members__'): |
88 |
return self.getValues().keys() |
89 |
elif name == '__dict__': |
90 |
return self.getValues() |
91 |
|
92 |
try:
|
93 |
v = getattr(self, attributeName, None) |
94 |
if v == None: |
95 |
v = self.get(attributeName)
|
96 |
return v
|
97 |
except Throwable, ex:
|
98 |
raise RuntimeException("Can't access to attribute %s of feature (%s)" % (attributeName, str(ex))) |
99 |
|
100 |
|
101 |
class EditableFeature(JEditableFeature,Feature): |
102 |
"""
|
103 |
Represents feature.
|
104 |
|
105 |
Extends the `java EditableFeature`_.
|
106 |
|
107 |
.. _`java EditableFeature` : FIXME_URL
|
108 |
"""
|
109 |
|
110 |
@staticmethod
|
111 |
def setGeometry(self,*args): |
112 |
if len(args)==1: |
113 |
self.setDefaultGeometry(args[0]) |
114 |
return
|
115 |
if len(args)==2: |
116 |
self.set(args[0],args[1]) |
117 |
return
|
118 |
raise IllegalArgumentException("Incorrent number of arguments ("+len(args)+"), expected 1 or 2") |
119 |
|
120 |
@staticmethod
|
121 |
def setValues(self,*args,**kwargs): |
122 |
"""
|
123 |
Set the value of an attribute of the feature.
|
124 |
|
125 |
Can receibe two parameters, the first the name of the attribute to set the
|
126 |
value, an the second the value of the attribute.
|
127 |
|
128 |
Alternativement you can pass parameters by name; the name is the name of the attribute to set,
|
129 |
and the value the value to set in the attribute.
|
130 |
"""
|
131 |
if len(args)!=0: |
132 |
if len(args)!=2: |
133 |
raise IllegalArgumentException("Incorrent number of arguments ("+len(args)+"), expected 2.") |
134 |
self.set(args[0],args[1]) |
135 |
return
|
136 |
for k,v in kwargs.iteritems(): |
137 |
self.set(k,v)
|
138 |
|
139 |
@staticmethod
|
140 |
def __setitem__(self,attributeName, value): |
141 |
"""
|
142 |
Set the value of an attribute of the feature.
|
143 |
|
144 |
:parameters:
|
145 |
attributeName : string
|
146 |
name of the attribute to retrieve the value
|
147 |
value : object
|
148 |
value to set
|
149 |
"""
|
150 |
return self.set(attributeName,value) |
151 |
|
152 |
@staticmethod
|
153 |
def __setattr__(self,attributeName, value): |
154 |
"""
|
155 |
Allow to set the value of an feature attribute as attribute of the python object.
|
156 |
|
157 |
:parameters:
|
158 |
attributeName : string
|
159 |
name of the feature attribute to retrieve the value
|
160 |
value : object
|
161 |
value to set
|
162 |
"""
|
163 |
try:
|
164 |
self.set(attributeName, value)
|
165 |
except Throwable, ex:
|
166 |
raise RuntimeException("Can't set the attribute %s of feature (%s)" % (attributeName, str(ex))) |
167 |
|
168 |
|
169 |
#
|
170 |
# Inject new methods in the class JFeature
|
171 |
#
|
172 |
JFeature.getValues = Feature.setValues |
173 |
JFeature.geometry = Feature.geometry |
174 |
JFeature.__getitem__ = Feature.__getitem__ |
175 |
JFeature.__getattr__ = Feature.__getattr__ |
176 |
|
177 |
#
|
178 |
# Inject new methods in the class JEditableFeature
|
179 |
#
|
180 |
JEditableFeature.getValues = Feature.setValues |
181 |
JEditableFeature.geometry = Feature.geometry |
182 |
JEditableFeature.__getitem__ = Feature.__getitem__ |
183 |
JEditableFeature.__getattr__ = Feature.__getattr__ |
184 |
JEditableFeature.setValues = EditableFeature.setValues |
185 |
JEditableFeature.setGeometry = EditableFeature.setGeometry |
186 |
JEditableFeature.__setitem__ = EditableFeature.__setitem__ |
187 |
JEditableFeature.__setattr__ = EditableFeature.__setattr__ |
188 |
|
189 |
|