gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / scripts / libs / toolbox.py @ 468
History | View | Annotate | Download (4.4 KB)
1 |
#
|
---|---|
2 |
# ==========================================================
|
3 |
#
|
4 |
# Declara la clase ToolboxProcess y declara una serie de
|
5 |
# constantes de utilidad para ser usadas en la creacion
|
6 |
# de geoprocesos.
|
7 |
# La clase ToolboxProcess esta pensada para ser usada como
|
8 |
# clase base para crear procesos desde scripting con python.
|
9 |
#
|
10 |
#
|
11 |
# Usar la siguiente linea para importar el FormPanel de este modulo
|
12 |
#
|
13 |
# import_from_module("libs.toolbox","*")
|
14 |
#
|
15 |
# Antes debe haberse cargado el modulo "import_utils".
|
16 |
#
|
17 |
|
18 |
|
19 |
#
|
20 |
# Declaramos que vamos a usar el plugin de geoprocesos
|
21 |
# e importamos los modulos que vamos a necesitar.
|
22 |
#
|
23 |
|
24 |
from use_plugin import * |
25 |
|
26 |
use_plugin("org.gvsig.geoprocess.app.mainplugin")
|
27 |
|
28 |
from org.gvsig.geoprocess.lib.sextante import AbstractSextanteGeoProcess |
29 |
from es.unex.sextante.outputs import OutputVectorLayer |
30 |
from es.unex.sextante.dataObjects import IVectorLayer |
31 |
from es.unex.sextante.additionalInfo import AdditionalInfoNumericalValue |
32 |
from org.gvsig.geoprocess.lib.api import GeoProcessLocator |
33 |
from es.unex.sextante.gui.core import SextanteGUI |
34 |
from org.gvsig.tools.dispose import DisposeUtils |
35 |
from es.unex.sextante.core import Sextante |
36 |
|
37 |
|
38 |
SHAPE_TYPE_POINT = IVectorLayer.SHAPE_TYPE_POINT |
39 |
SHAPE_TYPE_LINE = IVectorLayer.SHAPE_TYPE_LINE |
40 |
SHAPE_TYPE_POLYGON = IVectorLayer.SHAPE_TYPE_POLYGON |
41 |
SHAPE_TYPE_MIXED = IVectorLayer.SHAPE_TYPE_MIXED |
42 |
SHAPE_TYPE_MULTIPOINT = IVectorLayer.SHAPE_TYPE_MULTIPOINT |
43 |
SHAPE_TYPE_MULTILINE = IVectorLayer.SHAPE_TYPE_MULTILINE |
44 |
SHAPE_TYPE_MULTIPOLYGON = IVectorLayer.SHAPE_TYPE_MULTIPOLYGON |
45 |
SHAPE_TYPE_WRONG = IVectorLayer.SHAPE_TYPE_WRONG |
46 |
SHAPE_TYPE_UNDEFINED = SHAPE_TYPE_WRONG |
47 |
|
48 |
NUMERICAL_VALUE_INTEGER = AdditionalInfoNumericalValue.NUMERICAL_VALUE_INTEGER |
49 |
NUMERICAL_VALUE_DOUBLE = AdditionalInfoNumericalValue.NUMERICAL_VALUE_DOUBLE |
50 |
|
51 |
class ToolboxProcess(AbstractSextanteGeoProcess): |
52 |
|
53 |
def __init__(self): |
54 |
self.__maxrange = 0 |
55 |
self.__countrange = 0 |
56 |
|
57 |
def getCommandLineName(self): |
58 |
"""
|
59 |
Este metodo debe ser sobreescrito en Jython para que funcione correctamente el geoproceso.
|
60 |
No se debe sobreescribir en nuestro geoproceso.
|
61 |
"""
|
62 |
return self.__class__.__name__ |
63 |
|
64 |
def getNewInstance(self): |
65 |
"""
|
66 |
Este metodo debe ser sobreescrito en Jython para que funcione correctamente el geoproceso.
|
67 |
No se debe sobreescribir en nuestro geoproceso.
|
68 |
"""
|
69 |
alg = self.__class__()
|
70 |
alg.setName(self.getName())
|
71 |
alg.setGroup(self.getGroup())
|
72 |
|
73 |
alg.setParameters(self.getParameters().getNewInstance())
|
74 |
alg.setOutputObjects(self.getOutputObjects().getNewInstance())
|
75 |
return alg;
|
76 |
|
77 |
def setRangeOfValues(self,start,end): |
78 |
"""
|
79 |
Metodo que debe ser invocado para fijar los limites de la iteracion del geoproceso.
|
80 |
Se encarga de actualizar las barras de progreso asociadas a nuestros geoprocesos.
|
81 |
"""
|
82 |
self.__maxrange = end
|
83 |
self.__countrange = 0 |
84 |
self.getStatus().setRangeOfValues(1,end) |
85 |
self.setProgress(0, end) |
86 |
|
87 |
def next(self): |
88 |
"""
|
89 |
Incrementa el progreso de nuestro proceso.
|
90 |
"""
|
91 |
self.__countrange+=1 |
92 |
self.setCurValue(self.__countrange) |
93 |
|
94 |
def isCanceled(self): |
95 |
"""
|
96 |
Nos informa si el usuario a cancelado el proceso.
|
97 |
"""
|
98 |
return self.getTaskMonitor().isCanceled() |
99 |
|
100 |
def setCurValue(self,current): |
101 |
"""
|
102 |
Fija el progreso de nuestro proceso en el valor indicado como parametro.
|
103 |
"""
|
104 |
self.getStatus().setCurValue(current)
|
105 |
self.setProgress(current, self.__maxrange); |
106 |
|
107 |
def createNewFeature(self, store, feature=None): |
108 |
"""
|
109 |
Crea una nueva feature o entidad asociada al almacen (store) pasado como parametro.
|
110 |
Esta nueva feature podra ser insertada en el almancen inficado como parametro.
|
111 |
Si se ha indicado como parametro una feature, se copiaran los datos de esta sobre la nueva.
|
112 |
"""
|
113 |
newfeature = store.createNewFeature() |
114 |
if feature!=None: |
115 |
for field in newfeature.getType().iterator(): |
116 |
try:
|
117 |
value = feature.get(field.getName()) |
118 |
newfeature.set(field.getName(), value) |
119 |
except:
|
120 |
# Ignoramos errores ya que es facil que hayan campo que no existen en una u otra
|
121 |
# feature o que no son del mismo tipo.
|
122 |
pass
|
123 |
return newfeature
|
124 |
|
125 |
def selfregister(self, groupname): |
126 |
"""
|
127 |
Registra el geoproceso en la lista de geoprocesos disponibles.
|
128 |
"""
|
129 |
Sextante.addGeoalgorithm(groupname,self.__class__())
|
130 |
|
131 |
def updateToolbox(self): |
132 |
"""
|
133 |
Fuerza que se actualize el interface de usuario de la Toolbox.
|
134 |
"""
|
135 |
SextanteGUI.getGUIFactory().updateToolbox() |
136 |
|
137 |
#
|
138 |
# ==========================================================
|
139 |
|