Skip to content

Instantly share code, notes, and snippets.

@VictorVelarde
Last active August 29, 2015 14:22
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/4474bb556dac24abd0f7 to your computer and use it in GitHub Desktop.
Save VictorVelarde/4474bb556dac24abd0f7 to your computer and use it in GitHub Desktop.
PyQGIS - Capa en memoria de ENCUADRES (EPSG:4326 con ID)
'''
Capa en memoria de Encuadres EPSG:4326 con ID
'''
#input: lista de (id, xmin, ymin, xmax, ymax)
encuadres = [
("1", -5.505, 35.89,-5.30,36.20),
("2", -5.4697, 36.03,-5.3101,36.21),
]
# proceso
URI = 'Polygon?crs=epsg:4326&field=Codigo:string&index=yes'
mem_layer = QgsVectorLayer(URI, 'encuadres', 'memory')
mem_layer.startEditing()
for e in encuadres:
codigo = e[0]
xmin = float(e[1])
ymin = float(e[2])
xmax = float(e[3])
ymax = float(e[4])
print (codigo, xmin, ymin, xmax, ymax)
entidad = QgsFeature()
rectangulo = QgsRectangle(xmin, ymin, xmax, ymax)
entidad.setGeometry(QgsGeometry.fromRect(rectangulo))
entidad.setAttributes([id])
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