Hi, I am trying to add new features from a shapefile to a feature class sitting in database in sql server. Both have common fields but name of a few fields are different.
My question is that how can I automate this process using a python script.
I am new with Python and I've created this one but I am getting this error:
Runtime error
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "<string>", line 4, in getPrimaryFieldValues
TypeError: 'field_names' must be string or non empty sequence of strings.
My script looks like this:
ID is the field that the script should check it if the values don't exist then insert the rows.
import arcpy
def getPrimaryFieldValues(fc, field😞
values = []
with arcpy.da.SearchCursor(fc, [field]) as cursor:
for row in cursor:
values.append(row[0])
return values
def getSelectCursor(fc, whereClause😞
return arcpy.da.SearchCursor(fc, ["*"], whereClause)
def diff(a, b😞
b = set(b)
return [aa for aa in a if aa not in b]
source = r"original"
destination = r"test"
fieldName =["ID"]
sourceValues = getPrimaryFieldValues(source, fieldName)
destinationValues = getPrimaryFieldValues(destination, fieldName)
add = diff(sourceValues,destinationValues)
with arcpy.da.InsertCursor(destination, ["*"]) as insertCursor:
for a in add:
insertRows = getSelectCursor(source, fieldName + " = " + str(a))
for r in insertRows:
insertCursor.insertRow(r)