3

I've tried multiple times to understand field mappings and continue to be rather baffled. I assume it can be used to perform a geoprocess (in my case it will be a spatial join) and limit the fields in the output feature class. I'd like have the output only contain the fields generated by the spatial join (Join_Count, etc). I've tried creating blank field mappings objects and using it, but that's no good. I'd rather not take the extra step to delete all fields, as in large data set it will take some time.

Can anyone provide help?

  • I'm not sure what you are trying to accomplish with this question. Are you just wanting to understand more about how they work? It sounds like you understand them. They work in Spatial Joins or Merge type operations and allow you to remove fields or combine output from fields. I could potentially offer some helpful links if that is all you want to do here. – jbchurchill Apr 22 '15 at 20:07
  • I wasn't even positive field mappings would be able to get me my desired outcome of no fields carried over besides those created by the geoprocessing tool. I've gone over the esri help but haven't found much information elsewhere. – Emil Brundage Apr 22 '15 at 20:09
1

To answer the question about returning an output with no extra fields. From the dialog, you can just delete everything from the field map parameter. From Python, giving nothing (None, "", "#") to the field_mapping argument assumes you want everything. You can fake it out a bit, with something like this though:

arcpy.SpatialJoin_analysis(fc1, fc2, output_fc, 'JOIN_ONE_TO_ONE', 'KEEP_ALL', 'dummy_field', 'INTERSECT')

Which will add only a single field (better than everything), and then you can delete that single field.

arcpy.DeleteField_management(output_fc, 'dummy_field')
1

To familiarize yourself with what you are doing with field mappings, I recommend doing a spatial join or a merge operation within ArcMap. Perhaps visit the Geoprocessing Results window too. This will really help if you can first simulate manually the join that you want to do programmatically.

They can be tricky to work with but worth it. As you surmised, deleting fields manually can take time. I wrote a function in Python that deletes all fields except ones that you specify and it takes awhile to run when there are a lot of fields in a large table (I could share that if it helps). I think field mapping is really the way to go because it will run faster (when it is time to build the output it just ignores the fields that aren't being used).

Spatial Join can be tricky when both layers have the same field and the field in one is more restrictive (say 50 characters large vs another that is 250 characters large) so you may find you need some of this management just to avoid collisions.

Here are some links that should help get you started:

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.