Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Prodanovic committed Feb 7, 2019
1 parent 88638ea commit 836616c
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions shp2csv_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
#+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!
# #
# shp2csv_all.py #
# #
#+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!
#
# Author: Pat Prodanovic, Ph.D., P.Eng.
#
# Date: Feb 7, 2019
#
# Purpose: This script takes all *.shp files, and converts each to *.csv.
# I found that I was often running shp2csv.py too many times; this script
# simply automates this task.
#
# Uses: Python 2 or 3
#
# Example:
#
# python shp2csv_all.py
#
# there are no input arguments to this script; it looks for all *.shp
# files, and converts each to *.csv using shp2csv.py script
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Global Imports
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
import os,sys,glob,subprocess
#
# determine which version of python the user is running
if (sys.version_info > (3, 0)):
version = 3
pystr = 'python3'
elif (sys.version_info > (2, 7)):
version = 2
pystr = 'python'
#
# I/O
# gets a listing of all *.shp in the folder, and stores it in a list
shp_list = list()
shp_list = glob.glob('*.shp')

# sort the list
shp_list.sort()

# construct the file names for the output (replace *.shp with *.csv)
csv_list = list()

for i in range(len(shp_list)):
csv_list.append(shp_list[i].rsplit('.',1)[0] + '.csv')

# now call shp2csv.py for each *.shp file in the list
for i in range(len(shp_list)):
print('converting ' + shp_list[i])
subprocess.call([pystr, 'shp2csv.py', '-i', shp_list[i], '-o', csv_list[i]])

print('All done!')

0 comments on commit 836616c

Please sign in to comment.