0

I am using QGIS version 2.18.19. I have written a standalone script which converts a DXF file in to polygon shapefile. Now I want to write data into the attribute table of the polygon shapefile from a Excel file which I used as a input to the script.

My code is as follows:

dxf_to_polygon=name
t=table
dxffile=file
fpoly=output vector
outputs_GRASS7V_IN_DXF_1=processing.runalg('grass7:v.in.dxf', dxffile,'1',True,False,True,False,False,True,'200000.000000,700000.000000,200000.000000,700000.000000',0,None)
outputs_GRASS7V_CLEAN_1=processing.runalg('grass7:v.clean', outputs_GRASS7V_IN_DXF_1['output'],1,0.1,'200000.000000,700000.000000,200000.000000,700000.000000',-1.0,0.0001,None,None)
outputs_QGISPOLYGONIZE_1=processing.runalg('qgis:polygonize', outputs_GRASS7V_CLEAN_1['output'],True,True,None)
outputs_SAGAPOLYGONDISSOLVEBYATTRIBUTE_1=processing.runalg('saga:polygondissolvebyattribute', outputs_QGISPOLYGONIZE_1['OUTPUT'],'area','layer','perimeter',False,None)
outputs_SAGAPOLYGONDISSOLVEALLPOLYGONS_1=processing.runalg('saga:polygondissolveallpolygons', outputs_SAGAPOLYGONDISSOLVEBYATTRIBUTE_1['DISSOLVED'],False,None)
outputs_QGISADDFIELDTOATTRIBUTESTABLE_1=processing.runalg('qgis:addfieldtoattributestable', outputs_SAGAPOLYGONDISSOLVEALLPOLYGONS_1['DISSOLVED'],'Req_No',2,30.0,0.0,None)
outputs_QGISADDFIELDTOATTRIBUTESTABLE_2=processing.runalg('qgis:addfieldtoattributestable', outputs_QGISADDFIELDTOATTRIBUTESTABLE_1['OUTPUT_LAYER'],'Surveyor_Name',2,25.0,0.0,None)
outputs_QGISADDFIELDTOATTRIBUTESTABLE_3=processing.runalg('qgis:addfieldtoattributestable', outputs_QGISADDFIELDTOATTRIBUTESTABLE_2['OUTPUT_LAYER'],'Survey_Date',2,20.0,0.0,None)
outputs_QGISADDFIELDTOATTRIBUTESTABLE_4=processing.runalg('qgis:addfieldtoattributestable', outputs_QGISADDFIELDTOATTRIBUTESTABLE_3['OUTPUT_LAYER'],'Plan_Name',2,20.0,0.0,fpoly)

How can I solve this?

6
  • If both the shape file and Excel file have some column which can be used to identify the items then you can use Join feature in QGIS as you can also load the Excel file to QGIS. But I cannot help you with python...
    – Juhele
    Commented Jun 15, 2018 at 7:00
  • i want to read excel values and write the same to attribute table.anyway thanks a lot for your comment Commented Jun 15, 2018 at 7:11
  • 2
    You can do that by joining them like @Juhele is telling you. Add a field to the shapefile, join the tables, calculate the field, remove join.
    – Bera
    Commented Jun 15, 2018 at 8:15
  • 2
    Please do not comment on your own question. You should edit the question to provide clarification. Please take the Tour to better understand your role in curating a question.
    – Vince
    Commented Jun 15, 2018 at 10:35
  • 1
    @ShankaHerath - You could use the processing tool Join attributes table which should let you join the table of the final output with the excel input.
    – Joseph
    Commented Jun 15, 2018 at 11:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.