I am learning QGIS 3.XX and currently working on Voronoi Polygons.
I have three layers
- Point layer
- Building Layer
- Population CSV file.
These points layer are basically water tanks and building layer is full of small Polygon in YY area. I need to find which building will take water from the nearest water tanks.
I need to make Voronoi polygon on Point Layer. I tried manually by going through Layer
-> Geometry Tools
->Voronoi Polygon
. And I got the below output.
After doing this, the newly created Voronoi Layer is placed at top of Layer Panel. I need to add this layer at lowest so that all the layers above can be put simultaneously on canvas. By now I am doing manually by placing point layer and building layer above voronoi layer, but how to achieve this using python? My expected output should be
until now my code looks like
from qgis.core import QgsProject
uri='file:///C:/Test/points.csv?
delimiter=,&crs=epsg:4326&xField=Lat&yField=Long'
layer=QgsVectorLayer(uri,'Points','delimitedtext')
QgsProject.instance().addMapLayer(layer)
vectorLyr=QgsVectorLayer("C:/Test/demand/Demand.shp","BuildingLayer","ogr")
vectorLyr.isValid()
QgsProject.instance().addMapLayer(vectorLyr)
uri='file:///C:/Test/data.csv?delimiter=,'
infoLyr=QgsVectorLayer(uri,'Population','delimitedtext')
infoLyr.isValid()
QgsProject.instance().addMapLayer(infoLyr)
csvField='FID_1'
shpField='FID'
joinObject=QgsVectorLayerJoinInfo()
joinObject.setJoinFieldName(csvField)
joinObject.setTargetFieldName(shpField)
joinObject.setJoinLayerId(infoLyr.id())
joinObject.setUsingMemoryCache(True)
joinObject.setJoinLayer(infoLyr)
vectorLyr.addJoin(joinObject)
No comments:
Post a Comment