4

I have more than two hundreds similar csv files with columns (x, y, value1, value2, objectName). I need to convert them automatically to shp files with x and y columns as the coordinates. Could you please advice how to do it quickly using Python scripting?

Thanx!

4

You would need to iterate through every shapefile in your folder with ListFiles. You might use Make XY Event Layer GP tool to create an event layer with the point shape (XY). Then you could use Copy Features GP tool.

Something like:

import arcpy,os
shpworkspace = r"C:\GIS"
arcpy.env.workspace = shpworkspace
arcpy.env.overwriteOutput = True

csvlist = arcpy.ListFiles("*.csv")

for csvfile in csvlist:
    outlayer = "CSVEventLayer"
    spatialreference = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98315284119522E-09;0.001;0.001;IsHighPrecision"
    arcpy.MakeXYEventLayer_management(csvfile,"POINT_X","POINT_Y",outlayer,spatialreference,"#")

    shpfile = os.path.splitext(csvfile)[0]        
    arcpy.CopyFeatures_management(outlayer,shpfile)
del outlayer

Here is the .csv sample file which you can use for getting the script to work with and then use your own data later on.

| improve this answer | |

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.