I am trying to merge shapefiles (I have multiple of them in one folder) but it keeps returning this error. I'm not sure what that means. I didn't change the path or the data.

import arcpy, os 

fc = arcpy.ListFeatureClasses()
for shapefile in fc:
    if arcpy.ListFeatureClasses("","Polygon"):
    elif arcpy.ListFeatureClasses("","Point"):
    elif arcpy.ListFeatureClasses("","Line"):
        print("cannot merge")

ERROR 002948: The shape type of C:/Users/data\obce.shp is not the same as that of previously entered datasets. Failed to execute (Merge).

  • 1
    You cannot merge layers from differing topology classes. Your if tests are faulty.
    – Vince
    Mar 31 at 15:55

when you look at the list, you are not selecting the feature type but checking that the feature type is present in the entire list. I recommand to apply a filter based on the feature type to create your list, and you can test that the list is not empty to avoid errors.

if len(arcpy.ListFeatureClasses("*","Polygon"))>0:
if len(arcpy.ListFeatureClasses("*","Point"))>0:

rem 1: using elif, you would only merge the polygons even if you have several lines or several points, therefore I suggest to use only "if" rem 2: merging if you have only one feture of one type is useless, except that it copies the file with your standard naming. You could use "> 1" instead of "> 0"

  • Thank you so much! I didn't know how to make it all work together. This really helped, it works, thank you.
    – Max
    Mar 31 at 16:06

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.