3

file 1 file 15

I am using ArcPy to create an output feature layer. I am using the command:

arcpy.MakeXYEventLayer_management(wells, "longitude", "latitude", wells_layer, GEOGCS, ""), 

where wells is my input csv file and wells_layer is the path for the output feature layer. The idea is that after creating this feature class I will convert it to a shape file using arcpy.FeatureClassToShapefile_conversion. The issue is that when I try to run the first command

 arcpy.MakeXYEventLayer_management(wells, "longitude", "latitude", wells_layer, GEOGCS, ""), 

I get error 000212 : Cannot create XY event source:

Error:File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6589, 
in MakeXYEventLayer raise e arcgisscripting.ExecuteError: ERROR 000212:
 Cannot create XY event source Failed to execute (MakeXYEventLayer).

The weird thing is that I am running this command on around 50 numbered csv files which have been created in Stata using a for loop. Therefore, the formatting and structure of these files is precisely the same. However, this error only occurs for files numbered 15 and above. For files 1-14 this command works perfectly. I am at a complete loss because there seems to be no difference between these files.

I checked the ArcGIS help section and it says that I should check paths, field names and whether the coordinates are numeric. All of these appear to be fine across all the files.

I am using Python 2.7 and Arc Gis 10.2


I have detected with some help in comments that ArcMap is not detecting the latitude field for files 15 onwards. This is strange because the formatting is consistent and there are no spaces etc.

The field names in the csv are in top row as follows:

id_no,latitude,longitude
  • 3
    Have you tried adding one of the csv's that aren't working into ArcMap and using the "Display XY Data..." just to check if it works. – landocalrissian Oct 7 '14 at 18:39
  • @ChrisR Hi so I just did that and the file works with ArcMap.There is one discrepancy though. When I select files 15 and onwards, for some reason the automated selection on y-field is the id number as opposed to latitude. (this does not happen with the first 14 files where latitude is correctly selected automatically). But arc map does read the data properly after i select latitude as the y-field. But this shouldn't be a problem right because in the python command I specify arcpy to use latitude and longitude – user52932 Oct 7 '14 at 18:50
  • 1
    I know you created all the files the same but it sounds like in files 15-n there is some discrepancy with the latitude field. Is there a trailing space in the name of that field or in the field itself? – F_Kellner Oct 7 '14 at 18:58
  • Ok I think I detected the issue but still do not know the answer. Ignore my previous comment. ArcMaps is not detecting the latitude field. I went and opened the csvs in a text editor and i cannot see any difference in formatting. There are no spaces. – user52932 Oct 7 '14 at 19:01
  • 1
    Well that indicates to me that there is actually some difference in the the Latitude fields between 1-14 files and 15-n files. I would look into that further. Perhaps one of the entries isn't numeric? – F_Kellner Oct 7 '14 at 20:12
2

If I look to your provided data it seems the coords are given in text because of the ""'s, I had a simmilar problem with R output, when I re-did the R steps. With a double translation of the coords [ as.numeric(as.character(gsub(",",".",X-coord))) it worked out fine for me and the error was resolved. Could it be that your stata loop somwhere provided the data with an error? Perhaps in a previous calculation step?

0

Try this, as in the CSV your coordinates are quoted and viewed as text, so you need to convert them to numbers for plotting. Your ID fielld is already a number (no quotes)

arcpy.MakeXYEventLayer_management(wells, float("longitude"), float("latitude"), wells_layer, GEOGCS, ""),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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