Last active
August 29, 2015 14:22
-
-
Save VictorVelarde/4474bb556dac24abd0f7 to your computer and use it in GitHub Desktop.
PyQGIS - Capa en memoria de ENCUADRES (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 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