126 |
151 |
152 |
162 |
163 |
164 |
165 |
166 |
167 | «
1:110m Cultural Vectors
168 | «
Downloads
169 |
170 |
Admin 0 – Countries
171 |
172 |
183 |
184 |

185 |
About
186 |
Countries distinguish between metropolitan (homeland) and independent and semi-independent portions of sovereign states. If you want to see the dependent overseas regions broken out (like in ISO codes, see France for example), use map units instead.
187 |
Each country is coded with a world region that roughly follows the United Nations setup.
188 |
Includes some thematic data from the United Nations, U.S. Central Intelligence Agency, and elsewhere.
189 |
Disclaimer
190 |
Natural Earth Vector draws boundaries of countries according to defacto status. We show who actually controls the situation on the ground. Please feel free to mashup our disputed areas (link) theme to match your particular political outlook.
191 |
Known Problems
192 |
None.
193 |
Version History
194 |
195 | -
196 | 4.0.0
197 |
198 | -
199 | 2.0.0
200 |
201 | -
202 | 1.4.0
203 |
204 | -
205 | 1.3.0
206 |
207 | -
208 | 1.1.0
209 |
210 | -
211 | 1.0.0
212 |
213 |
214 |
215 |
The master changelog is available on Github »
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
335 |
336 |
337 |
338 |
400 |
401 |
402 |
403 |
404 |
--------------------------------------------------------------------------------
/datos/ne_110m_admin_0_countries.cpg:
--------------------------------------------------------------------------------
1 | UTF-8
--------------------------------------------------------------------------------
/datos/ne_110m_admin_0_countries.dbf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/volaya/curso-qgis-python/c141d27bbf809b53209e818faad0afed251d50a2/datos/ne_110m_admin_0_countries.dbf
--------------------------------------------------------------------------------
/datos/ne_110m_admin_0_countries.prj:
--------------------------------------------------------------------------------
1 | GEOGCS["WGS84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.017453292519943295]]
--------------------------------------------------------------------------------
/datos/ne_110m_admin_0_countries.shp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/volaya/curso-qgis-python/c141d27bbf809b53209e818faad0afed251d50a2/datos/ne_110m_admin_0_countries.shp
--------------------------------------------------------------------------------
/datos/ne_110m_admin_0_countries.shx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/volaya/curso-qgis-python/c141d27bbf809b53209e818faad0afed251d50a2/datos/ne_110m_admin_0_countries.shx
--------------------------------------------------------------------------------
/enlaces.md:
--------------------------------------------------------------------------------
1 | https://github.com/volaya/plugin-writing-course/blob/master/plugins.rst
2 |
3 | http://blog.habrador.com/2013/02/how-to-generate-random-terrain.html
4 |
5 | http://www.geoinformations.developpement-durable.gouv.fr/fichier/pdf/FOAD_Fonction_Action_cle7fa658.pdf?arg=177833603&cle=1034f2aebb6d17e1cd1b671336dbb55c7c6c595c&file=pdf%2FFOAD_Fonction_Action_cle7fa658.pdf
6 |
7 | https://github.com/wonder-sk/qgis-minimal-plugin
8 |
--------------------------------------------------------------------------------
/materiales/acciones/scripts.py:
--------------------------------------------------------------------------------
1 | import urllib
2 | import webbrowser
3 |
4 | url = "https://en.wikipedia.org/wiki/" + "[%wikipedia%]"
5 | try:
6 | urllib.request.urlopen(url)
7 | webbrowser.open(url, new=0, autoraise=True)
8 | except:
9 | QtGui.QMessageBox.warning(None, "Wrong value", "The corresponding Wikipedia page does not exist")
10 |
11 |
12 |
--------------------------------------------------------------------------------
/materiales/expresiones/scripts.py:
--------------------------------------------------------------------------------
1 | from qgis.core import *
2 | from qgis.gui import *
3 |
4 | @qgsfunction(args="auto", group="Custom", usesgeometry=True)
5 | def hemisphere(geom, feature, parent):
6 | box = geom.boundingBox()
7 | if box.yMinimum() > 0 and box.yMaximum() > 0:
8 | return "N"
9 | if box.yMinimum() <= 0 and box.yMaximum() <= 0:
10 | return "S"
11 | else:
12 | return "B"
13 |
14 | ## usar expresión para color
15 |
--------------------------------------------------------------------------------
/materiales/formularios/wikipedia.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/volaya/curso-qgis-python/c141d27bbf809b53209e818faad0afed251d50a2/materiales/formularios/wikipedia.py
--------------------------------------------------------------------------------
/materiales/formularios/wikipedia.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Form
4 |
5 |
6 |
7 | 0
8 | 0
9 | 264
10 | 284
11 |
12 |
13 |
14 | Form
15 |
16 |
17 | -
18 |
19 |
20 | Qt::Vertical
21 |
22 |
23 |
24 | 17
25 | 12
26 |
27 |
28 |
29 |
30 | -
31 |
32 |
33 | Wikipedia id
34 |
35 |
36 |
37 | -
38 |
39 |
-
40 |
41 |
42 | -
43 |
44 |
45 | Validate
46 |
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 | Qt::Vertical
55 |
56 |
57 |
58 | 17
59 | 12
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/materiales/hooks/colorramp.py:
--------------------------------------------------------------------------------
1 | import os
2 | from qgis.core import *
3 | from qgis.PyQt.QtGui import QColor
4 | from processing.core.outputs import OutputVector, OutputRaster, OutputFile
5 |
6 | NUM_INTERVALS = 5
7 |
8 | def createStyle(layer):
9 | areas = [f["area"] for f in layer.getFeatures()]
10 | minarea = min(areas)
11 | maxarea = max(areas)
12 | interval = (maxarea - minarea) / NUM_INTERVALS
13 | colorInterval = 255 / NUM_INTERVALS
14 |
15 | ranges = []
16 | for i in xrange(NUM_INTERVALS):
17 | symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
18 | value = 255- colorInterval * i
19 | symbol.setColor(QColor(value, value, value))
20 | rng = QgsRendererRangeV2(minarea + interval * i, minarea + interval * (i + 1), symbol, "class " + str(i+1))
21 | ranges.append(rng)
22 |
23 | renderer = QgsGraduatedSymbolRendererV2("area", ranges)
24 | layer.setRendererV2(renderer)
25 | source = layer.source()
26 | styleFile = os.path.splitext(layer.source())[0] + ".qml"
27 | layer.saveNamedStyle(styleFile)
28 |
29 | for output in alg.outputs:
30 | print output.value
31 | if isinstance(output, (OutputVector)):
32 | dirname, basename = os.path.split(output.value)
33 | layer = QgsVectorLayer(output.value, "layer", "ogr")
34 | fields = [f.name().lower() for f in layer.fields()]
35 | if "area" in fields:
36 | createStyle(layer)
37 |
38 |
39 |
--------------------------------------------------------------------------------
/materiales/hooks/projectmacros.py:
--------------------------------------------------------------------------------
1 | from qgis.utils import iface
2 | from qgis.gui import QgsMessageBar
3 | from qgis.core import Qgis
4 |
5 | def openProject():
6 | iface.messageBar().pushMessage(
7 | "Warning",
8 | "This project contains classified data. Don't distribute it",
9 | Qgis.Warning,
10 | 10
11 | )
12 |
13 | from qgis.core import QgsProject
14 | import shutil
15 | from subprocess import call
16 |
17 | REPO_FOLDER = "repo_folder"
18 | def saveProject():
19 | projFile = QgsProject.instance().fileName()
20 | scope = QgsExpressionContextUtils.projectScope()
21 | if not scope.hasVariable(REPO_FOLDER):
22 | return
23 | call("git pull".split(" "))
24 |
25 | repoFolder = scope.variable(REPO_FOLDER):
26 | destFile = os.path.join(repoFolder, os.path.basename(projFile))
27 | shutil.copyfile(projFile, destFile)
28 |
29 | call("git add .".split(" "))
30 | call("git commit -m 'updated QGIS project file'".split(" "))
31 | call("git push".split(" "))
32 |
--------------------------------------------------------------------------------
/materiales/maptips/script.py:
--------------------------------------------------------------------------------
1 | import urllib
2 | import json
3 | from qgis.core import *
4 | from qgis.gui import *
5 |
6 | @qgsfunction(args="auto", group="Custom")
7 | def wikipediaSummary(name, feature, parent):
8 | baseurl = 'https://en.wikipedia.org/w/api.php?'
9 | params={
10 | 'action': 'query',
11 | 'format': 'json',
12 | 'titles': name,
13 | 'prop': 'extracts',
14 | 'exintro': True,
15 | 'explaintext': True,
16 | }
17 | url = baseurl + urllib.parse.urlencode(params)
18 | try:
19 | response = urllib.request.urlopen(url)
20 | sresults = response.read()
21 | results = json.loads(sresults)
22 | extract = list(results['query']['pages'].values())[0]['extract']
23 | return extract
24 | except Exception:
25 | return "No wikipedia entry was found"
26 |
27 | '''
28 |
31 |
32 | [% wikipediaSummary(“wikipedia”) %]
33 |
34 | '''
35 |
--------------------------------------------------------------------------------
/materiales/para_empezar/ejercicios.txt:
--------------------------------------------------------------------------------
1 | Crear capa vectorial aleatoria
2 | Crear una capa en memoria
3 | Copiar contenido de una capa vectorial a otra capa en memoria
4 | Copiar ciertas entidades de una capa a otra
5 | Editar una capa
6 | CRSs
7 | Reproyectar geometrías
8 |
--------------------------------------------------------------------------------
/materiales/para_empezar/scripts.py:
--------------------------------------------------------------------------------
1 | layer = iface.activeLayer()
2 | features = layer.getFeatures()
3 | totalPopulation = 0
4 | for feat in features:
5 | pop = feat["pop_est"]
6 | if pop > 0:
7 | totalPopulation += pop
8 |
9 | print (totalPopulation)
10 |
11 | ##################
12 |
13 | layer = iface.activeLayer()
14 | features = layer.getFeatures()
15 | totalPopulation = {}
16 | for feat in features:
17 | pop = feat["pop_est"]
18 | continent = feat["continent"]
19 | if pop > 0:
20 | if continent in totalPopulation:
21 | totalPopulation[continent] += pop
22 | else:
23 | totalPopulation[continent] = pop
24 | print (totalPopulation)
25 |
26 |
27 | #####
28 |
29 |
30 | from qgis.PyQt.QtCore import QVariant
31 |
32 | def hemisphere(geom):
33 | box = geom.boundingBox()
34 | if box.yMinimum() > 0 and box.yMaximum() > 0:
35 | return "N"
36 | if box.yMinimum() <= 0 and box.yMaximum() <= 0:
37 | return "S"
38 | else:
39 | return "A"
40 |
41 | layer = iface.activeLayer()
42 | provider = layer.dataProvider()
43 | provider.addAttributes([QgsField("hemisphere", QVariant.String)])
44 | layer.updateFields()
45 | idxField = layer.fieldNameIndex("hemisphere")
46 | features = layer.getFeatures()
47 |
48 | for feat in features:
49 | geom = feat.geometry()
50 | hemi = hemisphere(geom)
51 | provider.changeAttributeValues({feat.id() : {idxField: hemi}})
52 |
--------------------------------------------------------------------------------
/materiales/plugin/__init__.py:
--------------------------------------------------------------------------------
1 | import os
2 | import re
3 | from qgis.PyQt import uic
4 | from qgis.PyQt.QtGui import *
5 | from qgis.PyQt.QtCore import *
6 |
7 | def classFactory(iface):
8 | return RegexPlugin(iface)
9 |
10 | def selectByRegex(layer, field, regex):
11 | exp = re.compile(regex)
12 | features = layer.getFeatures()
13 | ids = []
14 | for feature in features:
15 | if exp.search(feature[field]):
16 | ids.append(feature.id())
17 | layer.selectByIds(ids)
18 |
19 |
20 | class RegexPlugin:
21 | def __init__(self, iface):
22 | self.iface = iface
23 |
24 | def initGui(self):
25 | self.action = QAction(u'Regex', self.iface.mainWindow())
26 | self.action.triggered.connect(self.run)
27 | self.iface.addToolBarIcon(self.action)
28 |
29 | def unload(self):
30 | self.iface.removeToolBarIcon(self.action)
31 | del self.action
32 |
33 | def run(self):
34 | dialog = RegexDialog()
35 | dialog.exec_()
36 | if dialog.layer:
37 | selectByRegex(dialog.layer, dialog.field, dialog.regex)
38 |
39 | WIDGET, BASE = uic.loadUiType(
40 | os.path.join(os.path.dirname(__file__), 'plugin.ui'))
41 |
42 | class RegexDialog(BASE, WIDGET):
43 |
44 | def __init__(self):
45 | super(RegexDialog, self).__init__(None)
46 | self.layer = None
47 | self.setupUi(self)
48 | self.layerCombo.layerChanged.connect(layerChanged)
49 | self.buttonSelect.clicked.connect(self.selectClicked)
50 |
51 | def layerChanged(self, layer):
52 | self.fieldCombo.setLayer(layer)
53 |
54 | def selectClicked(self):
55 | layer = self.layerCombo.currentLayer()
56 | field = self.fieldCombo.currentField()
57 | expression = self.textExpression.text()
58 | selectByRegex(layer, field, expression)
--------------------------------------------------------------------------------
/materiales/plugin/metadata.txt:
--------------------------------------------------------------------------------
1 | [general]
2 | name=Minimal
3 | description=Minimal plugin
4 | version=1.0
5 | qgisMinimumVersion=2.0
6 | author=Martin Dobias
7 | email=wonder.sk@gmail.com
8 |
--------------------------------------------------------------------------------
/materiales/plugin/plugin.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | Dialog
4 |
5 |
6 |
7 | 0
8 | 0
9 | 400
10 | 200
11 |
12 |
13 |
14 | Dialog
15 |
16 |
17 | -
18 |
19 |
20 | QgsMapLayerProxyModel::HasGeometry|QgsMapLayerProxyModel::LineLayer|QgsMapLayerProxyModel::NoGeometry|QgsMapLayerProxyModel::PluginLayer|QgsMapLayerProxyModel::PointLayer|QgsMapLayerProxyModel::PolygonLayer|QgsMapLayerProxyModel::VectorLayer|QgsMapLayerProxyModel::WritableLayer
21 |
22 |
23 |
24 | -
25 |
26 |
27 | -
28 |
29 |
30 | -
31 |
32 |
33 | Select
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | QgsFieldComboBox
42 | QComboBox
43 |
44 |
45 |
46 | QgsMapLayerComboBox
47 | QComboBox
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/materiales/processing/randompoints.py:
--------------------------------------------------------------------------------
1 | from qgis.PyQt.QtCore import QCoreApplication, QVariant
2 | from qgis.core import (QgsField, QgsFeature, QgsFeatureSink, QgsFeatureRequest,
3 | QgsProcessing, QgsProcessingAlgorithm, QgsProcessingParameterFeatureSource,
4 | QgsProcessingParameterFeatureSink, QgsProcessingParameterNumber,
5 | QgsProcessingParameterExtent, QgsProcessingParameterCrs, QgsFields,
6 | QgsWkbTypes, QgsGeometry, QgsPointXY)
7 | import random
8 |
9 | class RandomPointsAlgorithm(QgsProcessingAlgorithm):
10 | EXTENT = 'EXTENT'
11 | COUNT = 'COUNT'
12 | OUTPUT = 'OUTPUT'
13 | CRS = "CRS"
14 |
15 | def __init__(self):
16 | super().__init__()
17 |
18 | def name(self):
19 | return "randompoints"
20 |
21 | def tr(self, text):
22 | return QCoreApplication.translate("randompoints", text)
23 |
24 | def displayName(self):
25 | return self.tr("Random Points")
26 |
27 | def group(self):
28 | return self.tr("Examples")
29 |
30 | def groupId(self):
31 | return "examples"
32 |
33 | def shortHelpString(self):
34 | return self.tr("Creates a layer with random points")
35 |
36 | def helpUrl(self):
37 | return "https://qgis.org"
38 |
39 | def createInstance(self):
40 | return type(self)()
41 |
42 | def initAlgorithm(self, config=None):
43 | self.addParameter(QgsProcessingParameterNumber(
44 | self.COUNT,
45 | self.tr("Point count"),
46 | QgsProcessingParameterNumber.Integer,
47 | 1, False, 1, 1000000000))
48 | self.addParameter(QgsProcessingParameterExtent(
49 | self.EXTENT,
50 | self.tr("Extent")))
51 | self.addParameter(QgsProcessingParameterCrs(
52 | self.CRS,
53 | self.tr("Crs")))
54 | self.addParameter(QgsProcessingParameterFeatureSink(
55 | self.OUTPUT,
56 | self.tr("Output layer"),
57 | QgsProcessing.TypeVectorPoint))
58 |
59 | def processAlgorithm(self, parameters, context, feedback):
60 | extent = self.parameterAsExtent(parameters, self.EXTENT, context)
61 | count = int(self.parameterAsDouble(parameters, self.COUNT, context))
62 | crs = self.parameterAsCrs(parameters, self.CRS, context)
63 |
64 | fields = QgsFields()
65 | fields.append(QgsField('id', QVariant.Int, '', 10, 0))
66 |
67 | (sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context, fields,
68 | QgsWkbTypes.Point, crs)
69 |
70 | for i in range(count):
71 | f = QgsFeature()
72 | f.setGeometry(QgsGeometry.fromPointXY(QgsPointXY(
73 | random.uniform(extent.xMinimum(), extent.xMaximum()),
74 | random.uniform(extent.yMinimum(), extent.yMaximum()))))
75 | f.setAttributes([i])
76 | sink.addFeature(f, QgsFeatureSink.FastInsert)
77 |
78 | return {self.OUTPUT: dest_id}
79 |
--------------------------------------------------------------------------------