4

i have many (>15) shapefiles which have slightly differing fields.

s1: (Name, age, layer_1, ...)
s2: (Name, age, layer_1, layer_2, ...)
...
s_n: (Name, age, layer_1, layer_1_extra, ...)

I want to combine s1,s2 up to s_n into a new feature class/shapefile with attributes

s_merge: (Name, age, layer_1, layer_1_extra, layer_2, ...)

Field order is irrelevant. layer_1_extra should be set to ' ' or 0 depending on type, where features come from e.g. s1 ()which does not have layer_1_extra)).

Do I have to program this myself using search cursors (to get the field names), add field tool and insert cursors, or is there a way to coerce e.g. the merge tool to do what I want?

So far i tried to use the merge tool, but this fails with

arcgisscripting.ExecuteError: ERROR 001156: Failed on input OID 0, could not write value ' ' to output field SCHICHT_2

Field SCHICHT_2 is a number field, so of course arcgis can't write ' ' to it.

Code for setting the fieldMap is

for shapepath in ...:
 land_shape_paths.append(shapepath)
 fieldMappings.addTable(shapepath)
arcpy.Merge_management(land_shape_paths, land+'_full.shp', fieldMappings)

I had guessed ArcGIS was aware of field types and tried to write sensible "empty" values depending on field type. Apparently not, or my data is more botched than I think.

Any help (especially on a tool more suited to my needs than merge, or on the needed fieldMap magic) is appreciated!

asked Jun 19, 2013 at 15:16

1 Answer 1

3

I've tried to do this with code and had a similar situation as yours. Arc kept trying to merge a text field with a integer field because the fields were named the same, even though the data type was different. Here is an example:

Data Type Conflict

I had to bring all the shape files I wanted to merge into the merge tool and go through the field mappings to make sure that the fields were going into a proper place. I'm not sure how familiar you are with the Merge tool, but if you right click a field name in the field map box, you have some options to sort things out.

If you right click an input field, you can delete it from and output field. If you right click the whitespace to the right, you can add an output field (if the default fields aren't enough). If you right click the output field you can add an input field, or many input fields. Once you have it built, run the tool, then copy the result as a Python Snippet and you can insert it into a script, editing as necessary.

answered Jun 19, 2013 at 16:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.