Sunday 21 June 2015

qgis - Constructing Voronoi Polgon and Applying Nearest neigbour in it


I am learning QGIS 3.XX and currently working on Voronoi Polygons.



I have three layers



  1. Point layer

  2. Building Layer

  3. 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.


enter image description here


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



enter image description here


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

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...