Last active
August 29, 2015 14:19
-
-
Save VictorVelarde/b44c2e75634a53b988da to your computer and use it in GitHub Desktop.
PyQGIS - Capa en memoria de PUNTOS (EPSG:4326 con ID)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Capa en memoria de Puntos EPSG:4326 con ID | |
''' | |
#input: lista de (id, lon, lat) | |
puntos = [ | |
(1, -5.3899, 36.12), | |
(2, -5.6096268, 35.9423065), | |
(3, -5.1701736, 36.2972908) | |
] | |
# proceso | |
URI = 'Point?crs=epsg:4326&field=Codigo:integer&index=yes' | |
mem_layer = QgsVectorLayer(URI, 'puntos', 'memory') | |
mem_layer.startEditing() | |
for p in puntos: | |
codigo = p[0] | |
x = float(p[1]) | |
y = float(p[2]) | |
print (codigo, x, y) | |
pto = QgsPoint(x, y) | |
entidad = QgsFeature() | |
entidad.setGeometry(QgsGeometry.fromPoint(pto)) | |
entidad.setAttributes([codigo]) | |
mem_layer.addFeature(entidad) | |
mem_layer.commitChanges() | |
QgsMapLayerRegistry.instance().addMapLayer(mem_layer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment