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 / vectorial_data / 01_maximun_and_minimun_elevation.py @ 462
History | View | Annotate | Download (1.87 KB)
1 |
|
---|---|
2 |
__author__ = """Victor Acevedo Royer <vacevedor@gvsig.com>,
|
3 |
<vacevedor@gmail.com>"""
|
4 |
|
5 |
__docformat__ = 'plaintext'
|
6 |
|
7 |
import gvsig |
8 |
import commonsdialog |
9 |
|
10 |
|
11 |
|
12 |
def main(): |
13 |
"""
|
14 |
This script runs all the features of the active layer, and calculates the
|
15 |
maximum and minimum elevation these, and with this:
|
16 |
- Shows a message informing the user which are
|
17 |
|
18 |
If no ELEVATION field shows a message and finish script execution.
|
19 |
|
20 |
In the data folder can be found cv05_3d_polygons layer used
|
21 |
for testing with this script.
|
22 |
"""
|
23 |
|
24 |
#
|
25 |
#Invoke gvsig.currentLayer function to get active layer
|
26 |
#If not view or active layer in view raise RuntimeException
|
27 |
layer = gvsig.currentLayer() |
28 |
|
29 |
#
|
30 |
#Invoke layer.getSchema method to get layer definition data
|
31 |
schema = layer.getSchema() |
32 |
|
33 |
#
|
34 |
#Invoke schema.get method to get ELEVATION field or None
|
35 |
field = schema.get('ELEVATION', None) |
36 |
|
37 |
#
|
38 |
#Check if field exist
|
39 |
if not field: |
40 |
#If not shows message and finish
|
41 |
text = '"ELEVATION" field must exist in the active layer.\nFinish script'
|
42 |
title = "ERROR"
|
43 |
message_type = commonsdialog.WARNING |
44 |
commonsdialog.msgbox(text, title, message_type) |
45 |
return
|
46 |
|
47 |
emax = 0.0
|
48 |
emin = 0.0
|
49 |
|
50 |
#
|
51 |
# Gets features using layer.features method
|
52 |
features = layer.features() |
53 |
|
54 |
#
|
55 |
#Runs layer features
|
56 |
for feature in features: |
57 |
#
|
58 |
# Cheacks if current feature ELEVATION is higher than calculated.
|
59 |
# If so stored current ELEVATION value
|
60 |
if feature.ELEVATION > emax :
|
61 |
emax = feature.ELEVATION |
62 |
#
|
63 |
# Same but with minimum ELEVATION
|
64 |
if feature.ELEVATION < emin or emin ==0.0: |
65 |
emin = feature.ELEVATION |
66 |
#
|
67 |
# Finally show results in a msgbox message.
|
68 |
text = "Maximum Elevation=%s, Minumun Elevation=%s" % (emax, emin)
|
69 |
title = "Maximun and minumum values"
|
70 |
message_type = commonsdialog.IDEA |
71 |
|
72 |
commonsdialog.msgbox(text, title, message_type) |
73 |
|