I try created an script with some modules and methods but i dont know whats wrong

2050
5
Jump to solution
11-24-2020 11:04 AM
Labels (1)
ALANMARQUES
New Contributor

import arcpy
import os
arcpy.env.workspace=r'C:\Users\alanamms\Documents\ArcGIS\Projects\MyProject8\MyProject8.gdb'
cw=os.getcwd()
infc=os.path.join(cw,'MyProject8.gdb','limite_ac.shp')
outfc=os.path.join(cw,'MyProject8.gdb','result.shp')
buffer=arcpy.Buffer_analysis('infc','outfc','1000 kilometers')

The error is below

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\analysis.py", line 1131, in Buffer
raise e
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\analysis.py", line 1128, in Buffer
retval = convertArcObjectToPythonObject(gp.Buffer_analysis(*gp_fixargs((in_features, out_feature_class, buffer_distance_or_field, line_side, line_end_type, dissolve_option, dissolve_field, method), True)))
File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\_base.py", line 511, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset infc does not exist or is not supported
Failed to execute (Buffer).

0 Kudos
1 Solution

Accepted Solutions
JoeBorgione
MVP Emeritus

I can't seem to find a way to format python code in a reply so I'll do the best I can.  You don't need the os module if you are working with file geodatabses.  Just set the workspace env: everything you do can then comes from and goes to that workspace with arcpy:

import arcpy

arcpy.env.workspace =  r'C:\path\to\your.gdb'

inFC = 'YourFeatureClassName'

outFC = 'TheOutFeatureClassName'

 arcpy.Buffer_analysis(inFC, outFC, '1000 Kilometers')

 

That should just about do it....

View solution in original post

5 Replies
JoeBorgione
MVP Emeritus

Please, when posting code use the format tool .

It looks to me that you are joining the current working directory to the field geodatabase and then a shapefile.  Actual shapefiles do not and cannot reside within a file geodatabase.

 

 

That should just about do it....
ALANMARQUES
New Contributor

So the trouble is the extension of the file? My real intention is to call the file without the need to add it, just making reference to it. (I thought the method os.path.join would solve it)
How could I do that?

0 Kudos
JoeBorgione
MVP Emeritus

Is your data stored as actual shape files or as feature classes with a file geodatabase?   If the former, they are stored in a folder as a series of files with the same name but different extensions.  The .shp extension is just one of them.

On the other hand if you are storing your data in a file geodatabase (best practices) there is no extension, just the feature class name.

Until you can explain where and how you have your data stored, there's not much I can help you with.

That should just about do it....
0 Kudos
ALANMARQUES
New Contributor

Sorry my confusion,but im begginer lmao. My files are stored in the geodatabase. 

0 Kudos
JoeBorgione
MVP Emeritus

I can't seem to find a way to format python code in a reply so I'll do the best I can.  You don't need the os module if you are working with file geodatabses.  Just set the workspace env: everything you do can then comes from and goes to that workspace with arcpy:

import arcpy

arcpy.env.workspace =  r'C:\path\to\your.gdb'

inFC = 'YourFeatureClassName'

outFC = 'TheOutFeatureClassName'

 arcpy.Buffer_analysis(inFC, outFC, '1000 Kilometers')

 

That should just about do it....