Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

[Python] Looking for baic tutorial on adding a row to feature class.

  • 06-04-2018 09:07PM
    #1
    Registered Users, Registered Users 2 Posts: 232 ✭✭


    Hi Folks

    I'm a newbie on Python and am looking for any help/tutorial on how to use Python to add a new row to a feature class.
    import arcpy
    
    arcpy.CreateFileGDB_management(r'F:\Project\Assignment', 'my_gdb')
    
    arcpy.env.workspace = r'F:\Project\Assignment\my_gdb.gdb'
    
    myPath = r'F:\Project\Assignment\my_gdb.gdb'
    arcpy.CreateFeatureclass_management(myPath, 'TestPoints', 'POINT')
    
    #add short integer field named PointID to TestPoints table:
    arcpy.AddField_management('TestPoints', 'PointID', 'SHORT')
    arcpy.AddField_management('TestPoints', 'Townland_Name', 'TEXT')
    arcpy.AddField_management('TestPoints', 'County_Name', 'TEXT')
    arcpy.AddField_management('TestPoints', 'URL', 'TEXT')
    
    editRows = arcpy.da.InsertCursor('TestPoints', '*')
    
    print editRows.fields
    
    OID = 0
    ptShape = arcpy.Point(0,0)
    ptID = 100
    townland = "Dublin"
    county = "Dun Laoghaire"
    URL = "http://www.google.com"
    
    newRecord = [OID, ptShape, ptID, townland, county, URL]
    editRows.insertRow(newRecord)
    
    del editRows
    

    This above works fine and I know that I need to comment out the part about creating the gdb and feature class as they'll already exist. My question is how to I add another record to the Feature Class 'TestPoints'. I believe it can be done using arcpy.da.InsertCursor so I'm looking for a very basic example of that.

    Thanks


Advertisement