Publicado el 6 de Junio del 2018
2.004 visualizaciones desde el 6 de Junio del 2018
618,8 KB
109 paginas
Creado hace 7a (08/08/2017)
"
PyQGIS developer cookbook
Publicación 2.14
QGIS Project
08 de August de 2017
Contents
1 Introducción
1.1
.
1.2
1.3
.
1.4 Aplicaciones Python .
Ejecutar código Python cuando QGIS inicie . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Consola Python .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
Python Plugins .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2 Cargar proyectos
3 Cargar capas
3.1
3.2
3.3
.
Capas Vectoriales .
Capas ráster
.
.
Registro de capa de mapa
.
.
.
.
.
.
4 Usar las capas ráster
Renderizador .
4.1 Detalles de la capa .
.
4.2
.
4.3 Actualizar capas .
.
4.4 Valores de consulta .
.
.
.
.
.
.
.
.
.
5 Usar capas vectoriales
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
5.1
Recuperando información sobre atributos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Selecting features .
.
5.3
Iterando sobre la capa vectorial
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.4 Modifying Vector Layers .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
5.5 Modifying Vector Layers with an Editing Buffer
. . . . . . . . . . . . . . . . . . . . . . . . . .
5.6 Usar índice espacial
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.7 Writing Vector Layers .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.8 Memory Provider .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.9 Appearance (Symbology) of Vector Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5.10 Más Temas .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
6 Manejo de Geometría
Construcción de Geometría
.
6.1
6.2 Acceso a Geometría .
.
6.3 Geometría predicados y Operaciones
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
7 Soporte de Proyecciones
7.1
7.2
Sistemas de coordenadas de referencia
Proyecciones .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
8 Usando el Lienzo de Mapa
Lienzo de mapa insertado .
8.1
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8.2 Utilizar las herramientas del mapa con el lienzo . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
1
1
2
2
3
7
9
9
11
11
13
13
13
15
15
17
17
18
18
20
21
22
23
24
25
32
33
33
34
34
37
37
38
39
40
40
i
8.3
8.4
8.5
Bandas elásticas y marcadores de vértices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Escribir herramientas de mapa personalizados . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Escribir elementos de lienzo de mapa personalizado . . . . . . . . . . . . . . . . . . . . . . . .
9 Representación del Mapa e Impresión
9.1
9.2
9.3
Representación Simple .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Representando capas con diferente SRC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Producción usando el Diseñador de impresión . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
10 Expresiones, Filtros y Calculando Valores
10.1 Análisis de expresiones
.
10.2 Evaluar expresiones
10.3 Ejemplos .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
11 Configuración de lectura y almacenamiento
12 Comunicarse con el usuario
12.1 Mostrar mensajes. La :class:‘QgsMessageBar‘class .
12.2 Mostrando el progreso .
.
12.3 Registro .
. . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
13 Desarrollo de Plugins Python
13.1 Escribir un complemento .
.
13.2 Contenido del complemento .
.
13.3 Documentación .
13.4 Traducción .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14 Configuración IDE para escribir y depurar complementos
14.1 Una nota sobre la configuración su IDE sobre Windows
. . . . . . . . . . . . . . . . . . . . . .
14.2 Depure utilizando eclipse y PyDev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14.3 Depure utilizando PDB .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
15 Utilizar complemento Capas
15.1 Subclassing QgsPluginLayer .
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16 Compatibilidad con versiones antiguas de QGIS
16.1 Menu de plugins .
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17 Compartiendo sus plugins
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.1 Metadatos y nombres .
17.2 Code and help .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
17.3 Repositorio oficial de complemento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
18 Fragmentos de código
18.1 Cómo llamar a un método por un atajo de teclado . . . . . . . . . . . . . . . . . . . . . . . . . .
18.2 Como alternar capas .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18.3 Cómo acceder a la tabla de atributos de los objetos espaciales seleccionados . . . . . . . . . . . .
.
.
.
.
.
19 Escribir nuevos complementos de procesamiento
19.1 Crear un complemento que incluya un proveedor de algoritmos
. . . . . . . . . . . . . . . . . .
19.2 Crear un complemento que contenga una serie de scripts de procesamiento . . . . . . . . . . . .
20 Biblioteca de análisis de redes
.
.
.
20.1 Información general
20.2 Contruir un gráfico .
20.3 Análisis gráfico .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21 Complementos de Python de QGIS Server
21.1 Server Filter Plugins architecture
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21.2 Raising exception from a plugin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
ii
41
42
44
45
45
46
46
49
50
50
51
53
55
55
56
57
59
60
61
65
65
67
67
68
72
73
73
75
75
77
77
77
78
81
81
81
82
83
83
83
85
85
85
87
93
93
95
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21.3 Writing a server plugin .
21.4 Complemento control de acceso . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
Índice
95
98
101
iii
iv
CHAPTER 1
Introducción
• Ejecutar código Python cuando QGIS inicie
– variable de entorno PYQGIS_STARTUP
– El fichero startup.py
• Consola Python
• Python Plugins
• Aplicaciones Python
– Usando PyQGIS en scripts individuales
– Usando PyQGIS en aplicaciones personalizadas
– Running Custom Applications
Este documento pretende funcionar como un tutorial y como una guía referencia. Aunque no muestra todos los
posibles casos de uso, debería dar una buena perspectiva de la funcionalidad principal.
Starting from 0.9 release, QGIS has optional scripting support using Python language. We’ve decided for Python
as it’s one of the most favourite languages for scripting. PyQGIS bindings depend on SIP and PyQt4. The reason
for using SIP instead of more widely used SWIG is that the whole QGIS code depends on Qt libraries. Python
bindings for Qt (PyQt) are done also using SIP and this allows seamless integration of PyQGIS with PyQt.
There are several ways how to use Python bindings in QGIS desktop, they are covered in detail in the following
sections:
• automatically run Python code when QGIS starts
• Comandos de objeto en la consola Python con QGIS
• Crear y usar extensiones en Python
• Crear aplicaciones personalizadas basadas en la API de QGIS
Python bindings are also available for QGIS Server:
• starting from 2.8 release, Python plugins are also available on QGIS Server (see: Server Python Plugins)
• starting from 2.11 version (Master at 2015-08-11), QGIS Server library has Python bindings that can be
used to embed QGIS Server into a Python application.
There is a complete QGIS API reference that documents the classes from the QGIS libraries. Pythonic QGIS API
is nearly identical to the API in C++.
A good resource when dealing with plugins is to download some plugins from plugin repository and examine their
code. Also, the python/plugins/ folder in your QGIS installation contains some plugin that you can use to
learn how t
Comentarios de: PyQGIS developer cookbook (0)
No hay comentarios