MakeXYEventLayer or FeatureClassToFeatureClass_conversion Cause Crash

822
11
12-10-2019 11:21 AM
guillaumemure
New Contributor

I am new to coding in python, my problems is the machine crashing halfway through first loop, and yet another five with its modulesScript .

i have "Serious Application Error" with the opportunity to send info to Esri.

i use script in toolbox, i have arcmap 10.6 .

Thanks.

0 Kudos
11 Replies
RandyBurton
MVP Alum

The additional information is helpful.  Could you share a sample of what the Mobilier_Urbain_L.shp file is like?  Also, is it safe to assume that all your shape files use the same format?

I noticed that the FieldX1 used in the MakeXYEventLayer may be the field name and probably should be quoted.  I am assuming there is a field in the shape file with this name.  If not, you would need to set it to the field's name, such as FieldX1 = 'XfieldName'.

arcpy.MakeXYEventLayer_management(OutTxtMob, 'FieldX1', 'FieldY1', OutTempMob, ParemSpat, 'FieldZ1')  ‍‍
0 Kudos
RandyBurton
MVP Alum

While experimenting with a line shape file, I realized that you do not need to convert the .dbf table to a text file to make use MakeXYEventLayer if it contains X and Y values.  For my experiment, I created some lines and save them as a shape file.  I used AddGeometryAttributes to add an XY value for the mid-point of the line.  The .dbf and .prj files were used to create a point feature.  Perhaps the test code will give you some ideas for your project.

import arcpy, os

arcpy.env.workspace = r'C:\Users\Randy\Documents\ArcGIS\PythonScripts\test\rbTest'
arcpy.env.overwriteOutput = True

dbf = 'line_test.dbf' # shape file data table
sr = arcpy.SpatialReference(os.path.join(arcpy.env.workspace,'line_test.prj')) # shape file spatial reference

# print sr.name, sr.factoryCode

FieldX1 = 'MID_X' # midpoint of line feature
FieldY1 = 'MID_y'
FieldZ1 = None

outShape = 'point_test.shp'

points = arcpy.MakeXYEventLayer_management(dbf, FieldX1, FieldY1, 'points', sr, FieldZ1) # make a point layer

result = arcpy.FeatureClassToFeatureClass_conversion(points, arcpy.env.workspace, outShape)

print result

'''
# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "line_test"

CENTROID - Adds attributes to store the centroid coordinates of each feature.
  (CENTROID_X, CENTROID_Y)
  
CENTROID_INSIDE - Adds attributes to store the coordinates of a central point inside or on each feature.
  (INSIDE_X, INSIDE_Y)

LINE_START_MID_END - Adds attributes to store the coordinates of the start, mid, and end points of each feature.
  (START_X, START_Y, MID_X, MID_Y, END_X, END_Y)

LINE_BEARING - Adds an attribute to store the start-to-end bearing of each line feature.
Values range from 0 to 360, with 0 meaning north, 90 east, 180 south, 270 west, and so on.
  (BEARING)
  
arcpy.AddGeometryAttributes_management(
    Input_Features="line_test",
    Geometry_Properties="LINE_START_MID_END;CENTROID;CENTROID_INSIDE;LINE_BEARING",
    Length_Unit="", Area_Unit="", Coordinate_System="")
'''

Hope this helps.

0 Kudos