gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / scripts / examples / monitor / monitor_suma1.py @ 475
History | View | Annotate | Download (1.07 KB)
1 |
|
---|---|
2 |
from gvsig import * |
3 |
from commonsdialog import * |
4 |
|
5 |
"""
|
6 |
Para probar este ejemplo cargue la capa MANZANAS_POB de la carpeta
|
7 |
data y seleccionela en el TOC
|
8 |
"""
|
9 |
|
10 |
def calcular_sumatorio(mapContext, layer, fieldname): |
11 |
encuadre = mapContext.getViewPort().getEnvelope().getGeometry() |
12 |
lineas = layer.getFeatureStore().getFeatureSet().iterator() |
13 |
suma = 0
|
14 |
for linea in lineas: |
15 |
g = linea.getDefaultGeometry() |
16 |
if encuadre.intersects(g) :
|
17 |
suma += int(linea.get(fieldname))
|
18 |
print "Sumatorio de %s: %s" % (fieldname, suma) |
19 |
|
20 |
def main(*args): |
21 |
if currentView() == None: |
22 |
msgbox("Debera tener una vista abierta y activa")
|
23 |
return
|
24 |
mapContext = currentView().getMapContext() |
25 |
|
26 |
layer = currentLayer() |
27 |
if layer == None: |
28 |
msgbox("Debera tener seleccionada la capa sobre la que desea trabajar")
|
29 |
return
|
30 |
fieldname = inputbox( |
31 |
"Introduzca el nombre del campo para calcular el sumatorio",
|
32 |
"Nombre de campo",
|
33 |
QUESTION, |
34 |
"pob_total"
|
35 |
) |
36 |
if fieldname in ("",None): |
37 |
msgbox("Operacion cancelada")
|
38 |
return
|
39 |
calcular_sumatorio(mapContext, layer, fieldname) |
40 |
|