Make XY Event Layer not taking .CSV info

3738
6
04-11-2013 03:23 PM
by Anonymous User
Not applicable
Original User: SStrand

I have a project going that requires an input XY to be mapped as a point before buffered. The XY point is in a .csv file and using the Make XY Event Layer results in an empty data set no matter what I do. I thought maybe it had something to do with the environments, hence why it is split into two at the moment.

the csv file has the following:

X_FIELD, Y_FIELD
33.8, 118

Python:

    #Env 1
    env.workspace = "I:\InfoRequest"
    InfoRequestNum = arcpy.GetParameterAsText(1)
    loctable = "I:\InfoRequest\XYLocation.csv"
    sitelocfeat = "XYLOC" + InfoRequestNum
    sitelocfeature = "XY_Loc_" + InfoRequestNum
    locgdbtable = "XYLocation"
   
    #Import table to InfoRequestGDB
    arcpy.TableToGeodatabase_conversion([loctable],  "I:\InfoRequest\InfoRequest.gdb")
   
    #Env 2
    env.workspace = "I:\InfoRequest\InfoRequest.gdb"
   
    arcpy.MakeXYEventLayer_management(locgdbtable, "X_FIELD", "Y_FIELD", sitelocfeat)
    arcpy.FeatureToPoint_management(sitelocfeat, sitelocfeature)
0 Kudos
6 Replies
RDHarles
Regular Contributor
Any reason you're not going directly from the .csv file to a layer when using arcpy.MakeXYEventLayer_management ?
Simply use the MakeXYEventLayer tool to create a layer from the .csv file and then export the layer to your FGDB.
0 Kudos
by Anonymous User
Not applicable
Original User: SStrand

I was doing that in the beginning and was ending up with an empty data set, so I tried bringing it into the GDB as a table first (what the code is showing) and that table is empty as well.

Any reason you're not going directly from the .csv file to a layer when using arcpy.MakeXYEventLayer_management ?
Simply use the MakeXYEventLayer tool to create a layer from the .csv file and then export the layer to your FGDB.
0 Kudos
RDHarles
Regular Contributor
Strange.
Can you post a snippet of your csv table?
I just made a "fake" csv file like this and tried it and it worked fine:

X_FIELD, Y_FIELD, Stuff
-88.472, 40.987, Mom
-87.5435, 33.0, Dad


p.s.  Here's the code...

import arcpy
arcpy.MakeXYEventLayer_management("xyEvent.txt", "X_FIELD", "Y_FIELD", "XYlayer")
arcpy.CopyFeatures_management("XYlayer", "XY.gdb/POIs")
0 Kudos
by Anonymous User
Not applicable
Original User: SStrand

Mine looks exactly like yours, except I don't have a "stuff" type string field.

Maybe my issue is the " " which you have but I don't, though that seems like it would throw a code, not create the actual tables and points with empty data.
0 Kudos
RDHarles
Regular Contributor
Another issue I see is that your slashes are incorrect.

You need to use:
1.) forward slashes = /
2.) double backslashes = \\
3.) raw string = r"I:\InfoRequest"
0 Kudos
by Anonymous User
Not applicable
Original User: SStrand

Thanks rdharles for the help, I've got it taking the X Y now.

But..now the XY point isn't displaying on the map properly...on to the next issue!
0 Kudos