Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Inserting EMPTY geometry

$
0
0
I had this code running just fine, but now all of the rows that are inserted are Zero length and I'm stumped. This grabs From/To XY's and then builds a line from them. The other stuff in here tests for duplicates. I print out the XY's so I know that I have them. What's going on?!


Code:

import arcpy
import sys

arcpy.env.overwriteOutput = True
arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(32043)

try:

    #import pprint
    pgTbl = r'Database Connections\Connection to myDb'
    output = r'\\xxx\xxx.gdb\Connections'

    arcpy.DeleteFeatures_management(output)
    print 'empty fc'

    xys = []
    with arcpy.da.SearchCursor(pgTbl, ['occ_num', 'cc_x_coord', 'cc_y_coord', 'x_coord', 'y_coord']) as c:   
        for r in c:
            if r[0] and r[1]:
                xys.append([r[0], r[1], r[2],r[3], r[4]])
               
    del r, c

    for i in xys:
        #print i
        if i[1] == i[3]:
            if i[2] == i[4]:
                xys.remove(i)

    xys.sort()
    for i in xys:
        print i

    for j in xys:
       
        myList = []
        myList.append(arcpy.Point(j[1], j[2]))
        myList.append(arcpy.Point(j[3], j[4]))
        array = arcpy.Array(myList)
        polyline = arcpy.Polyline(array)
        cursor = arcpy.da.InsertCursor(output, ("SHAPE@"))
        cursor.insertRow((polyline,))
        print 'inserted row'

    del cursor, polyline
       
    arcpy.Compact_management(r'\\xxx\xxx.gdb')
    print 'compact'
except:
    sys.exit()

finally:
    import gc
    gc.collect()


Viewing all articles
Browse latest Browse all 2485

Trending Articles