Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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

  • 06-04-2018 8:07pm
    #1
    Registered Users, Registered Users 2 Posts: 227 ✭✭


    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