I'm a veteran Python programmer very new to ArcGIS.

I'm trying to do what seems like it would be a simple operation in arcpy, but I don't think I know enough about the ArcGIS terminology to do more than fumble around.

Here's what I'd like to do:

  1. Load a .shp file containing terrain features (lines).
  2. Load a .csv file containing X-Y coordinates, setting the projection.
  3. Snap the coordinates in the csv to the .shp file.
  4. Save the new csv data to disk.

I can do this in the ArcMap UI without any trouble, but automating this with arcpy is a confusing mess to me. To load the data files do I use CreateFeatureDataset_management, CreateTable_management, CopyFeatures_management, AddXY_management, Project_management, CopyRows_management, or something else entirely?

I would very much welcome a tutorial, overview, or clue hammer. It seems that all of the ESRI documentation starts "in the middle" and I need to start at the beginning.

I don't suppose there's something like a "record what actions I perform in the GUI and export it as an arcpy script" function?

  • 1
    From the results window, you can right click and copy as python snippet. That would be a good starting point for getting the code you need. Then you can stick it in your favorite IDE (or the Python window in ArcMap) and edit it.
    – Paul
    Apr 22, 2014 at 17:51
  • 2
    Also, if you can document for us what your current workflow is within ArcMap, we may be able to give you a bit more direction.
    – John
    Apr 22, 2014 at 18:09

1 Answer 1


what you need to use is

MakeXYEventLayer_management to create a point layer

CopyFeature_managment to convert your layer to a feature class (some analysis are not possible if you don't have an object identifier)

SpatialJoin_analysis to get the value of the closest line feature class to your point

What you should know is that the GUI uses LAYERS to display data on the map. LAYERS are a kind of "pointer" with display properties, and they are stored within the map document or in a .lyr file. The data itself (e.g. what you store in a shapefile) is called FEATURE CLASS which can store a single geometry(e.g. points, lines or polygons). When you perform analysis outside of the GUI, you will usually use FEATURE CLASSES directly. With a geodatabase (another data format), you can store more than one feature class, and you can organize your feature classes within FEATURE DATASETS.

Adding CSV as point is a very particular action in ArcGIS because you use a table to directly create a layer (without actually creating a feature class). This special type of layer is called "event", it also exists with linear referencing but most of the time layers are based on feature classes. Event layers are not editable and, if the input table does not have an ObjectID field, you will not be able to make selections or add joins to the resulting layer. Many delimited text files or tables from OLE DS connections do not have ObjectID fields. This is why you probably need the CopyFeature tool.

As mentioned by Paul, you can add the "result" snippet from the geoprocessing menu, and then right click on the tools that you've used to copy them as Python snippets. You can also create a workflow using "Model Builder" and export this model as a Python script.

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.