Python script: "points to polygons" skipped fourth vertex

المشرف العام

Administrator
طاقم الإدارة
Using ArcGis 10.2

I have a script converting the nodes of a net into polygons. The polygons should be either triangles or rectangles but the script doesn't build polygon as rectangle, skipping the fourth vertice. Being not fluent in python, I can't spot the mistake: it looks like the Array stores or restitute only 3 values instead of 4. Could you please help me to fix this?



Here the code:

import syssys.setdefaultencoding('UTF8')import arcpyimport osoutfileGDB =arcpy.env.workspace= arcpy.GetParameterAsText (0)arcpy.env.overwriteOutput = TruepolygonsFile = arcpy.GetParameterAsText (1)verticesFile = arcpy.GetParameterAsText (2)srtxt = arcpy.GetParameterAsText(3)sr = arcpy.SpatialReference()sr.loadFromString(srtxt)Output = arcpy.GetParameterAsText(4)polygontable = arcpy.TableToTable_conversion(in_rows=polygonsFile, out_path= outfileGDB, out_name="polygons_table", where_clause="")vertextable = arcpy.TableToTable_conversion(in_rows=verticesFile, out_path= outfileGDB, out_name="vertices_tables", where_clause="")outfc =arcpy.CreateFeatureclass_management (outfileGDB,Output,"POLYGON","#","DISABLED","ENABLED",sr)arcpy.AddField_management (outfc,"ID_el", "LONG", "", "", "", "", "NULLABLE")with arcpy.da.SearchCursor(polygontable,["OID@","Eltyp","ID_el","IDpt1","IDpt2","IDpt3","IDpt4"]) as poly_cur: print "polygons" if "ELtyp"== "E3T": poly_dict = {x[2]: x[3:5] for x in poly_cur} else: poly_dict = {x[2]: x[3:6] for x in poly_cur}with arcpy.da.SearchCursor(vertextable,"*") as vertex_cur: print "vertices" vertex_dict = {x[1]: x[2:] for x in vertex_cur}polyArray = {}for polykey in poly_dict: polynodes = poly_dict[polykey] coordsList = [] for polynode in polynodes: coords = (v for k,v in vertex_dict.iteritems() if k == polynode) for coord in coords: coordsList.append(coord) polyArray[polykey] = coordsListfeatures = []for key,values in polyArray.iteritems(): features.append((key,arcpy.Polygon(arcpy.Array([arcpy.Point(*value) for value in values]), sr, True))) #True - for has_z parameterfor feature in features: with arcpy.da.InsertCursor(outfc,["ID_el","SHAPE@"]) as cur: cur.insertRow(feature)arcpy.JoinField_management(outfc,"ID_el",polygontable,"ID_el",["IDpt1", "IDpt2", "IDpt3", "IDpt4", "Mat"])

أكثر...
 
أعلى