2

I'm trying to create polygons from points layers. Each layer contains one point to avoid troubles due to superposition of polygons. I detailed the context here : How can I add output vector to a list to loop a geoprocessing on it?

The problem is, the solution proposed in the previous question worked well, but the context has changed a bit and now the sectors of my buffers need to be irregular but following a specific pattern, so i can't use voronoi polygons anymore.

I found a solution by customizing just a little the "create points along line" algorithm, creating hub lines to connect these points to the buffer's centroid and polygonizing.

This works great as far as the geometry is concerned, but the last step (polygonize) deletes the attributes.

I tried to set back the attributes with the spatial join algorithm, but it doesn't work : there is no error, it's just like if the algorithm did not run. Thought, it gives the expected result when used independently, outside of a script or modeler.

What am i doing wrong, and is there a solution ? Doesn't have to use the spatial join if there is a better way to do it

Here is my code :

##creatio_rose_vent_v3=name
##buffwind=output vector
##output_folder=folder
import glob, os, processing
os.chdir("H:/donnees_geo/points")
for points in glob.glob("*.shp"):
 outputs_QGISFIXEDDISTANCEBUFFER_1=processing.runalg('qgis:fixeddistancebuffer', points,1000.0,20.0,False,None)
 outputs_QGISFIXEDDISTANCEBUFFER_2=processing.runalg('qgis:fixeddistancebuffer', points,1100.0,20.0,False,None)
 outputs_SAGACONVERTPOLYGONSTOLINES_1=processing.runalg('saga:convertpolygonstolines', outputs_QGISFIXEDDISTANCEBUFFER_1['OUTPUT'],None)
 outputs_SAGACONVERTPOLYGONSTOLINES_2=processing.runalg('saga:convertpolygonstolines', outputs_QGISFIXEDDISTANCEBUFFER_2['OUTPUT'],None)
 outputs_SCRIPTCREATEPOINTSALONGLINESCUSTOM_1=processing.runalg('script:createpointsalonglinescustom', outputs_SAGACONVERTPOLYGONSTOLINES_2['LINES'],959.44,767.55,383.77,6524.22,None)
 outputs_QGISDISTANCETONEARESTHUB_1=processing.runalg('qgis:distancetonearesthub', outputs_SCRIPTCREATEPOINTSALONGLINESCUSTOM_1['output'],points,'ID5_35',1,0,None)
 outputs_QGISMERGEVECTORLAYERS_1=processing.runalg('qgis:mergevectorlayers', [outputs_SAGACONVERTPOLYGONSTOLINES_1['LINES'],outputs_QGISDISTANCETONEARESTHUB_1['OUTPUT']],None)
 outputs_QGISPOLYGONIZE_1=processing.runalg('qgis:polygonize', outputs_QGISMERGEVECTORLAYERS_1['OUTPUT'],False,False,None)
 outputs_QGISJOINATTRIBUTESBYLOCATION_1=processing.runalg('qgis:joinattributesbylocation', outputs_QGISPOLYGONIZE_1['OUTPUT'], outputs_QGISFIXEDDISTANCEBUFFER_1['OUTPUT'],['intersects'],0.0,1,'sum,mean,min,max,median',1,output_folder + "/buffwind_" + points)
os.chdir(output_folder)
output = glob.glob('*.shp')
processing.runalg("saga:mergelayers", ";".join(output), False, False, buffwind)

Finally works with the above code, i have no idea what was wrong the first time...

3
  • For your join attributes by location algorithm, try replacing ['intersects'] with u'intersects'. Commented Jun 16, 2016 at 9:42
  • 1
    finally works with the exact same code... i have no idea what was wrong the first time. Thanks Joseph for trying to help ! Commented Jun 17, 2016 at 10:23
  • No worries, really wonder what was wrong the first time. Hopefully it will continue to work :) Commented Jun 17, 2016 at 10:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.