Please review any and all PUBLIC repositories, groups and associate files. These allow anyone on the Internet to access without authentication. Repository and group owners are responsible for their content and permission settings. Go to your project(s), click on Settings > General and expand the "Visibility, project features, permissions" to change this setting.

Commit 307fec06 authored by Wigal, Jacob (CIV)'s avatar Wigal, Jacob (CIV)

Delete convert2geojson.py

parent 112611c6
import os
import geopandas as gpd
import re
def convert2geojson():
# Ask user for filepath of folder containing files to convert
def enterfilepath():
while True:
filepath=(input("Enter filepath of the folder containing your files: "))
if os.path.exists(filepath):
break
print("Not a valid filepath.")
os.chdir(filepath)
print("Converting all files in" , os.getcwd(), 'to geojson.')
enterfilepath()
# Make a geojson folder if it doesn't exist
current_directory = os.getcwd()
geojson_directory = current_directory + '/geojson'
if not os.path.exists(geojson_directory):
os.mkdir('geojson')
print('Will place all converted files in new "geojson" folder.' + '\n')
else:
print('Will place all converted files in existing "geojson" folder.' + '\n')
# Iterate over files and attempt to convert all to geojson
for file in os.listdir(current_directory):
# Skip folders and listed filetypes
if os.path.isdir(file):
continue
if not file.lower().endswith(('txt','jpg','jpeg','geojson','ds_store','pdf',\
'xlsx','doc','docx','git','qpj','prj','dbf','shx','cpg')):
print('Converting ' + file + '...')
try:
# Load data
file = str(current_directory) + '/' + str(file)
data = gpd.read_file(file)
# Alert user if CRS is changing with conversion
if data.crs['init'] != 'epsg:4326':
match = re.search('epsg:.[^\']*', str(data.crs)) #use regex to split each dms string into integer components to input in the dms_to_decimal function
crs = str(match.group())
print('Original CRS was ' + crs + '...will be converted to epsg:4326')
# Create new filepath with geojson folder and extension
head, tail = os.path.split(file)
filename = head + '/geojson/'+ tail
filename_ext = os.path.splitext(filename)[0] + '.geojson'
data.to_file(filename_ext, driver = 'GeoJSON')
#Print success message
print('Success: ' + file + ' was converted to GeoJSON' + '\n')
except:
# Alert user if file conversion failed
print('EXCEPTION: '+ file + ' is not a geopandas readable filetype')
print(file + ' could not be converted.' + '\n')
print('Done.')
convert2geojson()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment