Sunday 8 January 2017

csv - Batch convert xy to shapefile


I have about 300,000 CSV files which I want to convert to shapefiles, but ArcGIS and QGIS can only convert one CSV at a time.


Are there any ways to batch convert my CSVfiles?



x y z1 z2 z3 z4
1 2 3 4 5 6

My csv files just have a few columns like above


Can any one help me?



Answer



If anyone is still ever looking at this and are interested in scripting instead of batching, you can use the glob module in python to search through your directory that contains the .csv's, and then use one of the arc tools (feature class to feature class, copy features, etc.) as mentioned above.


You can download the glob module for free, but I think it already exists in package.


I would do something like this,


from glob import glob


directory = glob("DriveLetter:\FolderPath\\*.csv")

-- grabs all .csv files and puts them into array called directory
for files in directory:

arcpy.MakeXYEventLayer_management(files, "xcoordField", "ycoordField", "outputName", "spatialReference", "zcoordFieldIfExists")
arcpy.FeatureClassToFeatureClass_conversion("outputNameFromMakeXY", "YourDesiredOutputLocation", "NameofYourOutputFeatureClassorShapefile", "expressionIfEvenNeeded")

If your .csv's all have the same naming for their fields this can be easy because you can hardwire them in, it is also best to have the spatial reference parameter as a GetParameterAsText(#), or just not give it a spatial reference and use the same script when finished and perform a define projection on your new shapefiles



you can also use python for the naming to only keep so many characters from each object in the directory array and using it for output names


This is a pretty clunky answer but gives you some hints to google for and try to make it work


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...