1

I'm having a hard time here on processing GIS data in Python, using library arcpy.
I've been trying to generate independent features from a feature class based on a field of the attribute table which is a unique code representing productive forest units, but I can't get it done.
I've already done this in other situations, but this time I don't know what I am missing.
Here is the code and the error I get:

# coding utf-8
import arcpy

arcpy.env.overwriteOutput = True
ws = r'D:\Projeto_VANT\SIG\proc_parc.gdb'
arcpy.env.workspace = ws

talhoes = r'copy_talhoes'

estados = ('SP', 'MG')
florestas = ('PROPRIA', 'PARCERIA')

arcpy.MakeFeatureLayer_management(talhoes,
                                          'talhoes_layer',
                                          """ "ESTADO" IN {} AND "FLORESTA" IN {} """.format(estados, florestas),
                                          ws)
arcpy.FeatureClassToFeatureClass_conversion(in_features = 'talhoes_layer',
                                            out_path = ws,
                                            out_name = 'talhoes1')
talhoes1 = r'talhoes1'

arcpy.AddField_management(talhoes1, 'CONCAT_T', 'TEXT')
arcpy.CalculateField_management(talhoes1, 'CONCAT_T', """ [ESTADO] & "_" & [CODIGO] & "_" & [TALHAO] """, 'VB')

with arcpy.da.SearchCursor(talhoes1, ['CONCAT_T', 'AREA']) as tal_cursor:
    for x in tal_cursor:
        print(x[0] + " " + str(x[1])) # This print is just to check if the cursor works and it does!
        arcpy.MakeFeatureLayer_management(x,
                                          'teste',
                                          """ CONCAT_T = '{}' """.format(str(x[0]))) # Apparently the problem is here!
        arcpy.CopyFeatures_management('teste',
                                      'Layer{}'.format(x[0]))

Here is the error:

Traceback (most recent call last):
  File "D:/ArcPy_Classes/Scripts/sampling_sig.py", line 32, in <module>
    """ CONCAT_T = '{}' """.format(str(x[0])))
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 6965, in MakeFeatureLayer
    raise e
RuntimeError: Object: Error in executing tool

Can anyone help me out?

  • 1
    @BERA thanks a lot, I knew it was something simple that I was missing. I'm getting started with arcpy recently. Thanks again! – caio.valente14 Jun 23 at 13:04
3

First parameter to MakeFeatureLayer should be a input feature class or layer.

You are passing x which is a tuple of the values of 'CONCAT_T', 'AREA', for example ("somevalue", 1000). Maybe it should be 'talhoes_layer' instead?

If you have ArcMap >= 10.5 (I think), you can use Split By Attributes:

Splits an input dataset by unique attributes

| improve this answer | |

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.