Select to view content in your preferred language

arcpy fieldmappings Problem (spatial join)

558
3
11-03-2010 02:33 AM
SeldaSamiri
Emerging Contributor
SORRY! Found the error myself, immediately as I saw my post... wrong feature in the spatialjoin command...
So ignore this post, please!

PS: No delete option here?

##--------------------------------------------------------------------------------------

Hi there,

I want to do a spatial join with a polyline feature (target) and a point feature. In the new polyline-feature all fields of both features should appear. With the default values I only get the fields of the target-feature (correctly) and the ID field of the join-feature. So I tried fieldmapping and added the tables manually like this:

fieldmappings = arcpy.FieldMappings()

fieldmappings.addTable(inputFC)

fieldmappings.addTable(PS_copy)

arcpy.SpatialJoin_analysis (inputFC, PS, outputFC, "#", "#", fieldmappings, "INTERSECT")


This results in a feature table with the right fields, but except of the ID field of the join-feature the other fields  have the value 0.

What's wrong with my code?

If this is a stupid question, I'm sorry, I'm quite new to python-scripting...

Thanks!
Selda
0 Kudos
3 Replies
ChrisMathers
Deactivated User
No there isnt a delete option so that problems, even if they are self resolved can help others. By the way if you arent making a change to your field map and just leaving it as the default, you could have just used "#" as that patameter. No need to create that object, add in two tables and then use the object as the parameter.
0 Kudos
SeldaSamiri
Emerging Contributor
yes, thanx, if I use the correct feature it also works without the fieldmappings object 🙂
0 Kudos
SusanJones
Frequent Contributor
there is a huge problem with replaceFieldMap() and arcpy.
I struggled for quite some time.
See the link http://forums.arcgis.com/threads/34881-replacefieldmap()-appears-broken-in-arcpy.

Susan
0 Kudos