Skip to content

Instantly share code, notes, and snippets.

@VictorVelarde
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VictorVelarde/b44c2e75634a53b988da to your computer and use it in GitHub Desktop.
Save VictorVelarde/b44c2e75634a53b988da to your computer and use it in GitHub Desktop.
PyQGIS - Capa en memoria de PUNTOS (EPSG:4326 con ID)
'''
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