0

I am trying to run the PointDensity function on a feature class located in a shapefile:

[edit shp_file_path]

shp_file_path = os.path.join('path_to_shp_folder', 'shp_file_name')
if os.path.isfile(shp_file_path):
    out_raster = arcpy.sa.PointDensity(shp_file_path , 'FIELD_NAME', 0.000278832485028573, NbrCircle(2.32360404190478E-03, 'MAP'), 'SQUARE_METERS')

This is a code is pasted from the ArcGIS Pro Desktop application history after it run successfully from the toolbox.

In ArcPy, I get the following error:

arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000354: The name contains invalid characters

  • I have verified that path_to_shp_file is a valid file path.
  • I have checked with various numbers options inside the cellSize, and the NbrCircle.
  • I have tried from several locations on disk.
  • I have used MakeFeature_managment to create an in-memory feature class and gave its name as an argument to the input feature class.
  • I have verified that the workspace path is defined.
  • I have verified that the field 'FIELD_NAME' exists in the feature class by opening it in the desktop software.
  • I have verified that the feature class contains records of shape 'Point'.
  • I have tried to clone a new ArcPy Python virtual environment and configure its interpreter.
  • I have verified that I imported NbrCircle correctly.

How can I resolve this error?

3
  • 3
    \s is not a valid character in a shapefile name. Remember to always use raw formatting on strings with unescaped backslashes -- r'path_to_shp_folder\shp_file_name.shp'
    – Vince
    Jul 29, 2021 at 16:54
  • I actually used os.path.join('shp_file_folder', 'shp_filename') to get this string... I wrote this just as an example, apology for the confusion, if I test: os.path.isfile('shp_file_path') I get True.
    – CodePro
    Jul 30, 2021 at 5:21
  • It seems as if you're not providing the actual file name, when the error states that the name is invalid. Technically, it must be DOS 8.3 conformant, but ArcGIS doesn't enforce that. Without the actual name, it probably isn't possible to help you.
    – Vince
    Jul 31, 2021 at 2:48

1 Answer 1

0

It turned out that the path to the wokspace in:

arcpy.env.workspace = 'path_to_workspace'

was wrong, and the error message was not that helpful. After I fixed it, the command run successfully.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.