Sunday 22 May 2016

arcpy - Why is Python Script (using XYTabletoPoint) Deleting target Feature Class?




When I run the following script (using Arc 10.2.2):


import arcpy

if __name__ == "__main__":

# Get Parameters
Source_CSV = arcpy.GetParameterAsText(0)
Target_FC = arcpy.GetParameterAsText(1)

# Get Spatial Reference of Target_CSV

SR = arcpy.Describe(Target_FC).spatialReference.Name

# Produce New Feature Class (Overwrites Same-Named File if it exists)
arcpy.management.XYTableToPoint(Source_CSV, Target_FC,"Lat", "Lng", "",SR)

...I get the following error complaining that the Target Feature Class does not exist.


Traceback (most recent call last):
File "Q:\CSVtoASMADPointFeatureClass.py", line 10, in
SR = arcpy.Describe(Target_FC).spatialReference.Name
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\__init__.py", line 1234, in Describe

return gp.describe(value)
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 374, in describe
self._gp.Describe(*gp_fixargs(args, True)))
IOError: "Q:\Data\Infrastructure\Infrastructure.gdb\LiftStations_Active" does not exist

As you've likely figured out, "Target_FC" is indeed the feature class referred to in the error message called "LiftStations_Active".


I can assure you before I run the script the Target_FC ("LiftStations_Active") does exist. After I run the script and get the above error I come to discover it is gone.


I assumed that "XYTabletoPoint" would simply overwrite a feature class that already exists. Perhaps its methodology is a bit more stepwise? Perhaps it first deletes any feature class (with the same name) and then creates the new feature class (of course, with the same name)? Regardless, the error refers to line 11 ("SR = arcpy.Describe(Target_FC).spatialReference.Name") and then complains that "LiftStations_Active" does not exist.


What is causing the deletion of the target feature class?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...