1

I was trying to you this instead of field mapping because field mapping is hard to understand.

outfc = r'\\water.com\Blank.gdb\SewerCollection\ssLateralLine'
infc = r'\\water.com\Test.gdb\PW_Waste_Water\WastewaterUtilitySegment'

#The position of the fields must match, Name=Description etc.
outfcfield = ['INSTALLDATE', 'FACILITYID', 'SIZE', 'InstallationID', 'DOWNELEV', 'UPELEV', 'SIZE', 'LIFECYCLE', 'MATERIAL', 'PROJECTID_ADD', 'SEGMENTTYPE']
infcfields = ['equipDatePutInService', 'featureName', 'insideDiameter', 'installationId', 'invertElevationDownstream', 'invertElevationUom', 'nominalPipeSize', 'operationalStatus', 'pipeMaterial', 'projectId', 'wastewaterSegmentType']
icur = arcpy.da.InsertCursor(infc, infcfields)
with arcpy.da.SearchCursor(outfc, outfcfields) as cursor:
        for row in cursor:
            try:
                icur.insertRow(row)
            except:
                pass
            print "row[0:]: "+str(row[0:])
del icur

The insert cursor script above work but it didn't add the features just there data. I need to copy my feature to a different GDB that has a different Schema. I found the script below here https://community.esri.com/thread/185431-append-tool-and-field-mapping-help-examples and thought i could ad my data and see what happens then go from there.

import arcpy

append_layer = r'\\water.com\Test.gdb\PW_Waste_Water\WastewaterUtilitySegment'
target_layer = r'\\water.com\Blank.gdb\SewerCollection\ssLateralLine'


#This object looks like the empty grid of fields 
#you see when you first open the append tool in the toolbox
fieldmappings = arcpy.FieldMappings()

#Like when you manually choose a layer in the toolbox and it adds the fields to grid
fieldmappings.addTable(target_layer)
fieldmappings.addTable(append_layer)

#####Lets map fields that have different names!
list_of_fields_we_will_map = []
#Lets chuck some tuples into the list we made
list_of_fields_we_will_map.append(('equipDatePutInService', 'facilityNumber', 'installationId', 'numberOfPumps', 'operationalStatus',   'projectId','featureName'))

for field_map in list_of_fields_we_will_map:
    #Find the fields index by name. e.g 'TaxPin'
    field_to_map_index = fieldmappings.findFieldMapIndex(field_map[0])  
    #Grab "A copy" of the current field map object for this particular field
    field_to_map = fieldmappings.getFieldMap(field_to_map_index)
    #Update its data source to add the input from the the append layer
    field_to_map.addInputField(append_layer, field_map[1])
    #We edited a copy, update our data grid object with it
    fieldmappings.replaceFieldMap(field_to_map_index, field_to_map)

#Create a list of append datasets and run the the tool
inData = [append_layer]
arcpy.Append_management(inData, target_layer, field_mappings=fieldmappings)

Runtime error 
Traceback (most recent call last):
  File "<string>", line 25, in <module>
  File "d:\program files (x86)\arcgis\desktop10.7\arcpy\arcpy\arcobjects\arcobjects.py", line 328, in getFieldMap
return convertArcObjectToPythonObject(self._arc_object.GetFieldMap(*gp_fixargs(args)))

RuntimeError: FieldMappings: Error in getting field map from field mapping for GetFieldMap

How do I field map my ssLateralLine feature to the WastewaterUtilitySegment features?

2

I assume you mean the geometries aren't added with your first code. Add the SHAPE@ token for data access cursors to your list of fields. It will insert your geometries.

outfcfield = ['SHAPE@', 'INSTALLDATE', 'FACILITYID', 'SIZE', 'InstallationID', 'DOWNELEV', 'UPELEV', 'SIZE', 'LIFECYCLE', 'MATERIAL', 'PROJECTID_ADD', 'SEGMENTTYPE']
infcfields = ['SHAPE@', 'equipDatePutInService', 'featureName', 'insideDiameter', 'installationId', 'invertElevationDownstream', 'invertElevationUom', 'nominalPipeSize', 'operationalStatus', 'pipeMaterial', 'projectId', 'wastewaterSegmentType']
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.