Hi,
I've been trying to run arcpy.management.Eliminate in a script. As I understand, this tool, uses a layer with a selection in order to "merge" the selection with other adjacent polygons from the same layer.
Regardless of ESRI's doc, I can't seem to be able to make my script work. The problem seem to be the way I pass the feature Layer and selection to the Eliminate tool. I've tried countless ways, but it just doesn't seem to work. The layer is always passed as is and no polygon is merged.
Here is the bit of code that I'm using:
[...]
milieux_boises = arcpy.GetParameterAsText(0)
donnees_ecofor = arcpy.GetParameterAsText(1)
mb_ecofor = fr"{GDB}\mb_ecofor"
arcpy.analysis.Identity(in_features=milieux_boises, identity_features=donnees_ecofor_select, out_feature_class=mb_ecofor)
mb_ecofor_split = fr"{GDB}\mb_ecofor_split"
arcpy.MultipartToSinglepart_management(in_features=mb_ecofor, out_feature_class=mb_ecofor_split)
mb_ecofor_split_select="mb_ecofor_split_select"
arcpy.management.MakeFeatureLayer(in_features=mb_ecofor_split, out_layer=mb_ecofor_split_select)
exp = "FID_{0}= -1".format(nom_ecof)
arcpy.management.SelectLayerByAttribute(in_layer_or_view=mb_ecofor_split_select, selection_type="NEW_SELECTION", where_clause=exp, invert_where_clause=None)
mb_ecofor_split_net = fr"{GDB}\mb_ecofor_split_net"
arcpy.management.Eliminate(in_features=mb_ecofor_split_select, out_feature_class=mb_ecofor_split_net, selection="LENGTH")
[...]
The most frustrating part is that if I run the exact same lines in the python windows of ArcGIS Pro, it works.
Does anyone have a clue how to fix this?
your first two parameters, are they paths to featureclasses or layer names? The python window would be able to deal with both, but a standalone script wouldn't know what a layer was.
Have you tried throwing in a few print statements to see if anything is being done at the various steps
Hi @DanPatterson ,
Thanks for replying. The parameters are feature classes.
As for print statements, I have added prints of row count of the layer and after the selection. I get layer : 450 and selection: 0 which hints me towards a problem with the selection expression. But like I said, the exact same line worked in the python window so honestly I don't know how to troubleshoot this...
Could it be that I cannot use ".format()" for an SQL request? Because If I hard code the field name it works.
wow... ok nevermind me. My problem was that I inverted the inputs 🙄
Thank you for your help and sorry for this waste of time of yours!
no problem