Revision 561
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig_2_3_0/featureset.py | ||
---|---|---|
1 | 1 |
|
2 | 2 |
|
3 | 3 |
from org.gvsig.fmap.dal.feature.impl.featureset import DefaultFeatureSet as JFeatureSet |
4 |
|
|
5 | 4 |
|
5 |
|
|
6 | 6 |
class JavaIteratorWraper(object): |
7 | 7 |
def __init__(self, jiterator): |
8 | 8 |
self._jiterator = jiterator |
... | ... | |
18 | 18 |
def __len(self): |
19 | 19 |
return self.getSize() |
20 | 20 |
|
21 |
def _getCount(self): |
|
22 |
return self.getSize() |
|
23 |
|
|
21 | 24 |
# |
22 | 25 |
# Inject new methods in the class JFeatureSet |
23 | 26 |
# |
24 |
#JFeatureSet.__iter__ = __iter |
|
27 |
JFeatureSet.getCount = _getCount |
|
28 |
JFeatureSet.__iter__ = __iter |
|
25 | 29 |
JFeatureSet.__len__ = __len |
26 | 30 |
|
27 | 31 |
|
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig_2_3_0/layervectorial.py | ||
---|---|---|
1 | 1 |
|
2 | 2 |
|
3 | 3 |
from org.gvsig.fmap.mapcontext.layers.vectorial import FLyrVect as JLayerVectorial |
4 |
import table
|
|
4 |
import table |
|
5 | 5 |
|
6 | 6 |
def getProjectionCode(self): |
7 | 7 |
projection = self.getProjection() |
... | ... | |
29 | 29 |
JLayerVectorial.select = table._select |
30 | 30 |
JLayerVectorial.deselect = table._deselect |
31 | 31 |
JLayerVectorial.isSelected = table._isSelected |
32 |
JLayerVectorial.finishEditing = table._commit |
|
33 |
JLayerVectorial.cancelEditing = table._abort |
|
32 | 34 |
|
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig_2_3_0/table.py | ||
---|---|---|
15 | 15 |
return self.getFeatureStore().getFeatureSet().getSize() |
16 | 16 |
|
17 | 17 |
def _edit(self): |
18 |
self.getFeatureStore().edit()
|
|
19 |
|
|
18 |
self.getFeatureStore().edit() |
|
19 |
|
|
20 | 20 |
def _append(self, *valuesList, **values): |
21 | 21 |
self.getFeatureStore().append(*valuesList, **values) |
22 |
|
|
22 |
|
|
23 | 23 |
def _updateSchema(self, schema): |
24 | 24 |
self.getFeatureStore().update(schema) |
25 |
|
|
25 |
|
|
26 | 26 |
def _update(self, feature): |
27 | 27 |
self.getFeatureStore().update(feature) |
28 | 28 |
|
... | ... | |
37 | 37 |
|
38 | 38 |
def _getSelection(self): |
39 | 39 |
return self.getFeatureStore().getFeatureSelection() |
40 |
|
|
40 |
|
|
41 | 41 |
def _select(self, selection): |
42 | 42 |
self.getFeatureStore().getFeatureSelection().select(selection) |
43 | 43 |
|
... | ... | |
54 | 54 |
|
55 | 55 |
def _call(self): |
56 | 56 |
return self |
57 |
|
|
58 | 57 |
|
59 | 58 |
|
59 |
|
|
60 | 60 |
# |
61 | 61 |
# Inject new methods in the class JTableDocument |
62 | 62 |
# |
... | ... | |
76 | 76 |
JTableDocument.select = _select |
77 | 77 |
JTableDocument.deselect = _deselect |
78 | 78 |
JTableDocument.isSelected = _isSelected |
79 |
JTableDocument.finishEditing = _commit |
|
80 |
JTableDocument.cancelEditing = _abort |
|
79 | 81 |
|
82 |
|
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig_2_3_0/feature.py | ||
---|---|---|
1 | 1 |
|
2 | 2 |
|
3 | 3 |
from org.gvsig.fmap.dal.feature.impl import DefaultFeature as JFeature |
4 |
from java.lang import RuntimeException |
|
4 |
from java.lang import RuntimeException, Throwable
|
|
5 | 5 |
|
6 | 6 |
def _geometry(self): |
7 | 7 |
return self.getDefaultGeometry() |
8 |
|
|
8 |
|
|
9 | 9 |
def _getValues(self): |
10 | 10 |
items = dict() |
11 | 11 |
for name,value in self.iteritems(): |
12 | 12 |
items[name] = value |
13 |
return items
|
|
13 |
return items |
|
14 | 14 |
|
15 | 15 |
def _edit(self): |
16 | 16 |
raise Exception("Deprecated method, use import gvSIG_2_0_0 for compatibilitty with gvSIG 2.0.0 or use getEditable method") |
... | ... | |
20 | 20 |
|
21 | 21 |
def _getattr(self,attributeName): |
22 | 22 |
# FIX console error when try to introspect feature object |
23 |
if name in ('__methods__'):
|
|
23 |
if attributeName in ('__methods__'):
|
|
24 | 24 |
return dict() |
25 |
elif name in ('__members__'):
|
|
25 |
elif attributeName in ('__members__'):
|
|
26 | 26 |
return self.getValues().keys() |
27 |
elif name == '__dict__':
|
|
28 |
return self.getValues()
|
|
29 |
|
|
27 |
elif attributeName == '__dict__':
|
|
28 |
return self.getValues() |
|
29 |
|
|
30 | 30 |
try: |
31 |
v = getattr(self, attributeName, None) |
|
32 |
if v == None: |
|
33 |
v = self.get(attributeName) |
|
31 |
v = self.get(attributeName) |
|
34 | 32 |
return v |
35 | 33 |
except Throwable, ex: |
36 |
raise RuntimeException("Can't access to attribute %s of feature (%s)" % (attributeName, str(ex)))
|
|
34 |
raise RuntimeException("Can't access to attribute %s of feature (%s)" % (attributeName, str(ex))) |
|
37 | 35 |
|
38 | 36 |
def _call(self): |
39 | 37 |
return self |
... | ... | |
47 | 45 |
name = attr.getName() |
48 | 46 |
value = self.get(attr.getName()) |
49 | 47 |
yield name,value |
50 |
|
|
48 |
|
|
51 | 49 |
def _itervalues(self): |
52 | 50 |
descriptor = self.getType() |
53 | 51 |
for attr in descriptor.getAttributeDescriptors(): |
54 | 52 |
name = attr.getName() |
55 | 53 |
value = self.get(attr.getName()) |
56 | 54 |
yield value |
57 |
|
|
55 |
|
|
58 | 56 |
def _iterkeys(self): |
59 | 57 |
descriptor = self.getType() |
60 | 58 |
for attr in descriptor.getAttributeDescriptors(): |
61 | 59 |
name = attr.getName() |
62 | 60 |
yield name |
63 |
|
|
64 | 61 |
|
62 |
|
|
65 | 63 |
# |
66 | 64 |
# Inject new methods in the class JFeature |
67 | 65 |
# |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/gvsig_2_3_0/utils.py | ||
---|---|---|
6 | 6 |
from java.awt import Color |
7 | 7 |
|
8 | 8 |
def createFeatureType(schema = None): |
9 |
"""Returns attributes definition. If Schema is recived then makes a copy and
|
|
9 |
"""Returns attributes definition. If Schema is recived then makes a copy and |
|
10 | 10 |
returns editable instance. Otherwise returns empty Schema. |
11 | 11 |
:param schema: Schema to make a copy |
12 | 12 |
:type schema: Schema |
13 | 13 |
""" |
14 | 14 |
if isinstance(schema, FeatureType): |
15 |
try:
|
|
15 |
try: |
|
16 | 16 |
s = schema.getCopy().getEditable() |
17 | 17 |
return s |
18 | 18 |
except: |
19 | 19 |
pass |
20 |
|
|
20 |
|
|
21 | 21 |
application = ApplicationLocator.getManager() |
22 | 22 |
datamanager = application.getDataManager() |
23 | 23 |
return datamanager.createFeatureType() |
... | ... | |
29 | 29 |
Returns new layer |
30 | 30 |
:param schema: layer data definition |
31 | 31 |
:type schema: Schema |
32 |
:param servertype:
|
|
32 |
:param servertype: |
|
33 | 33 |
:type servertype: string |
34 | 34 |
:return: new layer |
35 | 35 |
:rtype: Layer |
... | ... | |
42 | 42 |
if layertype == "Shape" : |
43 | 43 |
if schema.get("GEOMETRY",None) == None: |
44 | 44 |
raise RuntimeException("Shape need a field named GEOMETRY in the schema") |
45 |
|
|
45 |
|
|
46 | 46 |
if parameters["geometryType"] == None: |
47 | 47 |
raise RuntimeException("Invalid geometry type for new layer") |
48 |
|
|
48 |
|
|
49 | 49 |
try: |
50 | 50 |
application = ApplicationLocator.getManager() |
51 | 51 |
datamanager = application.getDataManager() |
... | ... | |
68 | 68 |
layer = mapcontextmanager.createLayer(store.getName(), store) |
69 | 69 |
|
70 | 70 |
return layer |
71 |
|
|
71 |
|
|
72 | 72 |
except Throwable, ex: |
73 | 73 |
raise RuntimeException("Can't create layer, "+ str(ex)) |
74 | 74 |
|
75 |
def loadShapeFile(shpFile, CRS="CRS:84"):
|
|
75 |
def loadShapeFile(shpFile, **parameters):
|
|
76 | 76 |
""" |
77 | 77 |
Add existing shape file to the view. Returns Layer shape file |
78 | 78 |
:param shpFile: absolute file path |
... | ... | |
82 | 82 |
:return: the shape |
83 | 83 |
:type return: Layer |
84 | 84 |
""" |
85 |
layer = loadLayer('Shape', shpFile=shpFile, CRS=CRS) |
|
86 |
currentView().addLayer(layer) |
|
85 |
if parameters.get("CRS",None)==None: |
|
86 |
parameters["CRS"]="EPSG:4326" |
|
87 |
parameters["shpFile"]=shpFile |
|
88 |
layer = loadLayer('Shape', **parameters) |
|
89 |
viewName = parameters.get("gvViewName",None) |
|
90 |
if viewName == None: |
|
91 |
view = currentView() |
|
92 |
else: |
|
93 |
project = currentProject() |
|
94 |
view = project.getView(viewName) |
|
95 |
if view == None: |
|
96 |
raise RuntimeException("Can't get view with name '"+viewName+"', "+ str(ex)) |
|
97 |
view.addLayer(layer) |
|
87 | 98 |
layer.setActive(True) |
88 | 99 |
return layer |
89 |
|
|
100 |
|
|
101 |
def loadRasterFile(filename, **parameters): |
|
102 |
parameters["uri"]= File(filename).toURI() |
|
103 |
ext = os.path.splitext(filename) |
|
104 |
#if ext[1].lower() == ".jp2" or ext[1].lower()=="ecw": |
|
105 |
# layer = loadLayer("Ermapper Store", **parameters) |
|
106 |
#else: |
|
107 |
# layer = loadLayer('Gdal Store', **parameters) |
|
108 |
layer = loadLayer('Gdal Store', **parameters) |
|
109 |
viewName = parameters.get("gvViewName",None) |
|
110 |
if viewName == None: |
|
111 |
view = currentView() |
|
112 |
else: |
|
113 |
project = currentProject() |
|
114 |
view = project.getView(viewName) |
|
115 |
if view == None: |
|
116 |
raise RuntimeException("Can't get view with name '"+viewName+"', "+ str(ex)) |
|
117 |
view.addLayer(layer) |
|
118 |
layer.setActive(True) |
|
119 |
return layer |
|
120 |
|
|
90 | 121 |
def loadLayer(layerType, **parameters): |
91 | 122 |
try: |
92 | 123 |
application = ApplicationLocator.getManager() |
... | ... | |
94 | 125 |
mapcontextmanager = application.getMapContextManager() |
95 | 126 |
store_parameters = datamanager.createStoreParameters(layerType) |
96 | 127 |
copyToDynObject(parameters, store_parameters) |
97 |
store = datamanager.openStore(layerType, store_parameters) |
|
98 |
layer = mapcontextmanager.createLayer(store.getName(), store) |
|
128 |
store = datamanager.openStore(layerType, store_parameters) |
|
129 |
layerName = parameters.get("gvLayerName", store.getName()) |
|
130 |
layer = mapcontextmanager.createLayer(layerName, store) |
|
99 | 131 |
except Throwable, ex: |
100 |
raise RuntimeException("Can't load layer, "+ str(ex))
|
|
132 |
raise RuntimeException("Can't load layer, "+ str(ex)) |
|
101 | 133 |
|
102 | 134 |
return layer |
103 |
|
|
104 |
def createShape(definition, filename, geometryType, CRS="CRS:84"): |
|
135 |
|
|
136 |
def createShape(definition, filename, geometryType=None, CRS="CRS:84"):
|
|
105 | 137 |
""" |
106 |
Return new shape layer
|
|
138 |
Return new shape layer |
|
107 | 139 |
:param definition: layer data definition |
108 | 140 |
:type definition: Schema |
109 |
:param filename: absolute path for shape files.
|
|
141 |
:param filename: absolute path for shape files. |
|
110 | 142 |
:type filename: string |
111 | 143 |
:param geometryType: geometry type for shape |
112 | 144 |
:type geometryType: string |
113 | 145 |
:return: new shape layer |
114 | 146 |
:rtype: Layer |
115 | 147 |
""" |
148 |
geomattr = definition.getDefaultGeometryAttribute() |
|
149 |
if geomattr == None: |
|
150 |
raise RuntimeException("Can't create a shp without geometry attribute") |
|
151 |
if geometryType == None : |
|
152 |
geometryType = geomattr.getGeomType().getType() |
|
153 |
else: |
|
154 |
if geometryType != geomattr.getGeomType().getType(): |
|
155 |
raise RuntimeException("Can't create a shp, geoemtry mismatch.") |
|
156 |
|
|
116 | 157 |
return createLayer( |
117 |
definition,
|
|
118 |
"FilesystemExplorer",
|
|
119 |
"Shape",
|
|
120 |
shpFile=filename,
|
|
158 |
definition, |
|
159 |
"FilesystemExplorer", |
|
160 |
"Shape", |
|
161 |
shpFile=filename, |
|
121 | 162 |
CRS=CRS, |
122 | 163 |
geometryType = geometryType |
123 | 164 |
) |
... | ... | |
131 | 172 |
try: |
132 | 173 |
application = ApplicationLocator.getManager() |
133 | 174 |
datamanager = application.getDataManager() |
134 |
|
|
175 |
|
|
135 | 176 |
server_parameters = datamanager.createServerExplorerParameters(servertype) |
136 | 177 |
copyToDynObject(parameters, server_parameters) |
137 | 178 |
|
138 | 179 |
server = datamanager.openServerExplorer(servertype, server_parameters) |
139 |
|
|
180 |
|
|
140 | 181 |
store_parameters = server.getAddParameters(tableType) |
141 | 182 |
copyToDynObject(parameters, store_parameters) |
142 | 183 |
store_parameters.setDefaultFeatureType(schema()) |
143 |
|
|
184 |
|
|
144 | 185 |
server.add(tableType, store_parameters, True) |
145 | 186 |
|
146 | 187 |
store = datamanager.openStore(tableType, store_parameters) |
147 |
|
|
188 |
|
|
148 | 189 |
return store |
149 |
|
|
190 |
|
|
150 | 191 |
except Throwable, ex: |
151 | 192 |
raise RuntimeException("Can't create table, "+ str(ex)) |
152 |
|
|
193 |
|
|
153 | 194 |
def createDBF(definition, DbfFile, CRS="CRS:84"): |
154 | 195 |
""" |
155 |
Creates a new dbf document
|
|
196 |
Creates a new dbf document |
|
156 | 197 |
:param definition: layer data definition |
157 | 198 |
:type definition: Schema |
158 |
:param DbfFile: absolute path for shape files.
|
|
199 |
:param DbfFile: absolute path for shape files. |
|
159 | 200 |
:type DbfFile: string |
160 | 201 |
:return: new dbf |
161 |
:rtype: Table
|
|
202 |
:rtype: Table |
|
162 | 203 |
""" |
163 | 204 |
return createTable( |
164 |
definition,
|
|
165 |
"FilesystemExplorer",
|
|
166 |
"DBF",
|
|
167 |
DbfFile=DbfFile,
|
|
205 |
definition, |
|
206 |
"FilesystemExplorer", |
|
207 |
"DBF", |
|
208 |
DbfFile=DbfFile, |
|
168 | 209 |
CRS=CRS, |
169 | 210 |
) |
170 | 211 |
|
171 | 212 |
|
172 | 213 |
#=====================# |
173 | 214 |
# Simbology Functions # |
174 |
#=====================#
|
|
215 |
#=====================# |
|
175 | 216 |
COLORS = { |
176 | 217 |
'black': Color.black, |
177 | 218 |
'blue': Color.blue, |
... | ... | |
187 | 228 |
'white': Color.white, |
188 | 229 |
'yellow': Color.yellow, |
189 | 230 |
} |
190 |
|
|
231 |
|
|
191 | 232 |
def simplePointSymbol(color=None): |
192 | 233 |
""" |
193 |
Returns simple point symbol using parameter color. If no color
|
|
234 |
Returns simple point symbol using parameter color. If no color |
|
194 | 235 |
use a ramdom color |
195 | 236 |
:param color: String color name or Java awt Color |
196 | 237 |
:return: gvSIG point symbol |
197 | 238 |
""" |
198 | 239 |
if isinstance(color, str) and COLORS.has_key(color.lower()): |
199 | 240 |
color = COLORS.get(color) |
200 |
|
|
241 |
|
|
201 | 242 |
if not isinstance(color, Color): |
202 | 243 |
color = getDefaultColor() |
203 |
|
|
244 |
|
|
204 | 245 |
return MapContextLocator.getSymbolManager().createSymbol( |
205 | 246 |
Geometry.TYPES.POINT, color) |
206 | 247 |
|
207 | 248 |
def simpleLineSymbol(color=None): |
208 | 249 |
""" |
209 |
Returns simple line symbol using parameter color. If no color use a
|
|
210 |
ramdom color
|
|
250 |
Returns simple line symbol using parameter color. If no color use a |
|
251 |
ramdom color |
|
211 | 252 |
:param color: String color name or Java awt Color |
212 | 253 |
:return: gvSIG line symbol |
213 |
|
|
254 |
|
|
214 | 255 |
""" |
215 | 256 |
if isinstance(color, str) and COLORS.has_key(color.lower()): |
216 | 257 |
color = COLORS.get(color) |
217 | 258 |
|
218 | 259 |
if not isinstance(color, Color): |
219 | 260 |
color = getDefaultColor() |
220 |
|
|
261 |
|
|
221 | 262 |
return MapContextLocator.getSymbolManager().createSymbol( |
222 | 263 |
Geometry.TYPES.CURVE, color) |
223 | 264 |
|
224 | 265 |
def simplePolygonSymbol(color = None): |
225 | 266 |
""" |
226 |
Returns simple polygon symbol using parameter color. If no color
|
|
227 |
use a ramdom color.
|
|
267 |
Returns simple polygon symbol using parameter color. If no color |
|
268 |
use a ramdom color. |
|
228 | 269 |
:param color: String color name or Java awt Color |
229 | 270 |
:return: gvSIG polygon symbol |
230 | 271 |
""" |
... | ... | |
233 | 274 |
|
234 | 275 |
if not isinstance(color, Color): |
235 | 276 |
color = getDefaultColor() |
236 |
|
|
277 |
|
|
237 | 278 |
return MapContextLocator.getSymbolManager().createSymbol( |
238 | 279 |
Geometry.TYPES.SURFACE, color) |
239 |
|
|
240 | 280 |
|
281 |
|
|
241 | 282 |
#=========================================# |
242 | 283 |
# gvSIG Application Preferences Functions # |
243 |
#=========================================#
|
|
284 |
#=========================================# |
|
244 | 285 |
|
245 | 286 |
def getDataFolder(): |
246 | 287 |
""" |
247 |
Returns gvSIG data folder. This folder is defined in application
|
|
288 |
Returns gvSIG data folder. This folder is defined in application |
|
248 | 289 |
preferences. If is not defined returns None. |
249 | 290 |
""" |
250 | 291 |
return Preferences.userRoot().node("gvsig.foldering").get('DataFolder', None) |
251 |
|
|
292 |
|
|
252 | 293 |
def getProjectsFolder(): |
253 | 294 |
""" |
254 |
Returns gvSIG projects folder. This folder is defined in application
|
|
295 |
Returns gvSIG projects folder. This folder is defined in application |
|
255 | 296 |
preferences. If is not defined returns None. |
256 | 297 |
""" |
257 | 298 |
return Preferences.userRoot().node("gvsig.foldering").get( |
... | ... | |
259 | 300 |
|
260 | 301 |
def getColorFromRGB(r, g, b, a=None): |
261 | 302 |
""" |
262 |
Returns an sRGB color with the specified red, green, blue, and alpha
|
|
303 |
Returns an sRGB color with the specified red, green, blue, and alpha |
|
263 | 304 |
(optional) values in the range (0 - 255). |
264 | 305 |
""" |
265 | 306 |
if a: |
266 | 307 |
color = Color(r, g, b, a) |
267 | 308 |
else: |
268 | 309 |
color = Color(r, g, b) |
269 |
|
|
310 |
|
|
270 | 311 |
return color |
271 |
|
|
312 |
|
|
272 | 313 |
def getDefaultColor(c = None): |
273 | 314 |
"""Returns gvsig default symbol fill color or ramdom color""" |
274 | 315 |
if MapContextLocator.getSymbolManager().isDefaultSymbolFillColorAleatory(): |
275 |
color = Color(random.randint(0-255),
|
|
276 |
random.randint(0-255),
|
|
316 |
color = Color(random.randint(0-255), |
|
317 |
random.randint(0-255), |
|
277 | 318 |
random.randint(0-255) |
278 | 319 |
) |
279 | 320 |
else: |
280 | 321 |
sp = MapContextLocator.getSymbolManager().getSymbolPreferences() |
281 |
color = sp.getDefaultSymbolFillColor()
|
|
322 |
color = sp.getDefaultSymbolFillColor() |
|
282 | 323 |
|
283 |
return color
|
|
284 |
|
|
324 |
return color |
|
325 |
|
|
285 | 326 |
#================# |
286 | 327 |
# OTHER # |
287 | 328 |
#================# |
288 | 329 |
|
289 | 330 |
def getCRS(crs): |
290 |
"""Returns Projection from string code (i.e. CRS:84) if exist or None if
|
|
291 |
not.
|
|
331 |
"""Returns Projection from string code (i.e. CRS:84) if exist or None if |
|
332 |
not. |
|
292 | 333 |
""" |
293 | 334 |
try: |
294 | 335 |
return CRSFactory.getCRS(crs) |
... | ... | |
308 | 349 |
# ==================================== |
309 | 350 |
# |
310 | 351 |
|
352 |
""" |
|
353 |
def cloneShape(layer, target=None, expresion = None, sortby="", asc=True): |
|
354 |
if target==None: |
|
355 |
# una capa temporal en el temp de andami |
|
356 |
#... |
|
357 |
else: |
|
358 |
targetfile = File(target) |
|
359 |
if targetfile.isAbsolute(): |
|
360 |
#La guardamos ahi mismo |
|
361 |
else: |
|
362 |
# Al temp de andami con ese nombre. |
|
363 |
|
|
364 |
# Crear la nueva capa |
|
365 |
|
|
366 |
return newLayer |
|
367 |
""" |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/geom.py | ||
---|---|---|
65 | 65 |
MULTILINE = Geometry.TYPES.MULTICURVE |
66 | 66 |
MULTIPOLYGON = Geometry.TYPES.MULTISURFACE |
67 | 67 |
|
68 |
# geometrySubTypes
|
|
68 |
# geometrySubTypes |
|
69 | 69 |
D2 = Geometry.SUBTYPES.GEOM2D |
70 | 70 |
D2M = Geometry.SUBTYPES.GEOM2DM |
71 | 71 |
D3 = Geometry.SUBTYPES.GEOM3D |
72 | 72 |
D3M = Geometry.SUBTYPES.GEOM3DM |
73 | 73 |
UNKNOWN = Geometry.SUBTYPES.UNKNOWN |
74 |
|
|
74 |
|
|
75 | 75 |
def createGeometry(type, subtype=D2): |
76 | 76 |
""" |
77 |
Returns a new geometry with a concrete type and subtype or None if can't
|
|
77 |
Returns a new geometry with a concrete type and subtype or None if can't |
|
78 | 78 |
create geometry. |
79 | 79 |
:param type: geometry type |
80 | 80 |
:type type: string |
... | ... | |
89 | 89 |
except: |
90 | 90 |
return None |
91 | 91 |
return geometry |
92 |
|
|
92 |
|
|
93 | 93 |
def createPoint(x=0, y=0, subtype=D2): |
94 | 94 |
""" |
95 |
Returns a new point with a subtype and sets the value for the X and the Y
|
|
95 |
Returns a new point with a subtype and sets the value for the X and the Y |
|
96 | 96 |
coordinates (default 0,0) or None if can't create point |
97 |
:param x: X coordinate value
|
|
97 |
:param x: X coordinate value |
|
98 | 98 |
:param y: Y coordinate value |
99 | 99 |
:type x: double |
100 | 100 |
:type y: double |
101 | 101 |
:return: Point |
102 |
:rtype: Point
|
|
102 |
:rtype: Point |
|
103 | 103 |
""" |
104 | 104 |
try: |
105 | 105 |
geometryManager = GeometryLocator.getGeometryManager() |
106 | 106 |
point = geometryManager.createPoint(x, y, subtype) |
107 | 107 |
except: |
108 | 108 |
return None |
109 |
|
|
109 |
|
|
110 | 110 |
return point |
111 | 111 |
|
112 | 112 |
def createMultiPoint(subtype=D2, points=None): |
113 | 113 |
""" |
114 |
Returns a new multipoint with a subtype from a list of Points instances.
|
|
115 |
Also values of X and Y tuples like ([x1, y1], [x2, y2], ...., [xn, yn]) are
|
|
116 |
allowed. If not points returns empty multipoint geometry. If can't create
|
|
114 |
Returns a new multipoint with a subtype from a list of Points instances. |
|
115 |
Also values of X and Y tuples like ([x1, y1], [x2, y2], ...., [xn, yn]) are |
|
116 |
allowed. If not points returns empty multipoint geometry. If can't create |
|
117 | 117 |
geometry return None. |
118 | 118 |
:param points: list of points |
119 | 119 |
:type points: list |
... | ... | |
123 | 123 |
multipoint = createGeometry(MULTIPOINT, subtype) |
124 | 124 |
if all(points, multipoint): |
125 | 125 |
try: |
126 |
for point in points:
|
|
126 |
for point in points: |
|
127 | 127 |
multipoint.addPrimitive(point) |
128 | 128 |
except: |
129 | 129 |
return None |
130 |
|
|
131 |
return multipoint |
|
132 | 130 |
|
133 |
def createPolygon(subtype=D2, vertexes=None): |
|
131 |
return multipoint |
|
132 |
|
|
133 |
def createPolygon(subtype=D2, vertexes=None): |
|
134 | 134 |
""" |
135 | 135 |
Returns a new polygon with a subtype. Or None if can't create the geometry |
136 | 136 |
:return: polygon |
137 |
:rtype: Geometry
|
|
138 |
"""
|
|
137 |
:rtype: Geometry |
|
138 |
""" |
|
139 | 139 |
polygon = createGeometry(SURFACE, subtype) |
140 | 140 |
if all(vertexes, polygon): |
141 | 141 |
try: |
142 | 142 |
for vertex in vertexes: |
143 | 143 |
polygon.addPoint(vertex) |
144 |
polygon.closePrimitive() |
|
145 | 144 |
except: |
146 |
return None
|
|
145 |
return None |
|
147 | 146 |
return polygon |
148 | 147 |
|
149 |
def createMultiPolygon(subtype=D2, polygons=None):
|
|
148 |
def createMultiPolygon(subtype=D2, polygons=None): |
|
150 | 149 |
""" |
151 | 150 |
Returns a new multipolygon with a subtype. or None if can't create geometry |
152 | 151 |
:return: multipolygon |
153 | 152 |
:rtype: Geometry |
154 |
"""
|
|
153 |
""" |
|
155 | 154 |
multipolygon = createGeometry(MULTISURFACE, subtype) |
156 |
return multipolygon
|
|
157 |
|
|
158 |
def createLine(subtype=D2, vertexes=None):
|
|
155 |
return multipolygon |
|
156 |
|
|
157 |
def createLine(subtype=D2, vertexes=None): |
|
159 | 158 |
""" |
160 | 159 |
Returns a new line with a subtype or None if can't create geometry |
161 | 160 |
:return: polygon |
162 | 161 |
:rtype: Geometry |
163 |
"""
|
|
162 |
""" |
|
164 | 163 |
line = createGeometry(CURVE, subtype) |
165 | 164 |
return line |
166 | 165 |
|
167 |
def createMultiLine(subtype=D2, lines = None):
|
|
166 |
def createMultiLine(subtype=D2, lines = None): |
|
168 | 167 |
""" |
169 | 168 |
Create a new multiline with a subtype or None if can't create geometry |
170 | 169 |
:return: multiline |
171 | 170 |
:rtype: Geometry |
172 |
"""
|
|
171 |
""" |
|
173 | 172 |
multiline = createGeometry(MULTILINE, subtype) |
174 | 173 |
return multiline |
175 |
|
|
174 |
|
|
176 | 175 |
def createEnvelope(pointMax=None, pointMin=None, dimension=2): |
177 | 176 |
""" |
178 |
Returns envelope as a minimum bounding box or rectangle. This envelope is
|
|
179 |
equivalent to the GM_Envelope specified in ISO 19107.
|
|
180 |
:param pointMax:
|
|
177 |
Returns envelope as a minimum bounding box or rectangle. This envelope is |
|
178 |
equivalent to the GM_Envelope specified in ISO 19107. |
|
179 |
:param pointMax: |
|
181 | 180 |
:type pointMax: geometry POINT |
182 |
:param pointMin:
|
|
181 |
:param pointMin: |
|
183 | 182 |
:type pointMin: geometry POINT |
184 | 183 |
""" |
185 | 184 |
geometryManager = GeometryLocator.getGeometryManager() |
186 |
|
|
185 |
|
|
187 | 186 |
if all((pointMax, pointMin)): |
188 | 187 |
envelope = geometryManager.createEnvelope(pointMax, pointMin) |
189 | 188 |
else: |
190 |
envelope = geometryManager.createEnvelope()
|
|
189 |
envelope = geometryManager.createEnvelope() |
|
191 | 190 |
|
192 | 191 |
return envelope |
193 |
|
|
194 | 192 |
|
193 |
|
|
195 | 194 |
def main(): |
196 | 195 |
point = createPoint(1,1) |
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/scripts/libs/formpanel.py | ||
---|---|---|
1 | 1 |
|
2 | 2 |
import com.jeta.forms.components.panel.FormPanel |
3 | 3 |
import java.io.FileInputStream |
4 |
import java.io.File |
|
4 | 5 |
import javax.imageio.ImageIO |
5 | 6 |
import javax.swing.JButton |
6 | 7 |
import javax.swing.JComboBox |
7 | 8 |
import java.awt.event.ActionListener |
8 | 9 |
import javax.swing.SwingUtilities |
9 | 10 |
import java.lang.Runnable |
11 |
import javax.swing.ImageIcon |
|
10 | 12 |
|
11 | 13 |
|
12 | 14 |
import inspect |
... | ... | |
32 | 34 |
|
33 | 35 |
def __call__(self): |
34 | 36 |
self.__fn(*self.__args) |
35 |
|
|
36 | 37 |
|
38 |
|
|
37 | 39 |
class ProgressBarWithTaskStatus(Observer): |
38 | 40 |
def __init__(self, name, progressBar, labelProgress=None): |
39 | 41 |
self.taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus(name) |
... | ... | |
46 | 48 |
|
47 | 49 |
def getTaskStatus(self): |
48 | 50 |
return self.taskStatus |
49 |
|
|
51 |
|
|
50 | 52 |
def update(self, taskStatus, notification): |
51 | 53 |
if not javax.swing.SwingUtilities.isEventDispatchThread(): |
52 | 54 |
javax.swing.SwingUtilities.invokeLater( |
... | ... | |
63 | 65 |
taskStatus.getCompleted(), |
64 | 66 |
taskStatus.getLabel() |
65 | 67 |
) |
66 |
|
|
68 |
|
|
67 | 69 |
def updateGUI(self, isRunning, current, label): |
68 | 70 |
if not isRunning: |
69 | 71 |
self.progressBar.setIndeterminate(False); |
... | ... | |
74 | 76 |
self.progressBar.setValue(current) |
75 | 77 |
if self.labelProgress != None: |
76 | 78 |
self.labelProgress.setText(label) |
77 |
|
|
79 |
|
|
78 | 80 |
class FormPanel(object): |
79 | 81 |
|
80 | 82 |
def __init__(self,formfile=None): |
... | ... | |
87 | 89 |
|
88 | 90 |
def hide(self): |
89 | 91 |
self._panel.setVisible(False) |
90 |
|
|
92 |
|
|
91 | 93 |
def __getattr__(self, name): |
92 | 94 |
if name in ("__members__", "__methods__"): |
93 | 95 |
raise AttributeError("FormPanel",name) |
... | ... | |
95 | 97 |
if attr == None: |
96 | 98 |
raise AttributeError("FormPanel",name) |
97 | 99 |
return attr |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
100 | 102 |
def load(self, formfile): |
101 | 103 |
self._panel = com.jeta.forms.components.panel.FormPanel( java.io.FileInputStream(formfile) ) |
102 | 104 |
members = inspect.getmembers(self) |
... | ... | |
110 | 112 |
component.addActionListener(ComboBoxActionListener(value)) |
111 | 113 |
else: |
112 | 114 |
print component |
113 |
|
|
115 |
|
|
114 | 116 |
def load_image(self, afile): |
117 |
if not isinstance(afile,java.io.File): |
|
118 |
afile = java.io.File(str(afile)) |
|
115 | 119 |
return javax.imageio.ImageIO.read(afile) |
116 | 120 |
|
117 |
def showWindow(self, title): |
|
121 |
def load_icon(self, afile): |
|
122 |
if not isinstance(afile,java.io.File): |
|
123 |
afile = java.io.File(str(afile)) |
|
124 |
return javax.swing.ImageIcon(javax.imageio.ImageIO.read(afile)) |
|
125 |
|
|
126 |
def showWindow(self, title): |
|
118 | 127 |
windowManager = ToolsSwingLocator.getWindowManager() |
119 | 128 |
windowManager.showWindow(self._panel,title, windowManager.MODE.WINDOW) |
120 | 129 |
|
121 |
def showTool(self, title):
|
|
130 |
def showTool(self, title): |
|
122 | 131 |
windowManager = ToolsSwingLocator.getWindowManager() |
123 | 132 |
windowManager.showWindow(self._panel,title, windowManager.MODE.TOOL) |
124 | 133 |
|
Also available in: Unified diff